Focused navigation in Markdown

Fold and Focus can now navigate Markdown buffers.

It started with Org

I wrote this Emacs package years ago because I wanted to navigate Org buffers easily and without distraction.

I wanted to press a key that would:

  • navigate to the next or previous subtree and show its contents
  • have that subtree always at the same position in my screen
  • have everything around it folded, so that I could focus on that one subtree and nothing else

The package does that, as you can see in this old gif animation.

Then Emacs Lisp

I also wanted to navigate Emacs Lisp buffers the same way. That idea came naturally, since I already used Outshine.

Outshine gives your Emacs Lisp buffers an Org Mode look and feel, with colored headings that you can handle as if they were Org headings. So you can move up, move down, promote, demote, narrow, widen, fold, expand, insert, cut, and sort Elisp headings.

In Org, your headings start with one or more * followed by space:

* Level 1
** Level 2
*** Level 3

In Elisp, ; is for same-line comment, ;; is for comment-in-its-own-line, and ;;;+ are headings:

;;; Level 1
;;;; Level 2
;;;;; Level 3
;; A comment about the below
(ignore)  ; will be ignored

Adoption of this feature varies.

  • Some people like their Elisp files flat and simple, putting on the same level everything between ;;; Code: and ;;; … ends here.
  • Others, aware and fond of the hierarchy of headings, take full advantage of it to organize their thoughts and packages.

A quick look at this and you'll know which approach I like best.

And now Markdown

So I caught myself trying M-] to fold-and-focus-next in Markdown. "Oh, it doesn't work here."

Now it does.

It's just like the animation I previously linked to, but with Markdown instead of Org.

# Level 1…
## Level 2

Markdown subtree `fold-and-focus` is _currently_ in.

[Some markdown link](./something.md)

```elisp
(setq answer 42)
```

### Level 3a…
### Level 3b…

Plus minor modes

To make things easier, the package can now autodetect when you're in a major mode it supports, so that it can turn on a navigation keymap.

For that, just enable Fold and Focus' global minor modes.

Enjoy.