]> git.eshelyaron.com Git - emacs.git/commitdiff
New hook 'outline-after-change-functions' (bug#77256).
authorJuri Linkov <juri@linkov.net>
Wed, 16 Apr 2025 17:11:34 +0000 (20:11 +0300)
committerEshel Yaron <me@eshelyaron.com>
Thu, 17 Apr 2025 07:09:02 +0000 (09:09 +0200)
* lisp/outline.el (outline-after-change-functions): New variable.
(outline--fix-buttons-after-change):
Run hook 'outline-after-change-functions'.

* lisp/treesit.el (treesit--after-change): Improve docstring.
(treesit-major-mode-setup): Simplify to just add
'treesit--after-change' to 'outline-after-change-functions' hook.

* lisp/progmodes/rust-ts-mode.el (rust-ts-mode): Add explicit
'treesit-outline-predicate' that is like
'treesit-simple-imenu-settings', but also adds "trait_item".

(cherry picked from commit 7574eb82c5cd150a0706a81e9f8555962a1e2167)

lisp/outline.el
lisp/progmodes/rust-ts-mode.el
lisp/treesit.el

index d899d1df667d9ebff74c12bafa715d27e45dd346..6cfdf1c191e37e4925d2e0f32189c774b33dd9a6 100644 (file)
@@ -1980,7 +1980,11 @@ With a prefix argument, show headings up to that LEVEL."
          (outline--insert-button (if close-p 'close 'open))))
      (or from (point-min)) (or to (point-max)))))
 
-(defun outline--fix-buttons-after-change (beg end _len)
+(defvar outline-after-change-functions nil
+  "List of functions to call after each text change in outline-mode.")
+
+(defun outline--fix-buttons-after-change (beg end len)
+  (run-hook-with-args 'outline-after-change-functions beg end len)
   ;; Handle whole lines
   (save-excursion (goto-char beg) (setq beg (pos-bol)))
   (save-excursion (goto-char end) (setq end (pos-eol)))
index f756ba0c2a19cdd4f64ddb35173eb5e8b7226c13..83f20c385746048de958e2842ef175919c85df7d 100644 (file)
@@ -576,6 +576,16 @@ See `prettify-symbols-compose-predicate'."
                   ("Struct" "\\`struct_item\\'" nil nil)
                   ("Fn" "\\`function_item\\'" nil nil)))
 
+    ;; Outline.
+    (setq-local treesit-outline-predicate
+                (rx bos (or "mod_item"
+                            "enum_item"
+                            "impl_item"
+                            "type_item"
+                            "struct_item"
+                            "function_item"
+                            "trait_item")
+                    eos))
     ;; Indent.
     (setq-local indent-tabs-mode nil
                 treesit-simple-indent-rules rust-ts-mode--indent-rules)
index 80304e145de809d30a6689c6ab8522c02a70c5ad..d09ecd8c618597ccad6486908f4ee5f93b7b4264 100644 (file)
@@ -4105,7 +4105,8 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in
     level))
 
 (defun treesit--after-change (beg end _len)
-  "Force updating the ranges after each text change."
+  "Force updating the ranges in BEG...END.
+Expected to be called after each text change."
   (treesit-update-ranges beg end))
 
 ;;; Hideshow mode
@@ -4403,15 +4404,7 @@ before calling this function."
             #'treesit-outline-predicate--from-imenu))
     (setq-local outline-search-function #'treesit-outline-search
                 outline-level #'treesit-outline-level)
-    (add-hook 'outline-minor-mode-hook
-              (lambda ()
-                (if (bound-and-true-p outline-minor-mode)
-                    (add-hook 'after-change-functions
-                              #'treesit--after-change
-                              0 t)
-                  (remove-hook 'after-change-functions
-                               #'treesit--after-change t)))
-              nil t))
+    (add-hook 'outline-after-change-functions #'treesit--after-change nil t))
 
   ;; Remove existing local parsers.
   (dolist (ov (overlays-in (point-min) (point-max)))