From: Stefan Monnier Date: Sun, 6 Jul 2025 16:27:04 +0000 (-0400) Subject: outline.el: Remove buttons properly, including the " " X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fd4cdd9b8c02741d92daa5b50368f835e9c99da8;p=emacs.git outline.el: Remove buttons properly, including the " " 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) --- diff --git a/lisp/outline.el b/lisp/outline.el index 1c158a67652..af0355d192c 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -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)))))) + (defvar-keymap outline-navigation-repeat-map :repeat t