I'm using org-mode with really huge files (what I love in org-mode is having everything in a single file).

I would like to know where I am in the file by having a look at the modeline.

If I have the following :

* Foo
** Bar
*** Dump
[cursor being here]
** Egg

I'd like the modeline to show me something like Foo > Bar > Dump

Any ideas on how to achieve that?


The which-function minor mode by default shows part of the org outline path in the mode line; you can turn it on using M-x which-function-mode. In general, which-function tries to show the current function in the mode line. It works in most languages.

If you want to see the entire path, you just have to add a new function to the variable which-func-functions. The first function in this list that returns non-nil is what which-function uses. Here is a function that uses org-outline-path to get the full path, if the current major mode is org-mode

(defun org-which-function ()
  (when (eq major-mode 'org-mode)
    (mapconcat 'identity (org-get-outline-path t)
               " > ")

(add-to-list 'which-func-functions #'org-which-function)

You will quickly run out of room in your mode line, so try putting it in the header line instead. For example, this snippet will put the current buffer name and the outline path in the header:

(setq header-line-format
    " "
  • Nice. I didn't know about org-get-outline-path: using it would streamline the post I had made considerably. – Dan Feb 20 '17 at 19:40
  • @erikstokes I'm using Emacs 24, and getting Symbol's value as variable is void: which-func-functions while trying your code ; does it require recent emacs ? – Jocelyn delalande Feb 21 '17 at 22:45
  • @Jocelyndelalande It's in 24.5 at least. The repo history makes it look likes it's been around a long time. Try running (require which-func) first to make sure it's loaded. – erikstokes Feb 21 '17 at 23:06

The following is an interactive command that will give you your location within the current org-mode tree:

(defun org-where-am-i ()
  "Returns a string of headers indicating where point is in the
current tree."
  (let (headers)
      (while (condition-case nil
                   (push (nth 4 (org-heading-components)) headers) 
                   (outline-up-heading 1))
               (error nil))))
    (message (mapconcat #'identity headers " > "))))

I'd actually suggest not putting it in the modeline, if for no other reason than the fact that it'll take over the whole thing. Instead, I'd suggest you bind the command to a key and call it whenever you want to know where you are.

(Note: if you really want to put it in the modeline, you'll want to remove the call to message in the last line.)

  • The header-line might also be a reasonable place to put this. – amitp Feb 20 '17 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.