org-fold: Fix isearch when `org-fold-core-style' is 'overlays

* lisp/org-fold-core.el (org-fold-core--isearch-show): Make sure that
the actual isearch match is revealed.  This relies on undocumented
behavior of isearch that point is at the match when
'isearch-open-invisible is called.
(org-fold-core-region): Disable 'isearch-open-invisible-temporary
features when `org-fold-core-style' is 'overlays.  This is to work
around the undocumented requirement of isearch to _not_ delete the
overlay passed to 'isearch-open-invisible-temporary function.  Since
`org-fold-show-set-visibility' may destroy overlays arbitrarily, we
cannot currently support isearch `org-fold-show-context-detail' in
full.

Reported-by: Matt Lundin <mdl@imapmail.org>
Link: https://orgmode.org/list/87zgb6tk6h.fsf@localhost
This commit is contained in:
Ihor Radchenko 2023-01-16 12:21:57 +03:00
parent 2e22a8b827
commit df4a5d86d8
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 10 additions and 11 deletions

View File

@ -1003,7 +1003,13 @@ If SPEC-OR-ALIAS is omitted and FLAG is nil, unfold everything in the region."
(overlay-put o (org-fold-core--property-symbol-get-create spec) spec)
(overlay-put o 'invisible spec)
(overlay-put o 'isearch-open-invisible #'org-fold-core--isearch-show)
(overlay-put o 'isearch-open-invisible-temporary #'org-fold-core--isearch-show-temporary))
;; FIXME: Disabling to work around Emacs bug#60399
;; and https://orgmode.org/list/87zgb6tk6h.fsf@localhost.
;; The proper fix will require making sure that
;; `org-fold-core-isearch-open-function' does not
;; delete the overlays used by isearch.
;; (overlay-put o 'isearch-open-invisible-temporary #'org-fold-core--isearch-show-temporary)
)
(put-text-property from to (org-fold-core--property-symbol-get-create spec) spec)
(put-text-property from to 'isearch-open-invisible #'org-fold-core--isearch-show)
(put-text-property from to 'isearch-open-invisible-temporary #'org-fold-core--isearch-show-temporary)
@ -1131,16 +1137,9 @@ This function is intended to be used as `isearch-filter-predicate'."
"Clear `org-fold-core--isearch-local-regions'."
(clrhash org-fold-core--isearch-local-regions))
(defun org-fold-core--isearch-show (region)
"Reveal text in REGION found by isearch.
REGION can also be an overlay in current buffer."
(when (overlayp region)
(setq region (cons (overlay-start region)
(overlay-end region))))
(org-with-point-at (car region)
(while (< (point) (cdr region))
(funcall org-fold-core-isearch-open-function (car region))
(goto-char (org-fold-core-next-visibility-change (point) (cdr region) 'ignore-hidden)))))
(defun org-fold-core--isearch-show (_)
"Reveal text at point found by isearch."
(funcall org-fold-core-isearch-open-function (point)))
(defun org-fold-core--isearch-show-temporary (region hide-p)
"Temporarily reveal text in REGION.