0

I'm using the answer from this question Make all done org-mode items invisible (collapsed)

which works perfectly. I want to make an modification so that if I have the following:

* TODO header
** HOLD header2
** DONE header3

It can collapse the HOLD state as well.

Thanks

1 Answer 1

1

Make all done org-mode items invisible (collapsed)

Unlike the snippet there, the snippet here is easy to understand.

org-ql query here is

(org-ql-query :select 'element
              :from (current-buffer)
              :where '(or (done) (todo "HOLD"))  
              :order-by 'date)

and the action used is

(outline-hide-subtree)

  1. Install org-ql: Query language for Org files
  2. emacs -Q, and ensure that the org-ql library is available
  3. Copy the below snippet to demo.org
#+TODO: TODO HOLD | DONE CANCELED

* TODO header

Esse ea consequat id magna exercitation nisi ipsum.  In irure officia
cillum sed sunt ad non.

** HOLD header2

Officia ullamco anim minim id deserunt consequat esse.  Et sit officia
quis ipsum lorem et nostrud commodo nisi est dolor ullamco laboris.
Fugiat exercitation consequat proident, do proident, consequat sit
lorem consequat velit occaecat sed cillum est.  Occaecat ut nostrud
proident, quis id enim sit.  Minim nulla aute qui laborum lorem
occaecat veniam, elit, laboris elit, nulla eiusmod sint fugiat ex
reprehenderit consequat.

** DONE header3

Duis tempor sit incididunt ex sint sit aute esse dolore tempor.
Incididunt ullamco aliqua est tempor cupidatat duis anim ut tempor
amet, veniam, voluptate sunt reprehenderit dolore velit.


This is how the demo.org buffer looks

demo.org has a mix of TODO, HOLD and DONE items

demo.org

  1. Copy the following snippet to *scratch*, and do M-x eval-buffer
(defun my-org-hide-HOLD-and-DONE-items ()
  (interactive)
  (outline-show-all)
  (org-with-wide-buffer
   (dolist (headline (org-ql-query :select 'element
                                   :from (current-buffer)
                                   :where '(or (done) (todo "HOLD"))  
                                   :order-by 'date))
     (let ((start (org-element-property :begin headline)))
       (goto-char start)
       (outline-hide-subtree)))))
  1. C-x C-f demo.org and do M-x my-org-hide-HOLD-and-DONE-items. This is what you will see

demo.org with HOLD and TODO items folded

demo.org with HOLD and TODO items folded

1
  • Thank you so much! Never heard of Org-ql before this is really easy to use. I had a follow up, so I also have some headers that don't have TODO states, I figured out that you can do (todo) to get all states, but I couldn't get the inverse of that. * header ** HOLD header2 ** DONE header3 Commented Oct 18, 2022 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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