2017-01-22 Current headline or path in Org-mode

Today I have a short Elisp/Org-mode tip, in case you need something like this (I did a few weeks ago). If you want to get the headline the point is in, you can just eval (org-get-heading t t) (see the docstring to learn the meaning of the two t’s). This gives you a propertized string, which may or may not be what you want; you can say (substring-no-properties (org-get-heading t t)) to get a string without any properties.

In case you want to get the whole path to the current headline, Org-mode has you covered, too: (org-get-outline-path t) (again, check the docs to know when you want to use a non-nil first argument). This gives you a list of strings; in order to concatenate it into one string with some kind of separator, you can use the built-in (and quite useful) mapconcat function, e.g. like this: (mapconcat #'identity (org-get-outline-path t) "/")

That’s it for today, folks!

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode