Extract the second level headline

2019-05-24 12:20发布

问题:

For my global TODO list, I am showing breadcrumbs as suggested here :

(concat \"[ \"(org-format-outline-path (org-get-outline-path)) \" ]\") ") 

to produce following:

I would like to show only the second level of project breadcrumb. So in this case, I would only display [Project A]. I think if I can make a function that can extract the second level, I just need to prepend with %? so that [Tasks] does not appear for Tasks, but only project names would appear for Projects. What would be an ideal way of extracting the second level?

回答1:

All you have to do to get the second element of (org-get-outline-path) is to call nth.

(nth N LIST)

Return the Nth element of LIST. N counts from zero. If LIST is not that long, nil is returned.

The second element is (nth 1 LIST). Replace (org-get-outline-path) with (list (nth 1 (org-get-outline-path))) (we use list because that's what org-format-outline-path expects).