{"id":301,"date":"2019-10-10T23:57:14","date_gmt":"2019-10-10T23:57:14","guid":{"rendered":"http:\/\/procyonic.org\/blog\/?p=301"},"modified":"2019-10-11T12:17:12","modified_gmt":"2019-10-11T12:17:12","slug":"emacs-apologia-2019","status":"publish","type":"post","link":"https:\/\/procyonic.org\/blog\/emacs-apologia-2019\/","title":{"rendered":"Emacs Apologia (2019)"},"content":{"rendered":"<p>Its 2019. I&#8217;ve been using Emacs for more than a decade and I&#8217;m not inclined to stop. Sometimes, my colleagues get on my case about it &#8211; why not use (for instance) RStudio or Jupyter or whatever other IDEs are floating around out there.<\/p>\n<p>They&#8217;ve got a point: if you&#8217;re doing something, its hard for Emacs to beat a custom solution which usually has much bigger mind share and corporate support to boot.<\/p>\n<p>But most of the time I&#8217;m not doing <em>one<\/em> thing. I&#8217;m doing a few, related, things and its in this context where Emacs shines. I tell my friends that Emacs is a general purpose text-based task thingamajig.<\/p>\n<p>Imagine the scene!<\/p>\n<p>You&#8217;ve got a problem you&#8217;re working on in R. Because you&#8217;re extremely professional, you do your work in a dev environment which is reified as a docker image. You realize you need to add a dependency &#8211; so you just say in your <code>*R*<\/code> buffer (maybe you&#8217;re using <code>ESS<\/code> or maybe not &#8211; I don&#8217;t).<\/p>\n<pre><code>&gt; install.packages(\"gbm\")<\/code><\/pre>\n<p>You also add the dependency to your <code>deps.R<\/code> script which your docker file runs. <code>M-x shell<\/code> creates a new shell, where you<\/p>\n<pre><code>&gt; docker build . -t ds<\/code><\/pre>\n<p>And your container is updated in the background. Maybe you find yourself doing this a lot, so you say<\/p>\n<pre><code>(defun do-build ()\r\n  (interactive)\r\n  (comint-send-string \r\n   (get-buffer-process (shell \"*docker-build*\"))\r\n   (format \"docker build . -t ds\\n\")))\r\n   <\/code><\/pre>\n<p>And then you can just <code>M-x local-set-key C-c C-c do-build<\/code> and its just a keystroke away.<\/p>\n<p>While that is happening your trying to figure why some values are turning up <code>NA<\/code> when you try to read from an sqlite DB into a data frame. You want to inspect the database manually. So you <code>- M-x shell *sqlite*<\/code> then.<\/p>\n<pre><code>&gt; docker run ... sqlite3 \/path\/to\/sqlite.db<\/code><\/pre>\n<p>Now, you want to run exactly the sql you&#8217;ve got in your R script, so you write the following absolute gem of a function:<\/p>\n<pre><code>(defvar *default-comint-buffer*\r\n  nil)\r\n(defun region-&gt;comint (s e)\r\n  (interactive \"r\")\r\n  (let* ((bufs (get-buffers-with-processes))\r\n         (dflt (or *default-comint-buffer*\r\n                   (car bufs)))\r\n         (buffer (completing-read \"where? \" bufs nil t dflt))\r\n         (s (concat (buffer-substring s e)\r\n                    (format \"\\n\"))))    \r\n    (comint-send-string (get-buffer-process (get-buffer buffer))\r\n                        s)\r\n    (pop-to-buffer (get-buffer buffer))\r\n    (setq *default-comint-buffer* buffer)))\r\n    <\/code><\/pre>\n<p>And now you can highlight sql fragments <em>in any buffer<\/em> and <code>M-x region-&gt;comint *sqlite*<\/code> and you&#8217;ll execute that code and jump to the buffer.<\/p>\n<p>And <code>region-&gt;comint<\/code> will do an enormous amount of leg work for you. Suppose your project uses multiple languages: R for one step, Python for another. A hassle if you&#8217;re using a Notebook or RStudio, but relatively easy to orchestrate inside Emacs.<\/p>\n<p>Sure, lots of stuff is missing. People really love Tab completion and its not always perfect in Emacs.<\/p>\n<p>But if you do complicated, multi-environment, text based tasks Emacs is still, far and away, the best tool for the job. And the fact that it works over a terminal and can act as a server, which means you can pop in and out as you need, leaving the environment up for months at a time. These days I keep multiple Emaxen running as daemons, one for each active project.<\/p>\n<p>Emacs is indispensible for me <em>especially<\/em> in 2019.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Its 2019. I&#8217;ve been using Emacs for more than a decade and I&#8217;m not inclined to stop. Sometimes, my colleagues get on my case about it &#8211; why not use (for instance) RStudio or Jupyter or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[19,10,69],"tags":[71,70],"class_list":["post-301","post","type-post","status-publish","format-standard","hentry","category-data-analysis","category-development","category-emacs","tag-data-science","tag-emacs"],"_links":{"self":[{"href":"https:\/\/procyonic.org\/blog\/wp-json\/wp\/v2\/posts\/301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/procyonic.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/procyonic.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/procyonic.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/procyonic.org\/blog\/wp-json\/wp\/v2\/comments?post=301"}],"version-history":[{"count":2,"href":"https:\/\/procyonic.org\/blog\/wp-json\/wp\/v2\/posts\/301\/revisions"}],"predecessor-version":[{"id":303,"href":"https:\/\/procyonic.org\/blog\/wp-json\/wp\/v2\/posts\/301\/revisions\/303"}],"wp:attachment":[{"href":"https:\/\/procyonic.org\/blog\/wp-json\/wp\/v2\/media?parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/procyonic.org\/blog\/wp-json\/wp\/v2\/categories?post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/procyonic.org\/blog\/wp-json\/wp\/v2\/tags?post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}