emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] fold all drawers in a buffer?


From: Thorsten Jolitz
Subject: Re: [O] fold all drawers in a buffer?
Date: Fri, 01 Nov 2013 17:43:15 +0100
User-agent: Gnus/5.130002 (Ma Gnus v0.2) Emacs/24.3 (gnu/linux)

Thorsten Jolitz <address@hidden> writes:

> Matt Price <address@hidden> writes:
>
>> Is there a command to fold all drawers in a buffer (all property
>> drawers would be enough, actually)? Or a suggestion for how to do
>> this?   Thanks!
>
> They might exist (with me unaware of them), but the following pair of
> commands does the job, at least with this minimal test org snippet:
>
> * A
>   :PROPERTIES:
>   :CUSTOM_ID: a1
>   :END:
> * B
>   :PROPERTIES:
>   :CUSTOM_ID: B1
>   :END:
>
> #+begin_src emacs-lisp
>   (defun org-show-drawers ()
>     "Unfold all drawers in buffer"
>     (interactive)
>     (save-excursion
>       (goto-char (point-min))
>       (while (not (eobp))
>         (and (org-at-drawer-p)
>              (org-element-property :hiddenp (org-element-at-point))
>              (org-cycle))
>         (forward-char))))
>   
>   (defun org-hide-drawers ()
>     "Fold all drawers in buffer"
>     (interactive)
>     (save-excursion
>       (goto-char (point-min))
>       (while (not (eobp))
>         (and (org-at-drawer-p)
>              (not (org-element-property :hiddenp (org-element-at-point)))
>              (org-cycle))
>         (forward-char))))
> #+end_src
>
> #+results:
> : org-hide-drawers

I tested the above functions with a big org file - way to slow. 
These versions perfom better, but only on property drawers:

#+begin_src emacs-lisp
  (defun org-show-drawers ()
    "Unfold all drawers in buffer"
    (interactive)
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward org-property-start-re nil 'NOERROR)
             (and (org-element-property :hiddenp (org-element-at-point))
             (org-cycle)))))

  (defun org-hide-drawers ()
    "Unfold all drawers in buffer"
    (interactive)
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward org-property-start-re nil 'NOERROR)
             (and (not (org-element-property :hiddenp (org-element-at-point)))
             (org-cycle)))))
#+end_src

-- 
cheers,
Thorsten




reply via email to

[Prev in Thread] Current Thread [Next in Thread]