when given a file

* HeaderNoTask
** TODO Task 1
** TODO Task 2
* TODO HeaderTask 1
* TODO HeaderTask  2

I would like to get the first TODO from HeaderNoTask and all Level 1 Headers marked as TODO

I found those functions online, but this will only yield Task 1 and HeaderTask 1.

(defun my-org-agenda-skip-all-siblings-but-first ()
  "Skip all but the first non-done entry."
  (let (should-skip-entry)
    (unless (org-current-is-todo)
      (setq should-skip-entry t))
      (while (and (not should-skip-entry) (org-goto-sibling t))
        (when (org-current-is-todo)
          (setq should-skip-entry t))))
    (when should-skip-entry
      (or (outline-next-heading)
          (goto-char (point-max))))))

(defun org-current-is-todo ()
  (string= "TODO" (org-get-todo-state)))

How can I include a condition to not skip all but the first Level 1 Headers? I can't seem to find a function to read the level of the current entry, but I might be just looking for the wrong words.

  • I don't know if it helps you, but the function that returns the level of the current entry is org-current-level.
    – NickD
    Jul 4 at 16:23

Your Answer

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

Browse other questions tagged or ask your own question.