From bbd9727aa82230218420b1817d3e8f3b716b614f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?El=C3=ADas=20Gabriel=20P=C3=A9rez?= Date: Mon, 17 Nov 2025 21:17:46 -0600 Subject: [PATCH] hideshow: Add modification hooks to remove the hidden blocks bug#79865 * lisp/progmodes/hideshow.el (hs--discard-overlay-after-change): New function. (hs-make-overlay): Use the new function. --- lisp/progmodes/hideshow.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el index 78990993449..9474332e269 100644 --- a/lisp/progmodes/hideshow.el +++ b/lisp/progmodes/hideshow.el @@ -752,6 +752,15 @@ block at point." (when-let* ((block (hs-block-positions))) (apply #'hs-hideable-region-p block)))) +(defun hs--discard-overlay-after-change (o &rest _r) + "Remove overlay O after changes. +Intended to be used in `modification-hooks', `insert-in-front-hooks' and +`insert-behind-hooks'." + (let ((beg (overlay-start o)) + (end (overlay-end o))) + (delete-overlay o) + (hs--refresh-indicators beg end))) + (defun hs-make-overlay (b e kind &optional b-offset e-offset) "Return a new overlay in region defined by B and E with type KIND. KIND is either `code' or `comment'. Optional fourth arg B-OFFSET @@ -778,13 +787,20 @@ to call with the newly initialized overlay." 'highlight 'help-echo "mouse-1: show hidden lines" 'keymap '(keymap (mouse-1 . hs-toggle-hiding)))) + ;; Internal properties (overlay-put ov 'hs kind) (overlay-put ov 'hs-b-offset b-offset) (overlay-put ov 'hs-e-offset e-offset) + ;; Isearch integration (when (or (eq io t) (eq io kind)) (overlay-put ov 'isearch-open-invisible 'hs-isearch-show) (overlay-put ov 'isearch-open-invisible-temporary 'hs-isearch-show-temporary)) + ;; Remove overlay after modifications + (overlay-put ov 'modification-hooks '(hs--discard-overlay-after-change)) + (overlay-put ov 'insert-in-front-hooks '(hs--discard-overlay-after-change)) + (overlay-put ov 'insert-behind-hooks '(hs--discard-overlay-after-change)) + (when hs-set-up-overlay (funcall hs-set-up-overlay ov)) (hs--refresh-indicators b e) ov))