emacs-orgmode
[Top][All Lists]
Advanced

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

[PATCH] Re: How to stop results being hidden when using ":results drawer


From: Ihor Radchenko
Subject: [PATCH] Re: How to stop results being hidden when using ":results drawer"?
Date: Fri, 13 May 2022 21:35:34 +0800

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> This issue is specific to using a scimax function
> `scimax-ob-execute-and-next-block` that executes the current block then
> moves to the next or creates a new block if needed. This is a UI feature
> from jupyter notebooks that I like to use.
>
> That function uses `(org-babel-next-src-block)`, which uses
> org-next-block, which calls org-show-context, which uses
> org-show-set-visibility, which calls org-show-entry, which hides the
> drawers.
>
> It isn't an org-core issue perhaps, other than it is not obvious why
> org-show-entry has a hard-coded line to hide drawers in it.

I'd say that it is org-core issue. The current behaviour does not really
follow what org-fold-show-entry docstring promises:

>> Show the body directly following its heading.

>> Show the heading too, if it is currently invisible.

In fact, forcefully folding the drawers is relatively recent addition by
Nicolas in 1027e0256903bc2.

I am attaching the patch making drawer folding controllable via optional
argument. WDYT?

Best,
Ihor

>From bd3c7ac6162d64a19eff370b7b22ba233f8480ad Mon Sep 17 00:00:00 2001
Message-Id: 
<bd3c7ac6162d64a19eff370b7b22ba233f8480ad.1652448909.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Fri, 13 May 2022 21:30:46 +0800
Subject: [PATCH] org-fold-show-entry: Do not fold drawers unless requested

* lisp/org-fold.el (org-fold-show-entry): Do not fold drawers in the
unfolded entry unless the new optional argument is non-nil.  Folding
the drawers was introduced in 1027e0256903bc2, but does not follow the
function docstring.  Moreover, folding drawers creates unexpected
behaviour in some cases.  See
m2a6bl4mmr.fsf@andrew.cmu.edu">https://orgmode.org/list/m2a6bl4mmr.fsf@andrew.cmu.edu

* etc/ORG-NEWS (~org-fold-show-entry~ does not fold drawers by default
anymore): Document the change.

* lisp/org-agenda.el (org-agenda-show):
(org-agenda-show-and-scroll-up):
(org-agenda-show-1):
* lisp/org-clock.el (org-clock-goto):
* lisp/org-compat.el (outline-toggle-children):
* lisp/org-timer.el (org-timer--get-timer-title):
* lisp/org.el (org-move-subtree-down):
(org-return): Explicitly request folding drawers inside the revealed
entry in the places where it appears to make sense.
---
 etc/ORG-NEWS       | 7 +++++++
 lisp/org-agenda.el | 6 +++---
 lisp/org-clock.el  | 2 +-
 lisp/org-compat.el | 2 +-
 lisp/org-fold.el   | 4 ++--
 lisp/org-timer.el  | 2 +-
 lisp/org.el        | 4 ++--
 7 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 582816534..15986c935 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -190,6 +190,13 @@ installed. It uses Emacs' font-lock information, and so 
tends to
 produce results superior to Minted or Listings.
 
 ** New functions and changes in function arguments
+*** ~org-fold-show-entry~ does not fold drawers by default anymore
+
+~org-fold-show-entry~ now accepts an optional argument HIDE-DRAWERS.
+When the argument is non-nil, the function folds all the drawers
+inside entry.  This was the default previously.
+
+Now, ~org-fold-show-entry~ does not fold drawers by default.
 
 *** New function ~org-element-cache-map~ for quick mapping across Org elements
 
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 0479a0e1f..6fd0e4498 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -9701,7 +9701,7 @@ (defun org-agenda-show (&optional full-entry)
   (interactive "P")
   (let ((win (selected-window)))
     (org-agenda-goto t)
-    (when full-entry (org-fold-show-entry))
+    (when full-entry (org-fold-show-entry 'hide-drawers))
     (select-window win)))
 
 (defvar org-agenda-show-window nil)
@@ -9720,7 +9720,7 @@ (defun org-agenda-show-and-scroll-up (&optional arg)
          (select-window org-agenda-show-window)
          (ignore-errors (scroll-up)))
       (org-agenda-goto t)
-      (org-fold-show-entry)
+      (org-fold-show-entry 'hide-drawers)
       (if arg (org-cycle-hide-drawers 'children)
        (org-with-wide-buffer
         (narrow-to-region (org-entry-beginning-position)
@@ -9764,7 +9764,7 @@ (defun org-agenda-show-1 (&optional more)
      ((and (called-interactively-p 'any) (= more 1))
       (message "Remote: show with default settings"))
      ((= more 2)
-      (org-fold-show-entry)
+      (org-fold-show-entry 'hide-drawers)
       (org-fold-show-children)
       (save-excursion
        (org-back-to-heading)
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index ec87aaf8a..c04a8fdcf 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -1849,7 +1849,7 @@ (defun org-clock-goto (&optional select)
     (pop-to-buffer-same-window (marker-buffer m))
     (if (or (< m (point-min)) (> m (point-max))) (widen))
     (goto-char m)
-    (org-fold-show-entry)
+    (org-fold-show-entry 'hide-drawers)
     (org-back-to-heading t)
     (recenter org-clock-goto-before-context)
     (org-fold-reveal)
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 704197645..8553500d6 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -1400,7 +1400,7 @@ (defadvice outline-toggle-children (around 
outline-toggle-children@fix-for-org-f
               (if (not (org-fold-folded-p (line-end-position)))
                   (org-fold-hide-subtree)
                 (org-fold-show-children)
-                (org-fold-show-entry))))
+                (org-fold-show-entry 'hide-drawers))))
     ad-do-it))
 
 ;; TODO: outline-headers-as-kill
diff --git a/lisp/org-fold.el b/lisp/org-fold.el
index acf7c0761..482b5772b 100644
--- a/lisp/org-fold.el
+++ b/lisp/org-fold.el
@@ -514,7 +514,7 @@ (defun org-fold-hide-sublevels (levels)
       (if (and (bolp) (not (bobp)) (outline-invisible-p (1- (point))))
           (org-fold-region (max (point-min) (1- (point))) (point) nil)))))
 
-(defun org-fold-show-entry ()
+(defun org-fold-show-entry (&optional hide-drawers)
   "Show the body directly following its heading.
 Show the heading too, if it is currently invisible."
   (interactive)
@@ -529,7 +529,7 @@ (defun org-fold-show-entry ()
         (point-max)))
      nil
      'outline)
-    (org-cycle-hide-drawers 'children)))
+    (when hide-drawers (org-cycle-hide-drawers 'children))))
 
 (defalias 'org-fold-show-hidden-entry #'org-fold-show-entry
   "Show an entry where even the heading is hidden.")
diff --git a/lisp/org-timer.el b/lisp/org-timer.el
index 0c9350e76..f8e753edf 100644
--- a/lisp/org-timer.el
+++ b/lisp/org-timer.el
@@ -478,7 +478,7 @@ (defun org-timer--get-timer-title ()
        (with-current-buffer (marker-buffer marker)
          (org-with-wide-buffer
           (goto-char hdmarker)
-          (org-fold-show-entry)
+          (org-fold-show-entry 'hide-drawers)
           (or (ignore-errors (org-get-heading))
               (buffer-name (buffer-base-buffer))))))))
    ((derived-mode-p 'org-mode)
diff --git a/lisp/org.el b/lisp/org.el
index 47a16e94b..0f761e475 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6765,7 +6765,7 @@ (defun org-move-subtree-down (&optional arg)
      (move-marker ins-point nil)
      (if folded
         (org-fold-subtree t)
-       (org-fold-show-entry)
+       (org-fold-show-entry 'hide-drawers)
        (org-fold-show-children))
      (org-clean-visibility-after-subtree-move)
      ;; move back to the initial column we were at
@@ -17261,7 +17261,7 @@ (defun org-return (&optional indent arg interactive)
         (org-auto-align-tags (org-align-tags))
         (t (org--align-tags-here tags-column))) ;preserve tags column
        (end-of-line)
-       (org-fold-show-entry)
+       (org-fold-show-entry 'hide-drawers)
        (org--newline indent arg interactive)
        (when string (save-excursion (insert (org-trim string))))))
      ;; In a list, make sure indenting keeps trailing text within.
-- 
2.35.1


reply via email to

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