{"id":3234,"date":"2016-06-21T15:59:25","date_gmt":"2016-06-21T19:59:25","guid":{"rendered":"http:\/\/fgiasson.com\/blog\/?p=3234"},"modified":"2017-02-17T10:39:20","modified_gmt":"2017-02-17T15:39:20","slug":"optimal-emacs-settings-for-org-mode-for-literate-programming","status":"publish","type":"post","link":"https:\/\/fgiasson.com\/blog\/index.php\/2016\/06\/21\/optimal-emacs-settings-for-org-mode-for-literate-programming\/","title":{"rendered":"Optimal Emacs Settings for Org-mode for Literate Programming"},"content":{"rendered":"<p>For some time I have been interested in using Emacs and Org-mode for developing Clojure in a Literate Programming way. I discussed the <a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/04\/27\/my-literal-programming-commitment\/\">basic ideas<\/a>, <a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/05\/30\/creating-and-running-unit-tests-directly-in-source-files-with-org-mode\/\">some of the benefits of doing so<\/a>, <a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/06\/09\/literate-programming-and-team-development\/\">etc<\/a>, <a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/04\/05\/using-clojure-in-org-mode-and-implementing-asynchronous-processing\/\">etc<\/a>. It is now time to start showing how I am doing this, what are the rules of thumb I created, what is the structure of my programs, etc.<\/p>\n<p>However, before I start writing about any of this, I think the next step is to explain how I configured Org-mode to have a <i>frictionless<\/i> experience to develop my applications in Literate Programming using Org-mode. Then in a subsequent series of blog posts I will explain how I structured my Clojure project, what is my development workflow, etc.<\/p>\n<p>Note that if you don&#8217;t have Emacs setup for Clojure\/Cider, I would encourage you to <a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/06\/14\/my-optimal-gnu-emacs-settings-for-developing-clojure-revised\/\">read this other blog post<\/a> which explains how to setup a Clojure environment in Emacs.<\/p>\n<p>This is the first post of a series of blog posts that will cover the full workflow. I will demonstrate how I do Literate Programming for developing a Clojure application, but exactly the same workflow would work for any other programming language supported by Org-mode (Python, R, etc.). The only thing that is required is to adapt the principles to the project structures in these other languages. The series of blog posts will cover:<\/p>\n<ol class=\"org-ol\">\n<li><a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/06\/21\/optimal-emacs-settings-for-org-mode-for-literate-programming\/\">Configuring Emacs for Org-mode<\/a> (this post)<\/li>\n<li><a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/07\/06\/literate-clojure-programming-using-org-mode\/\">Project folder structure<\/a><\/li>\n<li><a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/08\/11\/literate-clojure-programming-anatomy-of-a-org-mode-file\/\">Anatomy of a Org-mode file<\/a><\/li>\n<li><a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/10\/26\/literate-clojure-programming-tangle-all-in-org-mode\/\">Tangling all project files<\/a><\/li>\n<li><a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2017\/02\/17\/literate-clojure-programming-publishing-documentation-in-multiple-formats\/\">Publishing documentation in multiple formats<\/a><\/li>\n<li><a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/05\/30\/creating-and-running-unit-tests-directly-in-source-files-with-org-mode\/\">Unit Testing<\/a><\/li>\n<\/ol>\n<p><!--more--><\/p>\n<div id=\"outline-container-orgheadline1\" class=\"outline-3\">\n<h3 id=\"orgheadline1\">Packages<\/h3>\n<div id=\"text-orgheadline1\" class=\"outline-text-3\">\n<p><a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/06\/14\/my-optimal-gnu-emacs-settings-for-developing-clojure-revised\/\">Once Emacs is installed with Cider<\/a>, the first thing you have to do is to install all the packages that are required to use Org-mode and some of the tweaks that I am proposing. The packages that you have to install are:<\/p>\n<ol class=\"org-ol\">\n<li><a href=\"http:\/\/orgmode.org\/\">org<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/emacsmirror\/adaptive-wrap\">adaptive-wrap<\/a><\/li>\n<li><a href=\"https:\/\/www.emacswiki.org\/emacs\/Htmlize\">htmlize<\/a><\/li>\n<\/ol>\n<p>They can easily be installed using the following commands:<\/p>\n<pre class=\"example\">M-x package-install [RET] org [RET]\nM-x package-install [RET] adaptive-wrap [RET]\nM-x package-install [RET] htmlize [RET]\n<\/pre>\n<p>Additionally, you could have used <code>M-x<\/code><code>package-list-packages<\/code>, then move your cursor in the buffer to the packages\u00e2\u20ac\u2122 line. Then press <code>i<\/code> (for install) and once all the packages are selected, you could have press <code>x<\/code> (execute) to install all the packages all at once.<\/p>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline2\" class=\"outline-3\">\n<h3 id=\"orgheadline2\">Configure Org-mode Editor Behaviors<\/h3>\n<div id=\"text-orgheadline2\" class=\"outline-text-3\">\n<p>Org-mode is installed with a series of default settings, but I don&#8217;t like all of them when come the time to do Literate Programming with it. The first thing I like doing is to hide some of the Org-mode markup and to replace it by the actual font. For example, I don&#8217;t want to see <code>\/test\/<\/code> in my text, I want to see the (italized) version of <i>test<\/i>. Same for bold, links, etc. This can be done by setting <code>org-hide-emphasis-markers<\/code>.<\/p>\n<p>Then I want to turn the Emacs visual line mode, but only for Org-mode. This basically wraps long lines without justifying it.<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #ae81ff;\">(<\/span><span style=\"color: #f92672;\">require<\/span> '<span style=\"color: #ae81ff;\">org<\/span><span style=\"color: #ae81ff;\">)<\/span>\n\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Remove the markup characters, i.e., \"\/text\/\" becomes (italized) \"text\"<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>setq org-hide-emphasis-markers t<span style=\"color: #ae81ff;\">)<\/span>\n\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Turn on visual-line-mode for Org-mode only<\/span>\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Also install \"adaptive-wrap\" from elpa<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>add-hook 'org-mode-hook 'turn-on-visual-line-mode<span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline3\" class=\"outline-3\">\n<h3 id=\"orgheadline3\">Configure Cider for Org-mode<\/h3>\n<div id=\"text-orgheadline3\" class=\"outline-text-3\">\n<p>Since we want to do Literate Programming using (among others) Clojure, what we have to do is to configure Cider to be the Clojure backend to be used by Org-mode. Org-mode&#8217;s <code>code block<\/code> feature supports a long list how programming language. However, each of these programming languages are supported by a backend except for a few like Elisp (which uses Emacs as the backend). This is what we are doing here for Clojure.<\/p>\n<p>What we do here is first to specify to Org-mode which language we want to support with its code blocks. I only defined four for now: <code>clojure<\/code>, <code>sh<\/code>, <code>dot<\/code> and <code>elisp<\/code>.<\/p>\n<p>Then we specify that the <code>org-babel-clojure-backend<\/code> we want to use is <code>Cider<\/code>.<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Configure org-mode with Cider<\/span>\n\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Configure Org-mode supported languages<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>org-babel-do-load-languages\n 'org-babel-load-languages\n '<span style=\"color: #66d9ef;\">(<\/span><span style=\"color: #a6e22e;\">(<\/span>clojure . t<span style=\"color: #a6e22e;\">)<\/span>\n   <span style=\"color: #a6e22e;\">(<\/span>sh . t<span style=\"color: #a6e22e;\">)<\/span>\n   <span style=\"color: #a6e22e;\">(<\/span>dot . t<span style=\"color: #a6e22e;\">)<\/span>\n   <span style=\"color: #a6e22e;\">(<\/span>emacs-lisp . t<span style=\"color: #a6e22e;\">)<\/span><span style=\"color: #66d9ef;\">)<\/span><span style=\"color: #ae81ff;\">)<\/span>\n\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Use cider as the Clojure execution backend<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>setq org-babel-clojure-backend 'cider<span style=\"color: #ae81ff;\">)<\/span>\n<span style=\"color: #ae81ff;\">(<\/span><span style=\"color: #f92672;\">require<\/span> '<span style=\"color: #ae81ff;\">cider<\/span><span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline4\" class=\"outline-4\">\n<h4 id=\"orgheadline4\">Useful Key Bindings<\/h4>\n<div id=\"text-orgheadline4\" class=\"outline-text-4\">\n<p>There are a few key bindings in Cider that are handy to have directly in Org-mode. We can easily add them like this. What I did here is to define two new: one for evaluating the last Clojure expression bound to <code>C-x C-e<\/code>. Then the binding to get the documentation of a symbol bound to <code>C-c C-d<\/code>.<\/p>\n<p>If you wonder why this is necessary, it is because each Org-mode code block is <b>not<\/b> running the Clojure major mode, so these key bindings are not available directly within a Org-mode file. This is why we have to remap the ones we want to use directly within Org-mode.<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Useful keybindings when using Clojure from Org<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>org-defkey org-mode-map <span style=\"color: #e6db74;\">\"\\C-x\\C-e\"<\/span> 'cider-eval-last-sexp<span style=\"color: #ae81ff;\">)<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>org-defkey org-mode-map <span style=\"color: #e6db74;\">\"\\C-c\\C-d\"<\/span> 'cider-doc<span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline5\" class=\"outline-4\">\n<h4 id=\"orgheadline5\">Configuration of Custom Features<\/h4>\n<div id=\"text-orgheadline5\" class=\"outline-text-4\">\n<p>In my <a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/04\/05\/using-clojure-in-org-mode-and-implementing-asynchronous-processing\/\">Using Clojure in Org-mode and Implementing Asynchronous Processing<\/a> I discuss some limitations of the current implementation of <code>org-babel-clojure<\/code>. In that blog post I show how these limitations can be overcome. One of the setting I need to change is to remove the timeout of the <code>nrepl<\/code> middleware. It can be done that way:<\/p>\n<p>Only set that setting if you updated <code>org-bable-clojure<\/code> with the information from that blog post.<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">No timeout when executing calls on Cider via nrepl<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>setq org-babel-clojure-sync-nrepl-timeout nil<span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline6\" class=\"outline-3\">\n<h3 id=\"orgheadline6\">Configure Code blocks Behaviors<\/h3>\n<div id=\"text-orgheadline6\" class=\"outline-text-3\">\n<p>The code block in Org-mode has their own behaviors that can be modified like the default number of spaces for indentations, if you can use the <code>shift<\/code> key, the use the mode&#8217;s (Clojure in this code) native tab behavior and fontification (syntax highlighting), etc.<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Let's have pretty source code blocks<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>setq org-edit-src-content-indentation 0\n      org-src-tab-acts-natively t\n      org-src-fontify-natively t\n      org-confirm-babel-evaluate nil\n      org-support-shift-select 'always<span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline7\" class=\"outline-3\">\n<h3 id=\"orgheadline7\">Change Behaviors On Save<\/h3>\n<div id=\"text-orgheadline7\" class=\"outline-text-3\">\n<p>The most important configuration I did related to use Org-mode as a Literate Programming environment are all the behaviors that occurs when I save a org-mode document.<\/p>\n<p>The purpose of Literate Programming is to write a computer software while writing about its development process, its purpose, its implementation, etc. However, every time I save a literate file, I want the literate environment to extract (<i>tangle<\/i>) the code from that file into a [Clojure] source file that can be executed. What I did to enable this behavior is to add a function to call for Emacs&#8217; <code>after-save-hook<\/code>. What the function does is to make sure that the buffer being saved is a Org-mode buffer. If it is, then I run Org-mode&#8217;s tangling procedure that will tangle the Org file on save.<\/p>\n<p>However, given the nature of Literate Programming in Clojure, it is often the case that you will have another buffer where the tangled source file is open. What this means is that if you change some code in a Org file that get tangled on save, then the buffer where this code file is open won&#8217;t automatically be refreshed with the newly tangled code. To fix this issue, I set the <code>global-auto-revert-mode<\/code> which means that as soon as a file changes on the file system, if it is open in an Emacs buffer, then this buffer will be refreshed with that content.<\/p>\n<p>Finally, because Org-mode is not only about code blocks, I also enabled a final behavior when I save a Org file. What I often do is to leave <code>TODO<\/code> tasks at different places in my Org file to tell me what some work needs to be done at that place. However, once you start developing multiple projects with Org-mode, and when you start using Org-mode for others of its features, there is no way to track where you left TODO items across your entire computer system (and not just programing projects!). This is why Org-mode created a global list of TODO items via its <code>agenda<\/code> feature. To see the list of all the TODOs across all the Org files you created, you can access it using: <code>M-x org-todo-list<\/code>. However the problem here is that each of the Org file you want to have accessible in your agenda, you have to <i>push<\/i> it to the agenda system. It is not a problem in itself, but it becomes a problem is you forget to <i>push<\/i> each relevant Org file to the agenda. This is why I choose to automatically <i>push<\/i> any Org file to the Org agenda every time a Org file is being saved. That way I don&#8217;t have to worry when I check the global list of TODOs, I am sure that all of them are there.<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Tangle Org files when we save them<\/span>\n<span style=\"color: #ae81ff;\">(<\/span><span style=\"color: #f92672;\">defun<\/span> <span style=\"color: #a6e22e;\">tangle-on-save-org-mode-file<\/span><span style=\"color: #66d9ef;\">()<\/span>\n  <span style=\"color: #66d9ef;\">(<\/span><span style=\"color: #f92672;\">when<\/span> <span style=\"color: #a6e22e;\">(<\/span>string= <span style=\"color: #e6db74;\">(<\/span>message <span style=\"color: #e6db74;\">\"%s\"<\/span> major-mode<span style=\"color: #e6db74;\">)<\/span> <span style=\"color: #e6db74;\">\"org-mode\"<\/span><span style=\"color: #a6e22e;\">)<\/span>\n    <span style=\"color: #a6e22e;\">(<\/span>org-babel-tangle<span style=\"color: #a6e22e;\">)<\/span><span style=\"color: #66d9ef;\">)<\/span><span style=\"color: #ae81ff;\">)<\/span>\n\n<span style=\"color: #ae81ff;\">(<\/span>add-hook 'after-save-hook 'tangle-on-save-org-mode-file<span style=\"color: #ae81ff;\">)<\/span>\n\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Enable the auto-revert mode globally. This is quite useful when you have <\/span>\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">multiple buffers opened that Org-mode can update after tangling.<\/span>\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">All the buffers will be updated with what changed on the disk.<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>global-auto-revert-mode<span style=\"color: #ae81ff;\">)<\/span>  \n\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Add Org files to the agenda when we save them<\/span>\n<span style=\"color: #ae81ff;\">(<\/span><span style=\"color: #f92672;\">defun<\/span> <span style=\"color: #a6e22e;\">to-agenda-on-save-org-mode-file<\/span><span style=\"color: #66d9ef;\">()<\/span>\n  <span style=\"color: #66d9ef;\">(<\/span><span style=\"color: #f92672;\">when<\/span> <span style=\"color: #a6e22e;\">(<\/span>string= <span style=\"color: #e6db74;\">(<\/span>message <span style=\"color: #e6db74;\">\"%s\"<\/span> major-mode<span style=\"color: #e6db74;\">)<\/span> <span style=\"color: #e6db74;\">\"org-mode\"<\/span><span style=\"color: #a6e22e;\">)<\/span>\n    <span style=\"color: #a6e22e;\">(<\/span>org-agenda-file-to-front<span style=\"color: #a6e22e;\">)<\/span><span style=\"color: #66d9ef;\">)<\/span><span style=\"color: #ae81ff;\">)<\/span>\n\n<span style=\"color: #ae81ff;\">(<\/span>add-hook 'after-save-hook 'to-agenda-on-save-org-mode-file<span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline8\" class=\"outline-3\">\n<h3 id=\"orgheadline8\">Export Configurations<\/h3>\n<div id=\"text-orgheadline8\" class=\"outline-text-3\">\n<p>There are a few things you can do regarding how you export your org files. One thing I like to do is to set <code>org-html-htmlize-output-type<\/code> to <code>css<\/code> (default is <code>inline-css<\/code>) such that it does not include the CSS in the exported HTML. I prefer using the CSS that comes with the HTML themes I use. However, when I need inline CSS (like when I export HTML to be displayed elsewhere, i.e. on my blog) then I simply define a <code>elisp<\/code> code block to set <code>org-html-htmlize-output-type<\/code> back to <code>inline-css<\/code> to reverse that behavior for that special usecase.<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">make sure that when we export in HTML, that we don't export with inline css.<\/span>\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">that way the CSS of the HTML theme will be used instead which is better<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>setq org-html-htmlize-output-type 'css<span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline9\" class=\"outline-4\">\n<h4 id=\"orgheadline9\">Enable External Exporters<\/h4>\n<div id=\"text-orgheadline9\" class=\"outline-text-4\">\n<p>There are tons of Org-mode export plugins, but not all of them are enabled by default. For contributed exporters, you will have to get it from the <code>contrib\/lisp<\/code> <a href=\"http:\/\/orgmode.org\/w\/org-mode.git?p=org-mode.git;a=tree;f=contrib\/lisp;h=c5dc72cebae54e5175f373d5b85f1a6bdbbd764f;hb=refs\/heads\/master\">folder on the Git repository<\/a> and save it in your else repository in <code>[home]\/.emacs.d\/elpa\/[org-20160623]\/<\/code> Here is an example of how you can enable a new one which is the exporter for Confluence. Then you can export typing <code>M-x org-confluence-export-as-confluence<\/code><\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Enable Confluence export<\/span>\n<span style=\"color: #ae81ff;\">(<\/span><span style=\"color: #f92672;\">require<\/span> '<span style=\"color: #ae81ff;\">ox-confluence<\/span><span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline10\" class=\"outline-3\">\n<h3 id=\"orgheadline10\">Dire Configuration<\/h3>\n<div id=\"text-orgheadline10\" class=\"outline-text-3\">\n<p>I personally use Dire a lot. However it displays everything by default which may not be optional, particularly when working within Org related directories with all the auto-save files that get generated. This is why I like to filter out a few things such that everything is not being displayed in the Dire buffer.<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #75715e; font-style: italic;\">; <\/span><span style=\"color: #75715e; font-style: italic;\">Remove autosave and other unnecessary files to see in Dire<\/span>\n<span style=\"color: #ae81ff;\">(<\/span><span style=\"color: #f92672;\">require<\/span> '<span style=\"color: #ae81ff;\">dired-x<\/span><span style=\"color: #ae81ff;\">)<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>setq-default dired-omit-files-p t<span style=\"color: #ae81ff;\">)<\/span> <span style=\"color: #75715e; font-style: italic;\">; <\/span><span style=\"color: #75715e; font-style: italic;\">Buffer-local variable<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>setq dired-omit-files <span style=\"color: #e6db74;\">\"^\\\\.?#\"<\/span><span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline11\" class=\"outline-3\">\n<h3 id=\"orgheadline11\">Spell checker<\/h3>\n<div id=\"text-orgheadline11\" class=\"outline-text-3\">\n<p>It is always convenient to have a spell checker in Org-mode. Right now I am using <code>ispell<\/code> along with <code>flyspell<\/code>. That works fine, but I don&#8217;t like the fact that the last aspell version for Windows is about 14 years old! Any idea to improve this situation would be greatly welcome!<\/p>\n<p>The first step that is required to enable this feature is to download <a href=\"http:\/\/aspell.net\/win32\/\">GNU Aspell (in my case, for Windows)<\/a>. Then we have to instruct Emacs where the aspell dictionary is located, and then we have to enable <code>Flyspell<\/code> for text modes. Finally, make sure to install the appropriate language pack as well.<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #ae81ff;\">(<\/span>custom-set-variables\n '<span style=\"color: #66d9ef;\">(<\/span>ispell-program-name <span style=\"color: #e6db74;\">\"c:\\\\Program Files (x86)\\\\Aspell\\\\bin\\\\aspell.exe\"<\/span><span style=\"color: #66d9ef;\">)<\/span><span style=\"color: #ae81ff;\">)<\/span>\n\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Enable Flyspell for text modes<\/span>\n<span style=\"color: #ae81ff;\">(<\/span>add-hook 'text-mode-hook 'flyspell-mode<span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline12\" class=\"outline-3\">\n<h3 id=\"orgheadline12\">DOT support<\/h3>\n<div id=\"text-orgheadline12\" class=\"outline-text-3\">\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/DOT_(graph_description_language)\">DOT<\/a> is like a markup language for describing graphs. It is really simple to use and generate effective graph images that can easily be embedded into your Org-mode files.<\/p>\n<p>The first step is to install <a href=\"http:\/\/www.graphviz.org\/\">Graphviz<\/a> on your computer. This is the library that will be used to generate the images from the DOT specification. The only thing you have to do is to make sure that Graphviz&#8217;s <code>bin<\/code> directory is in the <code>Path<\/code> environment variable and you are done.<\/p>\n<p>Once Graphviz is installed and configured, restart Emacs and start using it right away, no other configuration is required. Here is an example of a class hierarchy created using DOT:<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-dot\">digraph {\n  soloist -&gt; <span style=\"color: #e6db74;\">\"musical performer\"<\/span>;\n  <span style=\"color: #e6db74;\">\"musical performer\"<\/span> -&gt; musician;\n  musician -&gt; artist;\n  artist -&gt; person;\n  person -&gt; human;\n  author -&gt; artist;\n  <span style=\"color: #e6db74;\">\"scifi writer\"<\/span> -&gt; author;\n  journalist -&gt; author;\n  correspondent -&gt; journalist;\n}\n<\/pre>\n<\/div>\n<div class=\"figure\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3236\" src=\"https:\/\/fgiasson.com\/blog\/wp-content\/uploads\/2016\/06\/actors-authors-humans-e1466538581874.jpeg\" alt=\"actors-authors-humans\" width=\"400\" height=\"403\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline13\" class=\"outline-3\">\n<h3 id=\"orgheadline13\">Inline Images Display<\/h3>\n<div id=\"text-orgheadline13\" class=\"outline-text-3\">\n<p>One essential feature of Org-mode to make it a useful Notebook application is to be able to have inline images (that we generate from code blocks or that are somewhere on the file system) directly in Emacs. Depending on your Emacs distribution, you may require to download and install a few libraries in order to make this working properly (at least on Windows).<\/p>\n<p>The first step is to make sure that Org-mode does display inline images by default. If you don&#8217;t want this behavior, you can always use the key binding <code>C-c C-x C-v<\/code> to toggle this behavior. If you want to enable this by default when Emacs enter in Org-mode, then you have to add the following to your <code>.emacs<\/code> file:<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Enable inline image when entering org-mode<\/span>\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Make sure you have all the necessary DLL for image display<\/span>\n<span style=\"color: #75715e; font-style: italic;\">;; <\/span><span style=\"color: #75715e; font-style: italic;\">Windows ones can be downloaded from: https:\/\/sourceforge.net\/projects\/ezwinports\/files\/<\/span>\n<span style=\"color: #ae81ff;\">(<\/span><span style=\"color: #f92672;\">defun<\/span> <span style=\"color: #a6e22e;\">turn-on-org-show-all-inline-images<\/span> <span style=\"color: #66d9ef;\">()<\/span>\n  <span style=\"color: #66d9ef;\">(<\/span>org-display-inline-images t t<span style=\"color: #66d9ef;\">)<\/span><span style=\"color: #ae81ff;\">)<\/span>\n\n<span style=\"color: #ae81ff;\">(<\/span>add-hook 'org-mode-hook 'turn-on-org-show-all-inline-images<span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<p>It is possible that you get the following error message in your <code>mini buffer<\/code> if you type <code>C-c C-x C-v<\/code>:<\/p>\n<blockquote><p>&#8220;no images to display inline&#8221;<\/p><\/blockquote>\n<p>What this probably means is that you are lacking the libraries to display these type of images. What you should do is to run this elisp code to see the expected library files each supported file format and the expected library files names:<\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-elisp\"><span style=\"color: #ae81ff;\">(<\/span>print image-library-alist<span style=\"color: #ae81ff;\">)<\/span>\n<\/pre>\n<\/div>\n<pre class=\"example\">((xpm \"libxpm.dll\" \"xpm4.dll\" \"libXpm-nox4.dll\") (png \"libpng16.dll\" \"libpng16-16.dll\") (tiff \"libtiff-5.dll\" \"libtiff3.dll\" \"libtiff.dll\") (jpeg \"libjpeg-9.dll\") (gif \"libgif-7.dll\") (svg \"librsvg-2-2.dll\") (gdk-pixbuf \"libgdk_pixbuf-2.0-0.dll\") (glib \"libglib-2.0-0.dll\") (gobject \"libgobject-2.0-0.dll\") (gnutls \"libgnutls-28.dll\" \"libgnutls-26.dll\") (libxml2 \"libxml2-2.dll\" \"libxml2.dll\") (zlib \"zlib1.dll\" \"libz-1.dll\"))\n<\/pre>\n<p>Then for each of the format you want to report, get the library file and for add it in your <code>[...]\/emacs\/bin\/<\/code> folder. On windows, you can find all these <code>DLL<\/code> from the <a href=\"https:\/\/sourceforge.net\/projects\/ezwinports\/files\/\">EzWinPorts<\/a> project repository.<\/p>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline14\" class=\"outline-3\">\n<h3 id=\"orgheadline14\">Language Specific Libraries<\/h3>\n<div id=\"text-orgheadline14\" class=\"outline-text-3\">\n<p>For a few tasks I simply use external libraries to get the job done instead of Emacs\/Org-mode specific plugins or functionality. I will refer to Clojure external libraries, but the same kind of libraries could be used in any other programming languages.<\/p>\n<p>For example, if I want to output tabular information in Org-mode, then I normally use the <a href=\"https:\/\/github.com\/cldwalker\/table\">Clojure Table<\/a> application which takes multiple different kind of Clojure data structure and turns them into well-formatted tables in the resultsets. This is really handy for that kind of operation.<\/p>\n<p>Otherwise I use <a href=\"http:\/\/incanter.org\/\">Incanter<\/a> a lot to generate effective graphs, charts of plots that I save as PNG and that I display inline in Org-mode. However, if I have a graph or flow chart to create, then I will use the DOT plugin since it is really easy to use not to use it within Org-mode.<\/p>\n<p>Basically anything that output some text or some image could be used within Org-mode, but for the kind of software I develop and the kind of data analysis tasks I am doing, these are the two bests in my toolset for the moment.<\/p>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline15\" class=\"outline-3\">\n<h3 id=\"orgheadline15\">Helpful Keys for Working With Org-mode<\/h3>\n<div id=\"text-orgheadline15\" class=\"outline-text-3\">\n<p>There are a few key bindings in Org-mode that really make your life easier when come the time to do Literate Programming in Org-mode.<\/p>\n<p>If you are using Clojure in your Org file, then the first thing to do is to start Cider. I bound <code>cider-jack-in<\/code> to <code>F9<\/code>. Once Cider is started, then you will be able to run Clojure code within your Org file.<\/p>\n<p>The most obvious key binding is <code>C-x C-s<\/code> which will save the Org file. At the same time, it will do all the things described in the section <code>Change Behaviors On Save<\/code> described above.<\/p>\n<p>Then we have <code>C-c C-c<\/code> that will execute a specific code block and show the results. Note that the cursor needs to be somewhere within the code block (including the header and footer) to execute that block with that key binding.<\/p>\n<p>When you open an existing Org file with a lot of code blocks, you often want to run all the code blocks at once. It can easily be done using <code>C-c C-v t<\/code> which will do exactly that.<\/p>\n<p>We have to remember that it is not the Clojure major mode that we use directly in Org-mode. However, it is often handy to be able to switch to Clojure&#8217;s major mode from a Org file (to get auto completion, etc.). It can easily be done with <code>C-c '<\/code> which will open a new buffer with the code in Clojure&#8217;s major mode. Then if you modify that buffer and save it using <code>C-c C-x<\/code> then the Org file will be updated with the changes as well. To switch back to the Org file, then you simply has to hit <code>C-c '<\/code> again.<\/p>\n<p>There are a few key bindings quite handy to work with the structure of the document. We often endup writing big Org file with a lot of headers and level of headers. It is quite handy to be able to focus on specific regions in a Org outline. This can easily be done using <code>C-x n s<\/code> which will focus on a particular region (only the content of that region appears in the buffer). Then you can use <code>C-x n w<\/code> to unfocus a focused region (everything surrounding that region will reappear in the buffer).<\/p>\n<p>There are tens of other key bindings that you will endup using in Org-mode for doing Literate Programming, but these are the ones I most often use when writing a Org file.<\/p>\n<\/div>\n<\/div>\n<div id=\"outline-container-orgheadline16\" class=\"outline-2\">\n<h3 id=\"orgheadline16\">Conclusion<\/h3>\n<div id=\"text-orgheadline16\" class=\"outline-text-2\">\n<p>As you can see, there are quite a lot of things that can be configured in Org-mode. This is even just the tip of the iceberg in fact. However, these are the main features I use to do Literate Programming and to create data analysis notebooks. Now that we have <a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2016\/06\/14\/my-optimal-gnu-emacs-settings-for-developing-clojure-revised\/\">Emacs configured<\/a>, and that we have Org-mode configured, my next step will be to write about how I do organize my Clojure applications to write Literate programs.<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>For some time I have been interested in using Emacs and Org-mode for developing Clojure in a Literate Programming way. I discussed the basic ideas, some of the benefits of doing so, etc, etc. It is now time to start showing how I am doing this, what are the rules of thumb I created, what [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[251,279,277],"tags":[252,274,276],"class_list":["post-3234","post","type-post","status-publish","format-standard","hentry","category-clojure","category-emacs","category-literate-programming","tag-clojure-2","tag-literateprogramming","tag-orgmode"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=3234"}],"version-history":[{"count":9,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3234\/revisions"}],"predecessor-version":[{"id":3618,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3234\/revisions\/3618"}],"wp:attachment":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=3234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=3234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=3234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}