buff-menu: Add command to unmark all buffers

Bind 'U' in buff-menu, bs and electric-buff-menu to commands
to unmark all buffers (Bug#24880).
* lisp/emacs-lisp/tabulated-list.el (tabulated-list-header-overlay-p):
New predicate; return non-nil if tabulated-list has a fake header.
* lisp/buff-menu.el (Buffer-menu-unmark-all-buffers):
New command; remove all flags that use a particular mark from all the lines.
Bind it to 'M-DEL'.
(Buffer-menu-unmark-all):
New command; remove all flags from all the lines.  Bind it to 'U'.
(Buffer-menu-marker-char, Buffer-menu-del-char): New variables.
(Buffer-menu-delete, Buffer-menu-mark): Use them.
(Buffer-menu-mode-map): Update menus.
(Buffer-menu-mode): Update mode doc.
* lisp/bs.el (bs-unmark-all, bs-unmark-previous): New commands.
(bs-mode-map): Bind them to 'U' and '<backspace>' respectively.
(bs-mode): Update mode doc.
* lisp/ebuff-menu.el (electric-buffer-menu-mode-map):
Bind Buffer-menu-unmark-all to 'U' and Buffer-menu-unmark-all-buffers
to 'M-DEL'.
(bs--down, bs-down, bs--up, bs-up, bs-unmark-current, bs-mark-current):
Use point instead of cursor in doc string.
(electric-buffer-list): Update mode doc.
* doc/emacs/buffers.texi (Several Buffers): Mention Buffer-menu-unmark-all
and Buffer-menu-unmark-all-buffers.
; * etc/NEWS: Add an entry per each new feature.
This commit is contained in:
Tino Calancha 2016-11-22 15:23:50 +09:00
parent 3c194dafe0
commit 27b754cb44
6 changed files with 117 additions and 9 deletions

View file

@ -411,6 +411,18 @@ Remove all flags from the current line, and move down
@kindex DEL @r{(Buffer Menu)}
Move to the previous line and remove all flags on that line
(@code{Buffer-menu-backup-unmark}).
@item M-@key{DEL}
@findex Buffer-menu-unmark-all-buffers
@kindex M-DEL @r{(Buffer Menu)}
Remove a particular flag from all lines
(@code{Buffer-menu-unmark-all-buffers}).
@item U
@findex Buffer-menu-unmark-all
@kindex U @r{(Buffer Menu)}
Remove all flags from all the lines
(@code{Buffer-menu-unmark-all}).
@end table
@noindent

View file

@ -283,6 +283,24 @@ the file's actual content before prompting the user.
* Changes in Specialized Modes and Packages in Emacs 26.1
** Electric-Buffer-menu
+++
*** Key 'U' is bound to 'Buffer-menu-unmark-all' and key 'M-DEL' is
bound to 'Buffer-menu-unmark-all-buffers'.
** bs
---
*** Two new commands 'bs-unmark-all', bound to 'U', and
'bs-unmark-previous', bound to <backspace>.
** Buffer-menu
+++
*** Two new commands 'Buffer-menu-unmark-all', bound to 'U' and
'Buffer-menu-unmark-all-buffers', bound to 'M-DEL'.
** Ibuffer
---

View file

@ -491,6 +491,8 @@ Used internally, only.")
(define-key map "t" 'bs-visit-tags-table)
(define-key map "m" 'bs-mark-current)
(define-key map "u" 'bs-unmark-current)
(define-key map "U" 'bs-unmark-all)
(define-key map "\177" 'bs-unmark-previous)
(define-key map ">" 'scroll-right)
(define-key map "<" 'scroll-left)
(define-key map "?" 'bs-help)
@ -635,6 +637,8 @@ For faster navigation each digit key is a digit argument.
\\[bs-clear-modified] -- clear modified-flag on that buffer.
\\[bs-mark-current] -- mark current line's buffer to be displayed.
\\[bs-unmark-current] -- unmark current line's buffer to be displayed.
\\[bs-unmark-all] -- unmark all buffer lines.
\\[bs-unmark-previous] -- unmark previous line's buffer to be displayed.
\\[bs-show-sorted] -- display buffer list sorted by next sort aspect.
\\[bs-set-configuration-and-refresh] -- ask user for a configuration and \
apply selected configuration.
@ -867,7 +871,7 @@ the status of buffer on current line."
(defun bs-mark-current (count)
"Mark buffers.
COUNT is the number of buffers to mark.
Move cursor vertically down COUNT lines."
Move point vertically down COUNT lines."
(interactive "p")
(bs--mark-unmark count
(lambda (buf)
@ -876,12 +880,39 @@ Move cursor vertically down COUNT lines."
(defun bs-unmark-current (count)
"Unmark buffers.
COUNT is the number of buffers to unmark.
Move cursor vertically down COUNT lines."
Move point vertically down COUNT lines."
(interactive "p")
(bs--mark-unmark count
(lambda (buf)
(setq bs--marked-buffers (delq buf bs--marked-buffers)))))
(defun bs-unmark-previous (count)
"Unmark previous COUNT buffers.
Move point vertically up COUNT lines.
When called interactively a numeric prefix argument sets COUNT."
(interactive "p")
(forward-line (- count))
(save-excursion (bs-unmark-current count)))
(defun bs-unmark-all ()
"Unmark all buffers."
(interactive)
(let ((marked (string-to-char bs-string-marked))
(current (string-to-char bs-string-current))
(marked-cur (string-to-char bs-string-current-marked))
(unmarked (string-to-char bs-string-show-normally))
(inhibit-read-only t))
(save-excursion
(goto-char (point-min))
(forward-line 2)
(while (not (eobp))
(if (eq (char-after) marked)
(subst-char-in-region (point) (1+ (point)) marked unmarked)
(when (eq (char-after) marked-cur)
(subst-char-in-region (point) (1+ (point)) marked-cur current)))
(forward-line 1))
(setq bs--marked-buffers nil))))
(defun bs--show-config-message (what)
"Show message indicating the new showing status WHAT.
WHAT is a value of nil, `never', or `always'."
@ -973,14 +1004,14 @@ Uses function `read-only-mode'."
(apply fun args)))
(defun bs-up (arg)
"Move cursor vertically up ARG lines in Buffer Selection Menu."
"Move point vertically up ARG lines in Buffer Selection Menu."
(interactive "p")
(if (and arg (numberp arg) (< arg 0))
(bs--nth-wrapper (- arg) 'bs--down)
(bs--nth-wrapper arg 'bs--up)))
(defun bs--up ()
"Move cursor vertically up one line.
"Move point vertically up one line.
If on top of buffer list go to last line."
(if (> (count-lines 1 (point)) bs-header-lines-length)
(forward-line -1)
@ -989,14 +1020,14 @@ If on top of buffer list go to last line."
(recenter -1)))
(defun bs-down (arg)
"Move cursor vertically down ARG lines in Buffer Selection Menu."
"Move point vertically down ARG lines in Buffer Selection Menu."
(interactive "p")
(if (and arg (numberp arg) (< arg 0))
(bs--nth-wrapper (- arg) 'bs--up)
(bs--nth-wrapper arg 'bs--down)))
(defun bs--down ()
"Move cursor vertically down one line.
"Move point vertically down one line.
If at end of buffer list go to first line."
(if (eq (line-end-position) (point-max))
(progn

View file

@ -37,6 +37,12 @@
:group 'tools
:group 'convenience)
(defvar Buffer-menu-marker-char ?>
"The mark character for marked buffers.")
(defvar Buffer-menu-del-char ?D
"Character used to flag buffers for deletion.")
(defcustom Buffer-menu-use-header-line t
"If non-nil, use the header line to display Buffer Menu column titles."
:type 'boolean
@ -121,6 +127,8 @@ commands.")
(define-key map "\177" 'Buffer-menu-backup-unmark)
(define-key map "~" 'Buffer-menu-not-modified)
(define-key map "u" 'Buffer-menu-unmark)
(define-key map "\M-\177" 'Buffer-menu-unmark-all-buffers)
(define-key map "U" 'Buffer-menu-unmark-all)
(define-key map "m" 'Buffer-menu-mark)
(define-key map "t" 'Buffer-menu-visit-tags-table)
(define-key map "%" 'Buffer-menu-toggle-read-only)
@ -197,6 +205,12 @@ commands.")
(bindings--define-key menu-map [umk]
'(menu-item "Unmark" Buffer-menu-unmark
:help "Cancel all requested operations on buffer on this line and move down"))
(bindings--define-key menu-map [umkab]
'(menu-item "Remove marks..." Buffer-menu-unmark-all-buffers
:help "Cancel a requested operation on all buffers"))
(bindings--define-key menu-map [umka]
'(menu-item "Unmark all" Buffer-menu-unmark-all
:help "Cancel all requested operations on buffers"))
(bindings--define-key menu-map [mk]
'(menu-item "Mark" Buffer-menu-mark
:help "Mark buffer on this line for being displayed by v command"))
@ -239,6 +253,8 @@ In Buffer Menu mode, the following commands are defined:
\\[Buffer-menu-execute] Delete or save marked buffers.
\\[Buffer-menu-unmark] Remove all marks from current line.
With prefix argument, also move up one line.
\\[Buffer-menu-unmark-all-buffers] Remove a particular mark from all lines.
\\[Buffer-menu-unmark-all] Remove all marks from all lines.
\\[Buffer-menu-backup-unmark] Back up a line and remove marks.
\\[Buffer-menu-toggle-read-only] Toggle read-only status of buffer on this line.
\\[revert-buffer] Update the list of buffers.
@ -346,7 +362,7 @@ is nil or omitted, and signal an error otherwise."
"Mark the Buffer menu entry at point for later display.
It will be displayed by the \\<Buffer-menu-mode-map>\\[Buffer-menu-select] command."
(interactive)
(tabulated-list-set-col 0 ">" t)
(tabulated-list-set-col 0 (char-to-string Buffer-menu-marker-char) t)
(forward-line))
(defun Buffer-menu-unmark (&optional backup)
@ -356,6 +372,28 @@ Optional prefix arg means move up."
(Buffer-menu--unmark)
(forward-line (if backup -1 1)))
(defun Buffer-menu-unmark-all-buffers (mark)
"Cancel a requested operation on all buffers.
MARK is the character to flag the operation on the buffers.
When called interactively prompt for MARK; RET remove all marks."
(interactive "cRemove marks (RET means all):")
(save-excursion
(goto-char (point-min))
(when (tabulated-list-header-overlay-p)
(forward-line))
(while (not (eobp))
(let ((xmarks (list (aref (tabulated-list-get-entry) 0)
(aref (tabulated-list-get-entry) 2))))
(when (or (char-equal mark ?\r)
(member (char-to-string mark) xmarks))
(Buffer-menu--unmark)))
(forward-line))))
(defun Buffer-menu-unmark-all ()
"Cancel all requested operations on buffers."
(interactive)
(Buffer-menu-unmark-all-buffers ?\r))
(defun Buffer-menu-backup-unmark ()
"Move up and cancel all requested operations on buffer on line above."
(interactive)
@ -382,12 +420,12 @@ buffers to delete; a negative ARG means to delete backwards."
(setq arg 1))
(while (> arg 0)
(when (Buffer-menu-buffer)
(tabulated-list-set-col 0 "D" t))
(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 "D" t))
(tabulated-list-set-col 0 (char-to-string Buffer-menu-del-char) t))
(forward-line -1)
(setq arg (1+ arg))))

View file

@ -55,6 +55,8 @@
(define-key map "\177" 'Buffer-menu-backup-unmark)
(define-key map "~" 'Buffer-menu-not-modified)
(define-key map "u" 'Buffer-menu-unmark)
(define-key map "\M-\177" 'Buffer-menu-unmark-all-buffers)
(define-key map "U" 'Buffer-menu-unmark-all)
(let ((i ?0))
(while (<= i ?9)
(define-key map (char-to-string i) 'digit-argument)
@ -114,6 +116,7 @@ Run hooks in `electric-buffer-menu-mode-hook' on entry.
\\[Buffer-menu-save] -- mark that buffer to be saved.
\\[Buffer-menu-delete] or \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted.
\\[Buffer-menu-unmark] -- remove all kinds of marks from current line.
\\[Buffer-menu-unmark-all] -- remove all kinds of marks from all lines.
\\[Electric-buffer-menu-mode-view-buffer] -- view buffer, returning when done.
\\[Buffer-menu-backup-unmark] -- back up a line and remove marks."
(interactive "P")

View file

@ -259,6 +259,12 @@ Do nothing if `tabulated-list--header-string' is nil."
(make-overlay (point-min) (point))))
(overlay-put tabulated-list--header-overlay 'face 'underline))))
(defsubst tabulated-list-header-overlay-p (&optional pos)
"Return non-nil if there is a fake header.
Optional arg POS is a buffer position where to look for a fake header;
defaults to `point-min'."
(overlays-at (or pos (point-min))))
(defun tabulated-list-revert (&rest ignored)
"The `revert-buffer-function' for `tabulated-list-mode'.
It runs `tabulated-list-revert-hook', then calls `tabulated-list-print'."