Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org-mode: go back from sparse tree to previous visibility

Tags:

emacs

org-mode

After filtering my document to a sparse tree, how do I undo the filter, going back to the previous view/visibility? Because I haven't worked out how to do this out I have to make everything visible, which isn't nice in big documents. Seems like it must be obvious but I can't find the answer...

like image 662
jaybee Avatar asked Jul 12 '11 15:07

jaybee


5 Answers

According to Bastien on the org mailing list, this isn't possible and is a long-standing wishlist item.

like image 53
jaybee Avatar answered Nov 13 '22 04:11

jaybee


I'm not sure you can go back to the exact previous view. But one first step is C-c C-c which will remove temporary highlights/overlays from the current buffer.

like image 23
xevincent Avatar answered Nov 13 '22 03:11

xevincent


This looks like it might be possible to me. In the following code I use some advice to save the outline state before generating the sparse tree, and to restore it when it is cleared via C-c C-c.

(setq lexical-binding t)

(let ((*outline-data* nil))
  (defun org-save-outline-state (&optional arg type)
    (setq *outline-data* (org-outline-overlay-data t)))

  (defun org-restore-outline-state (&optional arg)
    (when *outline-data*
      (org-set-outline-overlay-data *outline-data*)
      (setq *outline-data* nil))))

(advice-add 'org-sparse-tree :before 'org-save-outline-state)
(advice-add 'org-match-sparse-tree :before 'org-save-outline-state)
(advice-add 'org-ctrl-c-ctrl-c :after 'org-restore-outline-state)

It seems to do what you want.

like image 4
John Kitchin Avatar answered Nov 13 '22 03:11

John Kitchin


You can create two windows using C-x 2, then switch to the other window, do the sparse tree. When you are done simply go back to the original window and press C-x 1 to close the sparse tree window.

like image 2
user2013585 Avatar answered Nov 13 '22 03:11

user2013585


You probably cannot go back to the same view as before.

But there are 3 steps to remove the spare tree effects:

  1. org-agenda-remove-restriction-lock to remove the locked items' highlighted background.

  2. org-remove-occur-highlights to remove the prefix's highlight.

  3. widen to remove the restriction to the special entry, and expand to view the full file.

like image 1
mick3dell Avatar answered Nov 13 '22 05:11

mick3dell