1

Hi I would like to make this function show a tree with headings in NEXT and WAITING status.

    (defun show-NEXT-in-subtree ()
       "Narrow to a subtree and show only headings with NEXT and WAITING keywords"
       (interactive)
       (org-narrow-to-subtree)
       (org-show-todo-tree '(3 4)) ;; NEXT|WAITING
       (org-ctrl-c-ctrl-c))

I don't understand how to do it in the correct way according to help.

With a prefix argument (or by using C-c / T), search for a specific TODO. You will be prompted for the keyword, and you can also give a list of keywords like KWD1|KWD2|... to list entries that match any one of these keywords. With a numeric prefix argument N, show the tree for the Nth keyword in the option org-todo-keywords.

4
  • Try (org-show-todo-tree "NEXT|WAITING") ? – NickD Aug 3 '20 at 17:50
  • @NickD this results in the tree only showing the first keyword (aka org-show-todo-tree 1) I tried to pass the universal argument (org-show-todo-tree '(4)) but then emacs propmts me to enter the keywords instead of accepting predefined ones. – breathe_in_breathe_out Aug 3 '20 at 18:08
  • See my answer: org-show-todo-tree is pretty useless in a lisp program - it is meant to be used interactively. – NickD Aug 3 '20 at 18:25
2

org-show-todo-tree is incorrigibly interactive, so we go under the covers and see that it uses org-occur to find what it wants. That allows us to bypass it altogether and write your function like this:

 (defun show-NEXT-in-subtree ()
       "Narrow to a subtree and show only headings with NEXT and WAITING keywords"
       (interactive)
       (org-narrow-to-subtree)
       (org-occur (concat "^" org-outline-regexp " *" "\\(NEXT\\|WAITING\\)"))
       (org-ctrl-c-ctrl-c))

That constructs the regexp that we give to org-occur explicitly: beginning of line, stars, spaces and then either NEXT or WAITING. There are easier ways to do the regexp perhaps, but these are new tricks and I am an old dog.

1
  • I use same same behavior in my org workflow. if you add (outline-up-heading 4) inside of the function also you will not need to put cursor to the exact point. Disadvantage it gives more visibility :) – itirazimvar Aug 3 '20 at 23:02

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.