emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@gmail.com>
To: Tor Kringeland <tor.kringeland@ntnu.no>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: [PATCH] Re: Change in `org-cycle-hook' breaks behavior
Date: Fri, 27 May 2022 15:10:53 +0800	[thread overview]
Message-ID: <87a6b3zc02.fsf@localhost> (raw)
In-Reply-To: <m235gww8wg.fsf@ntnu.no>

[-- 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.


[-- 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

* 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-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))

  reply	other threads:[~2022-05-27  7:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-26 16:33 Change in `org-cycle-hook' breaks behavior Tor Kringeland
2022-05-27  7:10 ` Ihor Radchenko [this message]
2022-05-27 12:41   ` [PATCH] " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a6b3zc02.fsf@localhost \
    --to=yantar92@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=tor.kringeland@ntnu.no \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


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).