]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/outline.el (outline-revert-buffer-rehighlight): New function.
authorJuri Linkov <juri@linkov.net>
Tue, 4 Jun 2024 16:53:47 +0000 (19:53 +0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 5 Jun 2024 10:15:04 +0000 (12:15 +0200)
(outline-minor-mode): Add 'outline-revert-buffer-rehighlight' to
'revert-buffer-restore-functions'.  When mode is disabled,
remove hooks from 'revert-buffer-restore-functions' and
also from 'after-change-functions'.

(cherry picked from commit 7f415f7d5e19ea3903500426a0724e49271ac699)

lisp/outline.el

index 74c679797aaf23a39642ac3992986e06fad3fe17..373902e3f596448f377fff7cd5371729c7084ee8 100644 (file)
@@ -583,17 +583,17 @@ See the command `outline-mode' for more information on this mode."
         (add-hook 'revert-buffer-restore-functions
                   #'outline-revert-buffer-restore-visibility nil t)
         (add-hook 'revert-buffer-restore-functions
-                  (lambda ()
-                    (when (and outline-minor-mode outline-minor-mode-highlight
-                               (not (and global-font-lock-mode
-                                         (font-lock-specified-p major-mode))))
-                      (lambda ()
-                        (outline-minor-mode-highlight-buffer))))
-                  nil t)
+                  #'outline-revert-buffer-rehighlight nil t)
         (setq-local line-move-ignore-invisible t)
        ;; Cause use of ellipses for invisible text.
        (add-to-invisibility-spec '(outline . t))
        (outline-apply-default-state))
+    (remove-hook 'after-change-functions
+                 #'outline--fix-buttons-after-change t)
+    (remove-hook 'revert-buffer-restore-functions
+                 #'outline-revert-buffer-restore-visibility t)
+    (remove-hook 'revert-buffer-restore-functions
+                 #'outline-revert-buffer-rehighlight t)
     (setq line-move-ignore-invisible nil)
     ;; Cause use of ellipses for invisible text.
     (remove-from-invisibility-spec '(outline . t))
@@ -1724,6 +1724,17 @@ under `outline-minor-mode' is reverted by `revert-buffer'."
       (lambda ()
         (outline-hide-by-heading-regexp regexp)))))
 
+(defun outline-revert-buffer-rehighlight ()
+  "Rehighlight outlines when reverting buffer under `outline-minor-mode'.
+This function rehighlightes outlines after the buffer under
+`outline-minor-mode' is reverted by `revert-buffer' when font-lock
+can't update highlighting for `outline-minor-mode-highlight'."
+  (when (and outline-minor-mode-highlight
+             (not (and global-font-lock-mode
+                       (font-lock-specified-p major-mode))))
+    (lambda ()
+      (outline-minor-mode-highlight-buffer))))
+
 \f
 ;;; Visibility cycling