]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/buff-menu.el: Mark all entries in outline.
authorJuri Linkov <juri@linkov.net>
Fri, 7 Jun 2024 06:45:05 +0000 (09:45 +0300)
committerEshel Yaron <me@eshelyaron.com>
Fri, 7 Jun 2024 10:44:37 +0000 (12:44 +0200)
(Buffer-menu-mark, Buffer-menu-unmark, Buffer-menu-delete)
(Buffer-menu-save): Mark all entries in the outline
when `outline-minor-mode' is enabled and point is
on the outline heading line (bug#70150).
(Buffer-menu-backup-unmark): Support outline heading lines.

(cherry picked from commit b18bdbb2c1ea004a3ad8f7c1716fcbc6a61ef927)

etc/NEWS
lisp/buff-menu.el

index 25b7eef589806ebe68188b4c0bcd9a6b3eaaa86d..e91270701d3a67f9bbbb433f6733db7a805c45cb 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1970,7 +1970,8 @@ This user option lets you customize the sample text that
 ---
 *** New user option 'Buffer-menu-group-by'.
 It controls how buffers are divided into groups that are displayed with
-headings using Outline minor mode.
+headings using Outline minor mode.  Using commands that mark buffers
+on the outline heading line will mark all buffers in the outline.
 
 +++
 *** New command 'Buffer-menu-toggle-internal'.
index d83bf2249e6c67de94836efae1aaf8647b6119cc..c35fa42934ce6216c8f7d7eb3e0addf6ab2feb32 100644 (file)
@@ -411,19 +411,50 @@ is nil or omitted, and signal an error otherwise."
 \f
 ;;; Commands for modifying Buffer Menu entries.
 
+(defvar outline-minor-mode)
+(declare-function outline-on-heading-p "outline" (&optional invisible-ok))
+(declare-function outline-end-of-subtree "outline" ())
+(declare-function outline-previous-heading "outline" ())
+
 (defun Buffer-menu-mark ()
   "Mark the Buffer menu entry at point for later display.
-It will be displayed by the \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command."
+It will be displayed by the \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command.
+When `outline-minor-mode' is enabled and point is on the outline
+heading line, this command will mark all entries in the outline."
   (interactive nil Buffer-menu-mode)
-  (tabulated-list-set-col 0 (char-to-string Buffer-menu-marker-char) t)
-  (forward-line))
+  (cond ((tabulated-list-get-id)
+         (tabulated-list-set-col 0 (char-to-string Buffer-menu-marker-char) t)
+         (forward-line))
+        ((and (bound-and-true-p outline-minor-mode) (outline-on-heading-p))
+         (let ((limit (save-excursion (outline-end-of-subtree) (point)))
+               ;; Skip outline subheadings on recursive calls
+               (outline-minor-mode nil))
+           (forward-line)
+           (while (< (point) limit)
+             (Buffer-menu-mark))))
+        (t (forward-line))))
 
 (defun Buffer-menu-unmark (&optional backup)
   "Cancel all requested operations on buffer on this line and move down.
-Optional prefix arg means move up."
+Optional prefix arg means move up.
+When `outline-minor-mode' is enabled and point is on the outline
+heading line, this command will unmark all entries in the outline."
   (interactive "P" Buffer-menu-mode)
-  (Buffer-menu--unmark)
-  (forward-line (if backup -1 1)))
+  (cond ((tabulated-list-get-id)
+         (Buffer-menu--unmark)
+         (forward-line (if backup -1 1)))
+        ((and (bound-and-true-p outline-minor-mode) (outline-on-heading-p))
+         (let ((old-pos (point))
+               (limit (save-excursion (outline-end-of-subtree) (point)))
+               ;; Skip outline subheadings on recursive calls
+               (outline-minor-mode nil))
+           (forward-line)
+           (while (< (point) limit)
+             (Buffer-menu-unmark))
+           (when backup
+             (goto-char old-pos)
+             (outline-previous-heading))))
+        (t (forward-line (if backup -1 1)))))
 
 (defun Buffer-menu-unmark-all-buffers (mark)
   "Cancel a requested operation on all buffers.
@@ -449,7 +480,10 @@ When called interactively prompt for MARK;  RET remove all marks."
   "Move up and cancel all requested operations on buffer on line above."
   (interactive nil Buffer-menu-mode)
   (forward-line -1)
-  (Buffer-menu--unmark))
+  (while (and (not (tabulated-list-get-id)) (not (bobp)))
+    (forward-line -1))
+  (unless (bobp)
+    (Buffer-menu--unmark)))
 
 (defun Buffer-menu--unmark ()
   (tabulated-list-set-col 0 " " t)
@@ -465,20 +499,34 @@ A subsequent \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] command \
 will delete it.
 
 If prefix argument ARG is non-nil, it specifies the number of
-buffers to delete; a negative ARG means to delete backwards."
+buffers to delete; a negative ARG means to delete backwards.
+
+When `outline-minor-mode' is enabled and point is on the outline
+heading line, this command will mark all entries in the outline.
+However, ARG is not supported in this case."
   (interactive "p" Buffer-menu-mode)
-  (if (or (null arg) (= arg 0))
-      (setq arg 1))
-  (while (> arg 0)
-    (when (Buffer-menu-buffer)
-      (tabulated-list-set-col 0 (char-to-string Buffer-menu-del-char) t))
-    (forward-line 1)
-    (setq arg (1- arg)))
-  (while (< arg 0)
-    (when (Buffer-menu-buffer)
-      (tabulated-list-set-col 0 (char-to-string Buffer-menu-del-char) t))
-    (forward-line -1)
-    (setq arg (1+ arg))))
+  (cond
+   ((and (bound-and-true-p outline-minor-mode) (outline-on-heading-p))
+    (let ((limit (save-excursion (outline-end-of-subtree) (point)))
+          ;; Skip outline subheadings on recursive calls
+          (outline-minor-mode nil))
+      (forward-line)
+      (while (< (point) limit)
+        (Buffer-menu-delete))))
+   (t
+    (if (or (null arg) (= arg 0))
+        (setq arg 1))
+    (while (> arg 0)
+      (when (Buffer-menu-buffer)
+        (tabulated-list-set-col 0 (char-to-string Buffer-menu-del-char) t))
+      (forward-line 1)
+      (setq arg (1- arg)))
+
+    (while (< arg 0)
+      (when (Buffer-menu-buffer)
+        (tabulated-list-set-col 0 (char-to-string Buffer-menu-del-char) t))
+      (forward-line -1)
+      (setq arg (1+ arg))))))
 
 (defun Buffer-menu-delete-backwards (&optional arg)
   "Mark the buffer on this Buffer Menu line for deletion, and move up.
@@ -491,11 +539,22 @@ will delete the marked buffer.  Prefix ARG
 (defun Buffer-menu-save ()
   "Mark the buffer on this Buffer Menu line for saving.
 A subsequent \\<Buffer-menu-mode-map>\\[Buffer-menu-execute] \
-command will save it."
+command will save it.
+When `outline-minor-mode' is enabled and point is on the outline
+heading line, this command will mark all entries in the outline."
   (interactive nil Buffer-menu-mode)
-  (when (Buffer-menu-buffer)
-    (tabulated-list-set-col 2 "S" t)
-    (forward-line 1)))
+  (cond ((tabulated-list-get-id)
+         (when (Buffer-menu-buffer)
+           (tabulated-list-set-col 2 "S" t))
+         (forward-line))
+        ((and (bound-and-true-p outline-minor-mode) (outline-on-heading-p))
+         (let ((limit (save-excursion (outline-end-of-subtree) (point)))
+               ;; Skip outline subheadings on recursive calls
+               (outline-minor-mode nil))
+           (forward-line)
+           (while (< (point) limit)
+             (Buffer-menu-save))))
+        (t (forward-line))))
 
 (defun Buffer-menu-not-modified (&optional arg)
   "Mark the buffer on this line as unmodified (no changes to save).