]> git.eshelyaron.com Git - emacs.git/commitdiff
Make outline buttons work in NEWS
authorStephen Berman <stephen.berman@gmx.net>
Tue, 9 Aug 2022 18:21:09 +0000 (20:21 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 9 Aug 2022 18:44:07 +0000 (20:44 +0200)
* lisp/outline.el (outline-minor-mode-highlight-buffer): Fix
button insertion.
(outline-minor-mode): Ditto.
(outline--insert-open-button): Don't mark buffer as modified when
inserting buttons.
(outline--insert-close-button): Ditto.

* lisp/textmodes/emacs-news-mode.el (emacs-news--mode-common):
Adjust outline regexp.

lisp/outline.el
lisp/textmodes/emacs-news-mode.el

index 7750f9a75d092245db9214864921855169bb1118..35524a79a90b13858a4bdc981814c610bd62ef6d 100644 (file)
@@ -435,7 +435,7 @@ outline font-lock faces to those of major mode."
                          (goto-char (match-beginning 0))
                          (not (get-text-property (point) 'face))))
             (overlay-put overlay 'face (outline-font-lock-face)))
-          (when (outline--use-buttons-p)
+          (when (and (outline--use-buttons-p) (outline-on-heading-p))
             (outline--insert-open-button)))
         (goto-char (match-end 0))))))
 
@@ -452,11 +452,10 @@ See the command `outline-mode' for more information on this mode."
   (if outline-minor-mode
       (progn
         (when outline-minor-mode-highlight
-          (if (and global-font-lock-mode (font-lock-specified-p major-mode))
-              (progn
-                (font-lock-add-keywords nil outline-font-lock-keywords t)
-                (font-lock-flush))
-            (outline-minor-mode-highlight-buffer)))
+          (when (and global-font-lock-mode (font-lock-specified-p major-mode))
+            (font-lock-add-keywords nil outline-font-lock-keywords t)
+            (font-lock-flush))
+          (outline-minor-mode-highlight-buffer))
        ;; Turn off this mode if we change major modes.
        (add-hook 'change-major-mode-hook
                  (lambda () (outline-minor-mode -1))
@@ -1011,32 +1010,34 @@ If non-nil, EVENT should be a mouse event."
     o))
 
 (defun outline--insert-open-button ()
-  (save-excursion
-    (beginning-of-line)
-    (when (derived-mode-p 'special-mode)
-      (let ((inhibit-read-only t))
-        (insert "  ")
-        (beginning-of-line)))
-    (let ((o (outline--make-button-overlay 'open)))
-      (overlay-put o 'help-echo "Click to hide")
-      (overlay-put o 'keymap
-                   (define-keymap
-                     "RET" #'outline-hide-subtree
-                     "<mouse-2>" #'outline-hide-subtree)))))
+  (with-silent-modifications
+    (save-excursion
+        (beginning-of-line)
+        (when (derived-mode-p 'special-mode)
+          (let ((inhibit-read-only t))
+            (insert "  ")
+            (beginning-of-line)))
+        (let ((o (outline--make-button-overlay 'open)))
+          (overlay-put o 'help-echo "Click to hide")
+          (overlay-put o 'keymap
+                       (define-keymap
+                         "RET" #'outline-hide-subtree
+                         "<mouse-2>" #'outline-hide-subtree))))))
 
 (defun outline--insert-close-button ()
-  (save-excursion
-    (beginning-of-line)
-    (when (derived-mode-p 'special-mode)
-      (let ((inhibit-read-only t))
-        (insert "  ")
-        (beginning-of-line)))
-    (let ((o (outline--make-button-overlay 'close)))
-      (overlay-put o 'help-echo "Click to show")
-      (overlay-put o 'keymap
-                   (define-keymap
-                     "RET" #'outline-show-subtree
-                     "<mouse-2>" #'outline-show-subtree)))))
+  (with-silent-modifications
+    (save-excursion
+        (beginning-of-line)
+        (when (derived-mode-p 'special-mode)
+          (let ((inhibit-read-only t))
+            (insert "  ")
+            (beginning-of-line)))
+        (let ((o (outline--make-button-overlay 'close)))
+          (overlay-put o 'help-echo "Click to show")
+          (overlay-put o 'keymap
+                       (define-keymap
+                         "RET" #'outline-show-subtree
+                         "<mouse-2>" #'outline-show-subtree))))))
 
 (defun outline--fix-up-all-buttons (&optional from to)
   (when from
index c7fa9fa2b2c1d519bc3ae4dc59ab98abfebd0469..e6e1f0372840591ce17eea69a330d4a9173f62fa 100644 (file)
 
 (defun emacs-news--mode-common ()
   (setq-local font-lock-defaults '(emacs-news-mode-font-lock-keywords t))
-  (setq-local outline-regexp "\\*+ "
+  (setq-local outline-regexp "\\(:? +\\)?\\(\\*+\\) "
               outline-minor-mode-cycle t
-              ;; We subtract one from the level, because we have a
-              ;; space after the asterisks.
-              outline-level (lambda () (1- (length (match-string 0))))
+              outline-level (lambda () (length (match-string 2)))
               outline-minor-mode-highlight 'append)
   (outline-minor-mode))