Emacs org-mode is an emacs major mode used for note keeping, project planning and for creating documents and articles. It has many export options from markdown to pdf to latex. While all this is great for document generation, it can also be used for creating presentations with org-reveal. Still, this needs a browser and sometimes you really have more text than a few bullet points and want a simpler option to just focus on the text under each heading by narrowing to each heading as you present.

Org-mode has the commands to move to next and previous headings and this combined with narrowing and widening options can really help one to focus on the text that is being presented at the moment.

The following elisp functions define how to focus the org text on each heading. Place this in the init.el emacs configuration file and bind it to the keys of your choice.

The functions use the org-mode builtin functions org-forward-heading-same-level and org-backward-heading-same-level to move to headings. Since these commands are themselves interactive commands we need to call them using the call-interactively function. widen is needed to make headings momentarily visible so that we can jump to the next/previous headings. Call org-narrow-to-subtree to focus only on the heading to be presented.

(defun narrow-to-next-heading ()
  "Narrow to next heading"
  (interactive)
  (widen)
  (call-interactively 'org-forward-heading-same-level nil)
  (org-narrow-to-subtree))

(with-eval-after-load 'org
  (add-hook 'org-mode-hook
	  (lambda ()
	    (local-set-key (kbd "C-c f") 'narrow-to-next-heading))))

(defun narrow-to-prev-heading ()
  "Narrow to prev heading"
  (interactive)
  (widen)
  (call-interactively 'org-backward-heading-same-level nil)
  (org-narrow-to-subtree))

(with-eval-after-load 'org
  (add-hook 'org-mode-hook
	  (lambda ()
	    (local-set-key (kbd "C-c b") 'narrow-to-prev-heading))))

To highlight the current subtree or heading, you can use (org-narrow-to-subtree) / (C-x n s) with cursor inside the block. To move to next/previous subtrees/headings you can use the keybindings defined for those functions. In my case, I’ve bound them to C-c f and C-c b to move forward and backward in the subtrees respectively.

To get back to the entire document run C-x n w to widen. The gif shows how this works in action.

TODO

It would be nice to increase/decrease font size of the highlighted section based on the current window size.

Shortly after I did this, I learnt of a emacs package called org-present which might do all this and more. I plan on trying it out sometime in the future. If nothing, this helped me to brush up on some emacs lisp.