diff options
| author | Elías Gabriel Pérez | 2025-11-17 21:17:46 -0600 |
|---|---|---|
| committer | Juri Linkov | 2025-11-20 19:42:01 +0200 |
| commit | bbd9727aa82230218420b1817d3e8f3b716b614f (patch) | |
| tree | fc49c6463077db211f2044b2b0263a7121647619 | |
| parent | 9c84fb5c73d1c390da5ad8e24157e37b0f3d4c93 (diff) | |
| download | emacs-bbd9727aa82230218420b1817d3e8f3b716b614f.tar.gz emacs-bbd9727aa82230218420b1817d3e8f3b716b614f.zip | |
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.
| -rw-r--r-- | lisp/progmodes/hideshow.el | 16 |
1 files changed, 16 insertions, 0 deletions
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." | |||
| 752 | (when-let* ((block (hs-block-positions))) | 752 | (when-let* ((block (hs-block-positions))) |
| 753 | (apply #'hs-hideable-region-p block)))) | 753 | (apply #'hs-hideable-region-p block)))) |
| 754 | 754 | ||
| 755 | (defun hs--discard-overlay-after-change (o &rest _r) | ||
| 756 | "Remove overlay O after changes. | ||
| 757 | Intended to be used in `modification-hooks', `insert-in-front-hooks' and | ||
| 758 | `insert-behind-hooks'." | ||
| 759 | (let ((beg (overlay-start o)) | ||
| 760 | (end (overlay-end o))) | ||
| 761 | (delete-overlay o) | ||
| 762 | (hs--refresh-indicators beg end))) | ||
| 763 | |||
| 755 | (defun hs-make-overlay (b e kind &optional b-offset e-offset) | 764 | (defun hs-make-overlay (b e kind &optional b-offset e-offset) |
| 756 | "Return a new overlay in region defined by B and E with type KIND. | 765 | "Return a new overlay in region defined by B and E with type KIND. |
| 757 | KIND is either `code' or `comment'. Optional fourth arg B-OFFSET | 766 | KIND is either `code' or `comment'. Optional fourth arg B-OFFSET |
| @@ -778,13 +787,20 @@ to call with the newly initialized overlay." | |||
| 778 | 'highlight | 787 | 'highlight |
| 779 | 'help-echo "mouse-1: show hidden lines" | 788 | 'help-echo "mouse-1: show hidden lines" |
| 780 | 'keymap '(keymap (mouse-1 . hs-toggle-hiding)))) | 789 | 'keymap '(keymap (mouse-1 . hs-toggle-hiding)))) |
| 790 | ;; Internal properties | ||
| 781 | (overlay-put ov 'hs kind) | 791 | (overlay-put ov 'hs kind) |
| 782 | (overlay-put ov 'hs-b-offset b-offset) | 792 | (overlay-put ov 'hs-b-offset b-offset) |
| 783 | (overlay-put ov 'hs-e-offset e-offset) | 793 | (overlay-put ov 'hs-e-offset e-offset) |
| 794 | ;; Isearch integration | ||
| 784 | (when (or (eq io t) (eq io kind)) | 795 | (when (or (eq io t) (eq io kind)) |
| 785 | (overlay-put ov 'isearch-open-invisible 'hs-isearch-show) | 796 | (overlay-put ov 'isearch-open-invisible 'hs-isearch-show) |
| 786 | (overlay-put ov 'isearch-open-invisible-temporary | 797 | (overlay-put ov 'isearch-open-invisible-temporary |
| 787 | 'hs-isearch-show-temporary)) | 798 | 'hs-isearch-show-temporary)) |
| 799 | ;; Remove overlay after modifications | ||
| 800 | (overlay-put ov 'modification-hooks '(hs--discard-overlay-after-change)) | ||
| 801 | (overlay-put ov 'insert-in-front-hooks '(hs--discard-overlay-after-change)) | ||
| 802 | (overlay-put ov 'insert-behind-hooks '(hs--discard-overlay-after-change)) | ||
| 803 | |||
| 788 | (when hs-set-up-overlay (funcall hs-set-up-overlay ov)) | 804 | (when hs-set-up-overlay (funcall hs-set-up-overlay ov)) |
| 789 | (hs--refresh-indicators b e) | 805 | (hs--refresh-indicators b e) |
| 790 | ov)) | 806 | ov)) |