emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master ab1b491f83 2/2: * lisp/outline.el (outline-minor-mode-insert-butt


From: Juri Linkov
Subject: master ab1b491f83 2/2: * lisp/outline.el (outline-minor-mode-insert-buttons): New defvar-local.
Date: Tue, 18 Oct 2022 14:14:32 -0400 (EDT)

branch: master
commit ab1b491f8373742a051aaf554c4604f2b976b414
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * lisp/outline.el (outline-minor-mode-insert-buttons): New defvar-local.
    
    (outline--make-button-overlay, outline--insert-open-button)
    (outline--insert-close-button): Insert button when
    outline-minor-mode-insert-buttons is non-nil, otherwise
    put an overlay with before-string.  (bug#57813)
    
    * lisp/help.el (describe-bindings): Set buffer-local
    outline-minor-mode-insert-buttons to t.
    
    * lisp/textmodes/emacs-news-mode.el (emacs-news--mode-common):
    Set buffer-local outline-minor-mode-use-margins to t.  Don't set
    outline-regexp for leading spaces because now spaces are not added
    in the NEWS buffer.
---
 lisp/help.el                      |  3 ++-
 lisp/outline.el                   | 31 ++++++++++++++++++++-----------
 lisp/textmodes/emacs-news-mode.el |  9 +++------
 3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/lisp/help.el b/lisp/help.el
index 1cfd044db8..0f5342b77d 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -744,7 +744,8 @@ or a buffer name."
           (setq-local outline-heading-end-regexp ":\n")
           (setq-local outline-level (lambda () 1))
           (setq-local outline-minor-mode-cycle t
-                      outline-minor-mode-highlight t)
+                      outline-minor-mode-highlight t
+                      outline-minor-mode-insert-buttons t)
           (outline-minor-mode 1)
           (save-excursion
             (goto-char (point-min))
diff --git a/lisp/outline.el b/lisp/outline.el
index 0d0974b5a9..2209964577 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -295,6 +295,9 @@ buffers (yet) -- that will be amended in a future version."
 (defvar-local outline--use-buttons nil
   "Non-nil when buffer displays clickable buttons on the headings.")
 
+(defvar-local outline-minor-mode-insert-buttons nil
+  "Non-nil when it's allowed to modify buffer to insert buttons.")
+
 (defvar-local outline--use-rtl nil
   "Non-nil when direction of clickable buttons is right-to-left.")
 
@@ -1668,18 +1671,24 @@ With a prefix argument, show headings up to that LEVEL."
                                    (if outline--use-rtl
                                        'outline-close-rtl
                                      'outline-close)
-                                 'outline-open)))
-          (inhibit-read-only t))
+                                 'outline-open))))
       ;; In editing buffers we use overlays only, but in other buffers
       ;; we use a mix of text properties, text and overlays to make
       ;; movement commands work more logically.
-      (when (derived-mode-p 'special-mode)
-        (put-text-property (point) (1+ (point)) 'face (plist-get icon 'face)))
-      (if-let ((image (plist-get icon 'image)))
-          (overlay-put o 'display image)
-        (overlay-put o 'display (concat (plist-get icon 'string)
-                                        (string (char-after (point)))))
-        (overlay-put o 'face (plist-get icon 'face))))
+      (if outline-minor-mode-insert-buttons
+          (let ((inhibit-read-only t))
+            (put-text-property (point) (1+ (point)) 'face (plist-get icon 
'face))
+            (if-let ((image (plist-get icon 'image)))
+                (overlay-put o 'display image)
+              (overlay-put o 'display (concat (plist-get icon 'string)
+                                              (string (char-after (point)))))
+              (overlay-put o 'face (plist-get icon 'face))))
+        (overlay-put
+         o 'before-string
+         (propertize " "
+                     'display
+                     (or (plist-get icon 'image)
+                         (plist-get icon 'string))))))
     o))
 
 (defun outline--make-margin-overlay (type)
@@ -1710,7 +1719,7 @@ With a prefix argument, show headings up to that LEVEL."
       (beginning-of-line)
       (if use-margins
           (outline--make-margin-overlay 'open)
-        (when (derived-mode-p 'special-mode)
+        (when outline-minor-mode-insert-buttons
           (let ((inhibit-read-only t))
             (insert "  ")
             (beginning-of-line)))
@@ -1727,7 +1736,7 @@ With a prefix argument, show headings up to that LEVEL."
       (beginning-of-line)
       (if use-margins
           (outline--make-margin-overlay 'close)
-        (when (derived-mode-p 'special-mode)
+        (when outline-minor-mode-insert-buttons
           (let ((inhibit-read-only t))
             (insert "  ")
             (beginning-of-line)))
diff --git a/lisp/textmodes/emacs-news-mode.el 
b/lisp/textmodes/emacs-news-mode.el
index d9decae4df..d57d053a7a 100644
--- a/lisp/textmodes/emacs-news-mode.el
+++ b/lisp/textmodes/emacs-news-mode.el
@@ -73,12 +73,9 @@
 
 (defun emacs-news--mode-common ()
   (setq-local font-lock-defaults '(emacs-news-mode-font-lock-keywords t))
-  ;; This `outline-regexp' matches leading spaces inserted
-  ;; by the current implementation of `outline-minor-mode-use-buttons'.
-  (setq-local outline-regexp "\\(?: +\\)?\\(\\*+\\) "
-              outline-level (lambda () (length (match-string 1)))
-              outline-minor-mode-cycle t
-              outline-minor-mode-highlight 'append)
+  (setq-local outline-minor-mode-cycle t
+              outline-minor-mode-highlight 'append
+              outline-minor-mode-use-margins t)
   (outline-minor-mode)
   (setq-local imenu-generic-expression outline-imenu-generic-expression)
   (emacs-etc--hide-local-variables))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]