]> git.eshelyaron.com Git - emacs.git/commitdiff
outline.el: Remove buttons properly, including the " "
authorStefan Monnier <monnier@iro.umontreal.ca>
Sun, 6 Jul 2025 16:27:04 +0000 (12:27 -0400)
committerEshel Yaron <me@eshelyaron.com>
Thu, 24 Jul 2025 11:57:26 +0000 (13:57 +0200)
In Xref, enabling+disabling `outline-minor-mode` left two spaces
in front of every heading (a.k.a "group") line.

* lisp/outline.el (outline--remove-buttons): New function.
(outline-minor-mode, outline--fix-buttons-after-change): Use it.
(outline-after-change-functions): Improve docstring.

(cherry picked from commit 845bb83a2236535455b3934709dc3a987933bcb9)

lisp/outline.el

index 1c158a67652e066c826719ce9a59a34eb0adbd23..af0355d192c11c762ba5e653a9713f21d4e97ce2 100644 (file)
@@ -624,7 +624,7 @@ See the command `outline-mode' for more information on this mode."
       (font-lock-flush)
       (remove-overlays nil nil 'outline-highlight t))
     (when outline-minor-mode-use-buttons
-      (remove-overlays nil nil 'outline-button t)
+      (outline--remove-buttons (point-min) (point-max))
       (when (and (eq outline-minor-mode-use-buttons 'in-margins)
                  (< 0 (if outline--use-rtl right-margin-width
                         left-margin-width)))
@@ -2030,16 +2030,31 @@ With a prefix argument, show headings up to that LEVEL."
      (or from (point-min)) (or to (point-max)))))
 
 (defvar outline-after-change-functions nil
-  "List of functions to call after each text change in outline-mode.")
+  "Hook run before updating buttons in a region in outline-mode.
+Called with three arguments (BEG END DUMMY).  Don't use DUMMY.")
 
 (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)))
-  (remove-overlays beg end 'outline-button t)
+  (when (eq outline-minor-mode-use-buttons 'insert)
+    ;; `outline--remove-buttons' may change the buffer's text.
+    (setq end (copy-marker end t)))
+  (outline--remove-buttons beg end)
   (save-match-data (outline--fix-up-all-buttons beg end)))
 
+(defun outline--remove-buttons (beg end)
+  (if (not (eq outline-minor-mode-use-buttons 'insert))
+      (remove-overlays beg end 'outline-button t)
+    (save-excursion
+      (dolist (ol (overlays-in beg end))
+        (when (overlay-get ol 'outline-button)
+          (goto-char (overlay-start ol))
+          (let ((inhibit-read-only t))
+            (when (looking-at "  ") (delete-char 2)))
+          (delete-overlay ol))))))
+
 \f
 (defvar-keymap outline-navigation-repeat-map
   :repeat t