Org Mode

Table of Contents

Org Mode is a Emacs tool built for organising notes, todo lists and agenda items. When i started using Beancount i was looking for more reasons to learn Emacs. When reading forum posts, found references to GTD which led to Org Roam.

Org Mode can be used for preserving and displaying formatting src blocks. The Emacs configuration page is a live example page as my init.el lives in org mode there.

After reading about the benefits of Org Mode converted most of my accumulated HowTo and other notes to org format.

To maintain these notes decided to use Org Roam based Zettelkasten system. While trying to configure Org Roam, went into a rabbit hole of emacs configuration hell, got lost, cleaned up the mess and learned some on the way.

Amongst the biggest gain include magit and helm based tool stack that included company, org-rifle, hydra, outshine, helm-swoop etc.

Using alternate org version

I use the default inbuilt version of org mode. To use a new version of org-mode instead of the built-in version, refer https://www.reddit.com/r/emacs/comments/dv02lk/how_to_force_emacs_to_prefer_manually_installed/

Preserve Formatting in Org Mode

This section explains how to preserve formatting for code like when literal examples are used inside Org Mode,i.e they should not be subjected to markup. How i used this feature is explained in a later section of this page.

Displaying source code

An example without specifying langugage appears as follows:

Some example from a text file.

If the source code is from a Programming language, the usual facilities offerred by Emacs like Font Lock are applied, so that the example looks like fontified emacs buffer. One needs to mention the major Mode.

(defun org-xor (a b)
  "Exclusive or."
  (if a (not b) b))
(defun my/doasedit ()
  (interactive)
  (if (buffer-file-name)
      (let ((cursor-pos (point))
            (truename (file-truename (buffer-file-name))))
        (find-alternate-file (concat "/doas::" truename))
        (goto-char cursor-pos))
    (message "This buffer is not visiting a file!")))

Because the ‘#+BEGIN’ … ‘#+END’ patterns need to be added so often, a shortcut is provided C-c C-,.

Structure templates can be used to define additional shortcuts for needed languages. An example can be found in the config file.

The electric-indent-mode needs to be disabled to avoid interfering with src blocks as shown below.

Editing the quoted source code

The source code can be edited using the shortcut "C-c '" (org-edit-special) to open src block in dedicated buffer. Once edited use the same shortcut "C-c '" to close.

C-c ' (org-edit-special)

Source:https://orgmode.org/manual/Literal-Examples.html

Steps to move an init.el file to org mode

Here are the steps i followed to migrate my pre-existing init.el file to a literate configuration.

  • Copied my original init.el to an org mode file.
  • Define filename where org-babel must tangle the file to as shown below just below the property drawer in Org Roam. I started with a test file.

    #+PROPERTY: header-args:emacs-lisp :tangle /tmp/test-init.el :lexical t
    
  • Added the following code-snippet to let org-babel tangle the file.

    (when (string-equal buffer-file-name
                        (expand-file-name "20260510115218-emacs_config_file.org"
            org-roam-directory))
    (add-hook 'after-save-hook #'org-babel-tangle nil t))
    
  • Add necessary formatting as explained in the above sections for few sections first. Check whether the export to test file works for few exported sections first.
  • Do repeated testing with diff between actual init.el and test-init.el until no code-snippet is lost.
  • In my case, all the previous outshine headlines at ;;; and ;;;; levels were moved to * and ** in Org Mode. For example, the below

    ;;; Initialization
    ;;;; files and folders
    

    becomes in org mode.

    * Initialization
    ** files and folders
    
  • When the code snippets are inside a Org mode file, the default electric-indent-mode needs to be disabled in Org Mode using a hook. Othewise, every change and enter will keep moving the code inside the block.

    (add-hook 'org-mode-hook
                (lambda ()
      (electric-indent-local-mode -1)))
    
  • Some useful commands to check the progress are listed below:

    $ diff /tmp/test-init.el ~/.config/emacs/init.el > /tmp/diff_output.txt
    $ diff .config/emacs/init.el /data/myhome/prabu/org/Resources/20260510115218-emacs_config_file.org
    
  • Once all the testing is over, then change to the actual filename after taking backup of the original file:

    #+PROPERTY: header-args:emacs-lisp :tangle ~/.config/emacs/init.el :lexical t
    

Active packages

outshine

Outshine attempts to bring the look and feel of Org Mode to the world outside of the Org major-mode. It’s an extension of outline-minor-mode that should act as a replacement of Outline Mode. Just change all your calls to outline-minor-mode into outshine-mode.

This is extremely helpful to manage program code by enabling code easier to group. This package is used in Emacs config file and beancount ledgers.

Obsolete packages

The following packages were installed when i first started using org mode. Now they have been replaced by more simpler alternatives.

helm

Helm is an Emacs framework for incremental completions and narrowing selections. Found more about helm from this webpage. http://tuhdo.github.io/helm-intro.html

Helm is used by various other utilities like org-rifle, helm-swoop etc. Helm based functions are quite powerful. Org Roam functions like find and insert nodes acquire more ease of use with helm.

org-rifle

org-rifle searches rapidly through Org Mode files, quickly bringing the relevant the information. Along with helm it makes Emacs and Org Roam very powerful.

helm-swoop

List match lines from helm to another buffer in Emacs, which is able to squeeze by any words you input. At the same time, the original buffer's cursor is jumping line to line according to moving up and down the line list.

hydra

Hydra is an emacs package that can be used to tie related commands into a family of short bindings with a common prefix - a Hydra.

Basically hydra brings modes concept of vi without using vi or evil mode. some references here..

Resources

Date: 2023-04-16 Sun 09:52

Author: Prabu Anand Kalivaradhan

Created: 2026-10-13 Tue 20:46