[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 125b5684c3: New command 'project-list-buffers' bound to 'C-x p C-
From: |
Juri Linkov |
Subject: |
master 125b5684c3: New command 'project-list-buffers' bound to 'C-x p C-b' (bug#59153) |
Date: |
Tue, 15 Nov 2022 13:55:19 -0500 (EST) |
branch: master
commit 125b5684c3fb85ed77eeaeca3237393507e4df55
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>
New command 'project-list-buffers' bound to 'C-x p C-b' (bug#59153)
* doc/emacs/maintaining.texi (Project Buffer Commands):
Add 'project-list-buffers'.
* lisp/buff-menu.el (Buffer-menu-filter-predicate): New defvar-local.
(list-buffers-noselect): Add new optional arg 'filter-predicate'.
Set 'Buffer-menu-filter-predicate' to 'filter-predicate'.
(list-buffers--refresh): Use 'Buffer-menu-filter-predicate'.
* lisp/progmodes/project.el (project-prefix-map): Bind "\C-b" to
'project-list-buffers'.
(project-list-buffers): New command.
---
doc/emacs/maintaining.texi | 7 +++++++
etc/NEWS | 4 ++++
lisp/buff-menu.el | 21 ++++++++++++++++++---
lisp/progmodes/project.el | 23 +++++++++++++++++++++++
4 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index 3e03bd817a..44e9e1896f 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -1832,6 +1832,8 @@ directory. @xref{Top,Eshell,Eshell, eshell, Eshell: The
Emacs Shell}.
@item C-x p b
Switch to another buffer belonging to the current project
(@code{project-switch-to-buffer}).
+@item C-x p C-b
+List the project buffers (@code{project-list-buffers}).
@item C-x p k
Kill all live buffers that belong to the current project
(@code{project-kill-buffers}).
@@ -1847,6 +1849,11 @@ switch between buffers that belong to the current
project by prompting
for a buffer to switch and considering only the current project's
buffers as candidates for completion.
+@findex project-list-buffers
+ Like the command @code{list-buffers} (@pxref{List Buffers}), the
+command @kbd{C-x p C-b} (@code{project-list-buffers}) displays a list
+of existing buffers, but only belonging to the current project.
+
@findex project-kill-buffers
@vindex project-kill-buffer-conditions
@vindex project-kill-buffers-display-buffer-list
diff --git a/etc/NEWS b/etc/NEWS
index 7cd192b9d3..e39833a704 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2212,6 +2212,10 @@ it with new 'term-{faint,italic,slow-blink,fast-blink}'
faces.
*** 'project-find-file' and 'project-or-external-find-file' now accept
a prefix argument which is interpreted to mean "include all files".
++++
+*** New command 'project-list-buffers' bound to 'C-x p C-b'.
+This command displays a list of buffers from the current project.
+
+++
*** 'project-kill-buffers' can display the list of buffers to kill.
Customize the user option 'project-kill-buffers-display-buffer-list'
diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el
index 34221ee440..aa5f70edf2 100644
--- a/lisp/buff-menu.el
+++ b/lisp/buff-menu.el
@@ -100,6 +100,13 @@ as it is by default."
This is set by the prefix argument to `buffer-menu' and related
commands.")
+(defvar-local Buffer-menu-filter-predicate nil
+ "Function to filter out buffers in the buffer list.
+Buffers that don't satisfy the predicate will be skipped.
+The value should be a function of one argument; it will be
+called with the buffer. If this function returns non-nil,
+then the buffer will be displayed in the buffer list.")
+
(defvar-keymap Buffer-menu-mode-map
:doc "Local keymap for `Buffer-menu-mode' buffers."
:parent tabulated-list-mode-map
@@ -616,19 +623,23 @@ This behaves like invoking \\[read-only-mode] in that
buffer."
;;; Functions for populating the Buffer Menu.
;;;###autoload
-(defun list-buffers-noselect (&optional files-only buffer-list)
+(defun list-buffers-noselect (&optional files-only buffer-list
filter-predicate)
"Create and return a Buffer Menu buffer.
This is called by `buffer-menu' and others as a subroutine.
If FILES-ONLY is non-nil, show only file-visiting buffers.
If BUFFER-LIST is non-nil, it should be a list of buffers; it
-means list those buffers and no others."
+means list those buffers and no others.
+If FILTER-PREDICATE is non-nil, it should be a function
+that filters out buffers from the list of buffers.
+See more at `Buffer-menu-filter-predicate'."
(let ((old-buffer (current-buffer))
(buffer (get-buffer-create "*Buffer List*")))
(with-current-buffer buffer
(Buffer-menu-mode)
(setq Buffer-menu-files-only
(and files-only (>= (prefix-numeric-value files-only) 0)))
+ (setq Buffer-menu-filter-predicate filter-predicate)
(list-buffers--refresh buffer-list old-buffer)
(tabulated-list-print))
buffer))
@@ -650,6 +661,8 @@ means list those buffers and no others."
(marked-buffers (Buffer-menu-marked-buffers))
(buffer-menu-buffer (current-buffer))
(show-non-file (not Buffer-menu-files-only))
+ (filter-predicate (and (functionp Buffer-menu-filter-predicate)
+ Buffer-menu-filter-predicate))
entries name-width)
;; Collect info for each buffer we're interested in.
(dolist (buffer (or buffer-list
@@ -663,7 +676,9 @@ means list those buffers and no others."
(and (or (not (string= (substring name 0 1) " "))
file)
(not (eq buffer buffer-menu-buffer))
- (or file show-non-file))))
+ (or file show-non-file)
+ (or (not filter-predicate)
+ (funcall filter-predicate buffer)))))
(push (list buffer
(vector (cond
((eq buffer old-buffer) ".")
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index ed26872ae7..63510e9050 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -712,6 +712,7 @@ DIRS must contain directory names."
(define-key map "G" 'project-or-external-find-regexp)
(define-key map "r" 'project-query-replace-regexp)
(define-key map "x" 'project-execute-extended-command)
+ (define-key map "\C-b" 'project-list-buffers)
map)
"Keymap for project commands.")
@@ -1222,6 +1223,28 @@ displayed."
(interactive (list (project--read-project-buffer)))
(display-buffer-other-frame buffer-or-name))
+;;;###autoload
+(defun project-list-buffers (&optional arg)
+ "Display a list of project buffers.
+The list is displayed in a buffer named \"*Buffer List*\".
+
+By default, all project buffers are listed except those whose names
+start with a space (which are for internal use). With prefix argument
+ARG, show only buffers that are visiting files."
+ (interactive "P")
+ (let ((pr (project-current t)))
+ (display-buffer
+ (if (version< emacs-version "29.0.50")
+ (let ((buf (list-buffers-noselect arg (project-buffers pr))))
+ (with-current-buffer buf
+ (setq-local revert-buffer-function
+ (lambda (&rest _ignored)
+ (list-buffers--refresh (project-buffers pr))
+ (tabulated-list-print t))))
+ buf)
+ (list-buffers-noselect
+ arg nil (lambda (buf) (memq buf (project-buffers pr))))))))
+
(defcustom project-kill-buffer-conditions
'(buffer-file-name ; All file-visiting buffers are included.
;; Most of temp and logging buffers (aside from hidden ones):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 125b5684c3: New command 'project-list-buffers' bound to 'C-x p C-b' (bug#59153),
Juri Linkov <=