* Change in `org-cycle-hook' breaks behavior @ 2022-05-26 16:33 Tor Kringeland 2022-05-27 7:10 ` [PATCH] " Ihor Radchenko 0 siblings, 1 reply; 10+ messages in thread From: Tor Kringeland @ 2022-05-26 16:33 UTC (permalink / raw) To: emacs-orgmode@gnu.org In Org 9.5, `org-cycle-hook' includes `org-cycle-hide-drawers', which hides the drawer after opening the contents of a headline with `org-cycle'. However, if you removed `org-cycle-hide-drawers' from the hook, `org-cycle' would show you the drawers (at least the PROPERTIES one). I relied on this behavior, as I wanted the drawers to be shown when I opened a headline. In Org 9.6 the hook does no longer include `org-cycle-hide-drawers', and this change is mentioned in the NEWS file. The new default behavior is to show a drawer iff it was opened previously. This is fine, but I don't see an easy change to resurrect my previously configuration wiht Org 9.6. Maybe a function `org-cycle-show-drawers' could be added? Implicitly it seems like `org-cycle' previously did contain this functionality. Adding such a function to `org-cycle-hook' would solve my problem. ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] Re: Change in `org-cycle-hook' breaks behavior 2022-05-26 16:33 Change in `org-cycle-hook' breaks behavior Tor Kringeland @ 2022-05-27 7:10 ` Ihor Radchenko 2022-05-27 12:41 ` Tor Kringeland 2022-06-25 5:18 ` Ihor Radchenko 0 siblings, 2 replies; 10+ messages in thread From: Ihor Radchenko @ 2022-05-27 7:10 UTC (permalink / raw) To: Tor Kringeland; +Cc: emacs-orgmode@gnu.org [-- Attachment #1: Type: text/plain, Size: 1284 bytes --] Tor Kringeland <tor.kringeland@ntnu.no> writes: > In Org 9.5, `org-cycle-hook' includes `org-cycle-hide-drawers', which > hides the drawer after opening the contents of a headline with > `org-cycle'. However, if you removed `org-cycle-hide-drawers' from the > hook, `org-cycle' would show you the drawers (at least the PROPERTIES > one). I relied on this behavior, as I wanted the drawers to be shown > when I opened a headline. I assume that you have org-startup-folded set to 't. Then, what you are seeing is caused by org-cycle-set-startup-visibility that folds all the drawers unless org-startup-folded is set to 'showeverything. Previously, the folded drawers (or folded anything) inside folded headline would be automatically unfolded when you unfold the headline. Now, the folding state is independent and we don't need to re-fold the drawers upon unfolding the headline. > Maybe a function `org-cycle-show-drawers' could be added? Implicitly it > seems like `org-cycle' previously did contain this functionality. > Adding such a function to `org-cycle-hook' would solve my problem. A more efficient way could be introducing a new customization similar to org-cycle-hide-block-startup. Say, it can be org-cycle-hide-drawer-startup. See the attached patch. Best, Ihor [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-org-cycle.el-New-custom-setting-org-cycle-hide-drawe.patch --] [-- Type: text/x-patch, Size: 3807 bytes --] From 2312e9280e5267cdcb72406a24068d6ec0a3696e Mon Sep 17 00:00:00 2001 Message-Id: <2312e9280e5267cdcb72406a24068d6ec0a3696e.1653635423.git.yantar92@gmail.com> From: Ihor Radchenko <yantar92@gmail.com> Date: Fri, 27 May 2022 15:09:16 +0800 Subject: [PATCH] org-cycle.el: New custom setting `org-cycle-hide-drawer-startup' * lisp/org-cycle.el (org-cycle-hide-drawer-startup): * lisp/org-cycle.el (org-cycle-set-startup-visibility): Add new customization to control initial folding state of the drawers. * lisp/org.el (org-startup-options): Provide #+STARTUP option for the new setting. Fixes https://list.orgmode.org/m235gww8wg.fsf@ntnu.no/T/#u --- etc/ORG-NEWS | 22 ++++++++++++++++++++++ lisp/org-cycle.el | 12 +++++++++++- lisp/org.el | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 35af94f92..e1e4beaf0 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -271,6 +271,28 @@ The new variable name is =org-plantuml-args=. It now applies to both jar PlantUML file and executable. ** Miscellaneous +*** A new custom setting =org-hide-drawer-startup= to control initial folding state of drawers + +Previously, all the drawers were always folded when opening an Org +file. This only had an effect on the drawers outside folded +headlines. The drawers inside folded headlines were re-folded because +=org-cycle-hide-drawers= was present inside =org-cycle-hook=. + +With the new folding backend, running =org-cycle-hide-drawers= is no +longer needed if all the drawers are truly folded on startup: [[*Folding +state of the drawers is now preserved when cycling headline +visibility]]. However, this has an unwanted effect when a user does +not want the drawers to be folded (see [[id:1d0e0874-8771-40e4-97ac-6746a0e97438][this bug report]]). + +The new custom setting gives more control over initial folding state +of the drawers. When set to =nil= (default is =t=), the drawers are +not folded on startup. + +The folding state can also be controlled on per-file basis using +=STARTUP= keyword: + +: #+startup: hidedrawers +: #+startup: nohidedrawers *** Styles are customizable in ~biblatex~ citation processor diff --git a/lisp/org-cycle.el b/lisp/org-cycle.el index b15ead788..fb7ff4749 100644 --- a/lisp/org-cycle.el +++ b/lisp/org-cycle.el @@ -119,6 +119,16 @@ (defcustom org-cycle-hide-block-startup nil :group 'org-cycle :type 'boolean) +(defcustom org-cycle-hide-drawer-startup t + "Non-nil means entering Org mode will fold all drawers. +This can also be set in on a per-file basis with + +#+STARTUP: hidedrawers +#+STARTUP: nohidedrawers" + :group 'org-startup + :group 'org-cycle + :type 'boolean) + (defcustom org-cycle-global-at-bob nil "Cycle globally if cursor is at beginning of buffer and not at a headline. @@ -603,7 +613,7 @@ (defun org-cycle-set-startup-visibility () (when org-cycle-hide-block-startup (org-fold-hide-block-all)) (org-cycle-set-visibility-according-to-property) (org-cycle-hide-archived-subtrees 'all) - (org-cycle-hide-drawers 'all) + (when org-cycle-hide-drawer-startup (org-cycle-hide-drawers 'all)) (org-cycle-show-empty-lines t))) (defun org-cycle-set-visibility-according-to-property () diff --git a/lisp/org.el b/lisp/org.el index 0eb819f23..be9900d68 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -3984,6 +3984,8 @@ (defconst org-startup-options ("noptag" org-tag-persistent-alist nil) ("hideblocks" org-hide-block-startup t) ("nohideblocks" org-hide-block-startup nil) + ("hidedrawers" org-hide-drawer-startup t) + ("nohidedrawers" org-hide-drawer-startup nil) ("beamer" org-startup-with-beamer-mode t) ("entitiespretty" org-pretty-entities t) ("entitiesplain" org-pretty-entities nil)) -- 2.35.1 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH] Re: Change in `org-cycle-hook' breaks behavior 2022-05-27 7:10 ` [PATCH] " Ihor Radchenko @ 2022-05-27 12:41 ` Tor Kringeland 2022-05-28 3:31 ` Ihor Radchenko 2022-06-25 5:18 ` Ihor Radchenko 1 sibling, 1 reply; 10+ messages in thread From: Tor Kringeland @ 2022-05-27 12:41 UTC (permalink / raw) To: Ihor Radchenko; +Cc: emacs-orgmode@gnu.org Ihor Radchenko <yantar92@gmail.com> writes: > I assume that you have org-startup-folded set to 't. Then, what you are > seeing is caused by org-cycle-set-startup-visibility that folds all the > drawers unless org-startup-folded is set to 'showeverything. Yes, that is my customization :) > A more efficient way could be introducing a new customization similar to > org-cycle-hide-block-startup. Say, it can be > org-cycle-hide-drawer-startup. See the attached patch. That sounds good. But this would only fold the drawers when starting org-mode, right? Basicall my configuration has been to remove `org-cycle-hide-drawers' from `org-cycle-hook', which opened all the drawers whenever I called `org-cycle' (bound to TAB). I also had a custom function where I added `org-cycle-hide-drawers' back to the hook and then called `org-cycle' (bound to C-TAB). This way I could toggle showing/not showing the drawers when opening a headline in any Org buffer. (Both of them would ignore the visibility of the drawers in the headline and show them/hide them unconditionally. I can always hide the drawers by adding `org-cycle-hide-drawers' to `org-cycle-hook' when I call my custom function, but I cannot replicate the behavior of `org-cycle' without `org-cycle-hide-drawers' in the hook, which would uncoditionally open all the drawers (AFAIK).) ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Re: Change in `org-cycle-hook' breaks behavior 2022-05-27 12:41 ` Tor Kringeland @ 2022-05-28 3:31 ` Ihor Radchenko 2022-05-28 12:06 ` Tor Kringeland 0 siblings, 1 reply; 10+ messages in thread From: Ihor Radchenko @ 2022-05-28 3:31 UTC (permalink / raw) To: Tor Kringeland; +Cc: emacs-orgmode@gnu.org Tor Kringeland <tor.kringeland@ntnu.no> writes: >> A more efficient way could be introducing a new customization similar to >> org-cycle-hide-block-startup. Say, it can be >> org-cycle-hide-drawer-startup. See the attached patch. > > I can always hide the > drawers by adding `org-cycle-hide-drawers' to `org-cycle-hook' when I > call my custom function, but I cannot replicate the behavior of > `org-cycle' without `org-cycle-hide-drawers' in the hook, which would > uncoditionally open all the drawers (AFAIK).) Sure. Now, you need to call a different function to open all the drawers unconditionally. That function is: (let* ((headline (save-excursion (org-back-to-heading) (org-element-at-point))) (section (org-element-lineage (org-element-at-point (org-element-property :contents-begin headline)) '(section)))) (when section (org-fold-region (org-element-property :begin section) (org-element-property :end section) nil 'drawer))) Though we might also modify org-fold-show-entry to allow what you wish. I am not sure here. Best, Ihor ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Re: Change in `org-cycle-hook' breaks behavior 2022-05-28 3:31 ` Ihor Radchenko @ 2022-05-28 12:06 ` Tor Kringeland 2022-05-28 12:10 ` Tor Kringeland 2022-05-28 12:40 ` Ihor Radchenko 0 siblings, 2 replies; 10+ messages in thread From: Tor Kringeland @ 2022-05-28 12:06 UTC (permalink / raw) To: Ihor Radchenko; +Cc: emacs-orgmode@gnu.org Ihor Radchenko <yantar92@gmail.com> writes: > Sure. Now, you need to call a different function to open all the drawers > unconditionally. That function is: > > (let* ((headline (save-excursion (org-back-to-heading) (org-element-at-point))) > (section (org-element-lineage > (org-element-at-point > (org-element-property :contents-begin headline)) > '(section)))) > (when section > (org-fold-region > (org-element-property :begin section) > (org-element-property :end section) > nil 'drawer))) Thanks! This almost imitates the old behavior, except that all drawers (i.e., including sub-headlines) would be opened when the headline it was a part of was opened. (So pressing TAB multiple times would first show the outline with the first headline open, then the next would show sub-headlines with their drawers open.) > Though we might also modify org-fold-show-entry to allow what you wish. > I am not sure here. That sounds nice. So an optional behavior would be for it to open the drawers as well, which I guess would lead to the "recursive" behavior above I mentioned working, right? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Re: Change in `org-cycle-hook' breaks behavior 2022-05-28 12:06 ` Tor Kringeland @ 2022-05-28 12:10 ` Tor Kringeland 2022-05-28 12:40 ` Ihor Radchenko 1 sibling, 0 replies; 10+ messages in thread From: Tor Kringeland @ 2022-05-28 12:10 UTC (permalink / raw) To: Ihor Radchenko; +Cc: emacs-orgmode@gnu.org Tor Kringeland <tor.kringeland@ntnu.no> writes: > a part of was opened. (So pressing TAB multiple times would first show > the outline with the first headline open, then the next would show > sub-headlines with their drawers open.) Correction: it wouldn't show the drawer of the headline on the first TAB press. But on the second TAB press it would show everything, including drawers of sub-headlines. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Re: Change in `org-cycle-hook' breaks behavior 2022-05-28 12:06 ` Tor Kringeland 2022-05-28 12:10 ` Tor Kringeland @ 2022-05-28 12:40 ` Ihor Radchenko 2022-05-28 14:14 ` Tor Kringeland 1 sibling, 1 reply; 10+ messages in thread From: Ihor Radchenko @ 2022-05-28 12:40 UTC (permalink / raw) To: Tor Kringeland; +Cc: emacs-orgmode@gnu.org Tor Kringeland <tor.kringeland@ntnu.no> writes: > Ihor Radchenko <yantar92@gmail.com> writes: > >> Sure. Now, you need to call a different function to open all the drawers >> unconditionally. That function is: >> > Thanks! This almost imitates the old behavior, except that all drawers > (i.e., including sub-headlines) would be opened when the headline it was > a part of was opened. (So pressing TAB multiple times would first show > the outline with the first headline open, then the next would show > sub-headlines with their drawers open.) I am a bit confused. The code I provided should only open the drawers inside the headline at point, before its first child (if any). If you have * headline :drawer: test :end: ** child :drawer2: test :end: then only "drawer" will be revealed. Not "drawer2". If you want all the drawers in all the children to be opened, you can instead do the following: (let* ((headline (save-excursion (org-back-to-heading) (org-element-at-point)))) (when headline (org-fold-region (org-element-property :begin headline) (org-element-property :end headline) nil 'drawer))) >> Though we might also modify org-fold-show-entry to allow what you wish. >> I am not sure here. > > That sounds nice. So an optional behavior would be for it to open the > drawers as well, which I guess would lead to the "recursive" behavior > above I mentioned working, right? I am not sure. Can you elaborate what exactly you want to achieve? Best, Ihor ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Re: Change in `org-cycle-hook' breaks behavior 2022-05-28 12:40 ` Ihor Radchenko @ 2022-05-28 14:14 ` Tor Kringeland 2022-05-29 12:19 ` Ihor Radchenko 0 siblings, 1 reply; 10+ messages in thread From: Tor Kringeland @ 2022-05-28 14:14 UTC (permalink / raw) To: Ihor Radchenko; +Cc: emacs-orgmode@gnu.org Ihor Radchenko <yantar92@gmail.com> writes: > If you want all the drawers in all the children to be opened, you can > instead do the following: > > (let* ((headline (save-excursion (org-back-to-heading) (org-element-at-point)))) > (when headline > (org-fold-region > (org-element-property :begin headline) > (org-element-property :end headline) > nil 'drawer))) Thanks, this does exactly what I want when I add it as a hook to `org-cycle' :) > I am not sure. Can you elaborate what exactly you want to achieve? For me in Org 9.5 `org-cycle' without `org-cycle-hide-drawers' would do the following (on each tab press) #+begin_example * first... --> TAB * first :PROPERTIES:... ** second ** third --> TAB * first :PROPERTIES :ID: abc :END: ** second :PROPERTIES :ID: cba :END: ** third :PROPERTIES :ID: 123 :END: --> TAB * first... #+end_example So adding the code you sent as a hook to `org-cycle' (and ignoring the STATE argument) the same behavior is replicated, except that on the first TAB press, the properties of the =first= headline is shown. I'm indifferent to whether its properties are shown on the first TAB press or not, though (the most important thing was just to get all the properties of the secondary headlines on the second TAB press), so your code solves my issue. Thanks again. Maybe a function like that could be added to Org, that the user could add to `org-cycle-hooks' to produce the "opposite" of `org-cycle-hide-drawers'/does what `org-cycle' used to do without `org-cycle-hide-drawers' in the hook in Org 9.5? ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Re: Change in `org-cycle-hook' breaks behavior 2022-05-28 14:14 ` Tor Kringeland @ 2022-05-29 12:19 ` Ihor Radchenko 0 siblings, 0 replies; 10+ messages in thread From: Ihor Radchenko @ 2022-05-29 12:19 UTC (permalink / raw) To: Tor Kringeland; +Cc: emacs-orgmode@gnu.org Tor Kringeland <tor.kringeland@ntnu.no> writes: > Maybe a function like that could be added to Org, that the user could > add to `org-cycle-hooks' to produce the "opposite" of > `org-cycle-hide-drawers'/does what `org-cycle' used to do without > `org-cycle-hide-drawers' in the hook in Org 9.5? I will take a note on this for future reference. I do not plan to implement it yet, unless other people jump in and ask for this feature. Generally, org-fold.el can be restructured a bit better given that we have the working cache now and can generalize many old functions from org-fold. Best, Ihor ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] Re: Change in `org-cycle-hook' breaks behavior 2022-05-27 7:10 ` [PATCH] " Ihor Radchenko 2022-05-27 12:41 ` Tor Kringeland @ 2022-06-25 5:18 ` Ihor Radchenko 1 sibling, 0 replies; 10+ messages in thread From: Ihor Radchenko @ 2022-06-25 5:18 UTC (permalink / raw) To: Tor Kringeland; +Cc: emacs-orgmode@gnu.org Ihor Radchenko <yantar92@gmail.com> writes: > A more efficient way could be introducing a new customization similar to > org-cycle-hide-block-startup. Say, it can be > org-cycle-hide-drawer-startup. See the attached patch. Applied onto main via bcfed0f34. Best, Ihor ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-06-25 5:18 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-05-26 16:33 Change in `org-cycle-hook' breaks behavior Tor Kringeland 2022-05-27 7:10 ` [PATCH] " Ihor Radchenko 2022-05-27 12:41 ` Tor Kringeland 2022-05-28 3:31 ` Ihor Radchenko 2022-05-28 12:06 ` Tor Kringeland 2022-05-28 12:10 ` Tor Kringeland 2022-05-28 12:40 ` Ihor Radchenko 2022-05-28 14:14 ` Tor Kringeland 2022-05-29 12:19 ` Ihor Radchenko 2022-06-25 5:18 ` Ihor Radchenko
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).