{"id":8203,"date":"2019-07-28T13:10:05","date_gmt":"2019-07-28T17:10:05","guid":{"rendered":"https:\/\/irreal.org\/blog\/?p=8203"},"modified":"2019-07-28T13:10:05","modified_gmt":"2019-07-28T17:10:05","slug":"building-an-emacs-mode-to-improve-your-workflow","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=8203","title":{"rendered":"Building an Emacs Mode to Improve Your Workflow"},"content":{"rendered":"<p>Adrien Brochard gave an excellent talk to the <a href=\"https:\/\/www.meetup.com\/New-York-Emacs-Meetup\/\">New York Emacs Meetup<\/a> in which he demonstrates <a href=\"https:\/\/www.youtube.com\/watch?v=w3krYEeqnyk\">how to build an Emacs major mode to improve a workflow<\/a>. Brochard is working with Kubernetes and would like a way to look at\u2014or even tail and follow\u2014the logs. For those who don\u2019t know what Kubernetes does, or perhaps have never heard of it, it\u2019s a system for controlling a set of processes (called pods).<\/p>\n<p>Kubernetes, of course, has a way of displaying and tailing the logs but you first have to call a Kubernetes command to list all the pods, which have long, complicated names, and then cut and paste the name into another Kubernetes command to list the log. Brochard wanted an easier workflow that didn\u2019t involve leaving Emacs or using the mouse. His solution is Kubernetes mode.<\/p>\n<p>What I really like about the talk is that he incrementally builds up his solution in much the same way that <a href=\"http:\/\/irreal.org\/blog\/?p=2200\">Kris Jenkins did when building his Spotify client<\/a>. He starts in the shell showing us how to call Kubernetes to list the pods and get the logs, then he writes a bit of Emacs code to call the code and put the results in a buffer using <code>shell-command-to-string<\/code>, and then <code>split-string<\/code> to get a (Lisp) list of pods.<\/p>\n<p>Next he wants a way of picking the correct pod. I probably would have used <code>ivy-completing-read<\/code> or one of its brethren but Brochard chose to use <code>tabulated-list-mode<\/code>, which makes sense for him because he is going to derive Kubernetes mode from <code>tabulated-list-mode<\/code>. By combining this with his previous code to get the list of pods, he has a naive version of the desired workflow. The problem is that large files can hang Emacs while they\u2019re being collected and, of course, trying to tail and follow the log will lock everything up. He solves that by substituting <code>call-process<\/code> and <code>start-process<\/code> (depending on whether he wants to tail or not) for <code>shell-command-to-string<\/code>. Now he a workflow with good performance and that supports tailing the log.<\/p>\n<p>Finally, he uses <code>transient<\/code> from Magit to wrap his mode up in a nice UX. Again, he does this incrementally so you can follow each step.<\/p>\n<p>All his intermediate code is in code blocks in an <a href=\"https:\/\/gist.githubusercontent.com\/abrochard\/dd610fc4673593b7cbce7a0176d897de\/raw\/bebc2a99dab1e9439bbd4402b37ca0b5f08320d5\/presentation.org\">Org file<\/a> so it\u2019s easy to follow along or go back afterwards to clarify something you missed. He also has a link to the <a href=\"https:\/\/github.com\/abrochard\/kubel\">full implementation of the mode<\/a> if you want to see everything together or try it out. As I said, this is a really good talk and definitely worth watching. It\u2019s about 33 and half minutes long so plan accordingly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adrien Brochard gave an excellent talk to the New York Emacs Meetup in which he demonstrates how to build an Emacs major mode to improve a workflow. Brochard is working with Kubernetes and would like a way to look at\u2014or &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=8203\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[18],"class_list":["post-8203","post","type-post","status-publish","format-standard","hentry","category-general","tag-emacs"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8203"}],"version-history":[{"count":1,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8203\/revisions"}],"predecessor-version":[{"id":8204,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/8203\/revisions\/8204"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}