branch: externals/org commit d1e8023eb3b1a1bdbc7210cfa81d6f600c91e49d Author: Ihor Radchenko <yanta...@posteo.net> Commit: Ihor Radchenko <yanta...@posteo.net>
Do not assume that folded == invisible * lisp/org-compat.el (outline-back-to-heading): (outline-toggle-children): * lisp/org-cycle.el (org-cycle-internal-local): * lisp/org-src.el (org-edit-src-exit): * lisp/org.el (org-back-to-heading): (org-at-heading-p): Test for invisibility when we do care about text being actually invisible. (org-insert-heading): Consider all types of folds. * lisp/org-fold-core.el: Add a comment clarifying that folded regions might sometimes be visible. This can happen, in particular, during isearch, when fold overlays are temporarily made visible, but the folds themselves are still retained. Reported-by: Brett <brett.kerw...@gmail.com> Link: https://orgmode.org/list/CACZEyLjR2NMpK3At3R2tYBxDfyXGy8Yiu=m0ececscysb+1...@mail.gmail.com --- lisp/org-compat.el | 5 ++--- lisp/org-cycle.el | 2 +- lisp/org-fold-core.el | 5 +++++ lisp/org-src.el | 2 +- lisp/org.el | 9 ++++----- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lisp/org-compat.el b/lisp/org-compat.el index 4f58a6351c..189b0ac1db 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -78,7 +78,6 @@ (declare-function speedbar-line-directory "speedbar" (&optional depth)) (declare-function table--at-cell-p "table" (position &optional object at-column)) (declare-function ob-clojure-eval-with-cmd "ob-clojure" (cmd expanded)) -(declare-function org-fold-folded-p "org-fold" (&optional pos spec-or-alias)) (declare-function org-fold-hide-sublevels "org-fold" (levels)) (declare-function org-fold-hide-subtree "org-fold" ()) (declare-function org-fold-region "org-fold" (from to flag &optional spec)) @@ -1953,7 +1952,7 @@ key." (or (re-search-backward (concat "^\\(?:" outline-regexp "\\)") nil t) (signal 'outline-before-first-heading nil)) - (setq found (and (or invisible-ok (not (org-fold-folded-p))) + (setq found (and (or invisible-ok (not (org-invisible-p))) (point))))) (goto-char found) found))) @@ -1982,7 +1981,7 @@ key." (if (derived-mode-p 'org-mode) (save-excursion (org-back-to-heading) - (if (not (org-fold-folded-p (line-end-position))) + (if (not (org-invisible-p (line-end-position))) (org-fold-hide-subtree) (org-fold-show-children) (org-fold-show-entry 'hide-drawers))) diff --git a/lisp/org-cycle.el b/lisp/org-cycle.el index 3f90701ac5..fce1063a00 100644 --- a/lisp/org-cycle.el +++ b/lisp/org-cycle.el @@ -518,7 +518,7 @@ Use `\\[org-edit-special]' to edit table.el tables")) (forward-line 1) (if (eq org-fold-core-style 'text-properties) (while (and (not (eobp)) ;this is like `next-line' - (org-fold-folded-p (1- (point)))) + (org-invisible-p (1- (point)))) (goto-char (org-fold-next-visibility-change nil nil t)) (and (eolp) (forward-line 1))) (while (and (not (eobp)) ;this is like `next-line' diff --git a/lisp/org-fold-core.el b/lisp/org-fold-core.el index 7d53e82702..e737e89990 100644 --- a/lisp/org-fold-core.el +++ b/lisp/org-fold-core.el @@ -28,6 +28,11 @@ ;; This file contains library to control temporary invisibility ;; (folding and unfolding) of text in buffers. +;; Do note that something being folded does not necessarily mean +;; that it is invisible. Folded regions might be permanently visible +;; by the means of `:visible' folding spec or because isearch +;; temporarily revealed the folds. + ;; The file implements the following functionality: ;; ;; - Folding/unfolding regions of text diff --git a/lisp/org-src.el b/lisp/org-src.el index 1f29a87198..971d6e938f 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -1516,7 +1516,7 @@ EVENT is passed to `mouse-set-point'." (goto-char beg) (cond ;; Block is hidden; move at start of block. - ((org-fold-folded-p nil 'block) (forward-line -1)) + ((org-invisible-p) (forward-line -1)) (write-back (org-src--goto-coordinates coordinates beg end)))) ;; Clean up left-over markers and restore window configuration. (set-marker beg nil) diff --git a/lisp/org.el b/lisp/org.el index ad66edda5b..c4d02e343c 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -6582,9 +6582,8 @@ Assume that point is on the inserted heading." (cond ((org-fold-folded-p (max (point-min) - (1- (line-beginning-position))) - 'headline) - (org-fold-region (line-end-position 0) (line-end-position) nil 'headline)) + (1- (line-beginning-position)))) + (org-fold-region (line-end-position 0) (line-end-position) nil)) (t nil)) (pcase (get-char-property-and-overlay (point) 'invisible) (`(outline . ,o) @@ -21129,7 +21128,7 @@ interactive command with similar behavior." (org-element-at-point) (lambda (el) (goto-char (org-element-begin el)) - (or invisible-ok (not (org-fold-folded-p)))) + (or invisible-ok (not (org-invisible-p)))) '(headline inlinetask) 'with-self 'first-match) (user-error "Before first headline at position %d in buffer %s" @@ -21162,7 +21161,7 @@ Respect narrowing." If INVISIBLE-NOT-OK is non-nil, an invisible heading line is not ok." (save-excursion (forward-line 0) - (and (or (not invisible-not-ok) (not (org-fold-folded-p))) + (and (or (not invisible-not-ok) (not (org-invisible-p))) (looking-at outline-regexp)))) (defun org-in-commented-heading-p (&optional no-inheritance element)