From: Juri Linkov <juri@linkov.net>
To: Akib Azmain Turja <akib@disroot.org>
Cc: 59153@debbugs.gnu.org
Subject: bug#59153: List project buffers
Date: Thu, 10 Nov 2022 19:59:56 +0200 [thread overview]
Message-ID: <86leoilmg3.fsf@mail.linkov.net> (raw)
In-Reply-To: <8635arqllm.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 10 Nov 2022 09:56:01 +0200")
[-- Attachment #1: Type: text/plain, Size: 869 bytes --]
>>> + (bufs (mapcan
>>> + (lambda (buf)
>>> + (when (and (project--buffer-check buf '("\\`[^ ]"))
>>> + (or (not arg)
>>> + (project--buffer-check buf '(buffer-file-name))))
>>> + (list buf)))
>>> + (project-buffers pr))))
>>> + (display-buffer (list-buffers-noselect arg bufs))))
>>
>> This won't survive a revert buffer, I think. (I'll show all buffers
>> then.)
>
> This means that all uses of the BUFFER-LIST arg of 'list-buffers-noselect'
> are flawed. So better would be to provide not a list of buffers, but
> a predicate to filter out a list of buffers. Then the revert could use
> such a predicate from e.g. a buffer-local variable.
Here is a patch that adds a buffer-local variable similar to
Buffer-menu-files-only:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Buffer-menu-filter-predicate.patch --]
[-- Type: text/x-diff, Size: 4460 bytes --]
diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el
index abf152f058c..fbf2bbc58bc 100644
--- a/lisp/buff-menu.el
+++ b/lisp/buff-menu.el
@@ -101,6 +101,13 @@ Buffer-menu-files-only
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
@@ -597,19 +604,23 @@ Buffer-menu-view-other-window
;;; 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))
@@ -631,6 +642,8 @@ list-buffers--refresh
(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
@@ -644,7 +657,9 @@ list-buffers--refresh
(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 fc035675cec..917d80b2d3f 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -713,6 +713,7 @@ project-prefix-map
(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.")
@@ -1223,6 +1224,19 @@ project-display-buffer-other-frame
(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))
+ (filter-predicate (lambda (buf) (memq buf (project-buffers pr)))))
+ (display-buffer (list-buffers-noselect arg nil filter-predicate))))
+
(defcustom project-kill-buffer-conditions
'(buffer-file-name ; All file-visiting buffers are included.
;; Most of temp and logging buffers (aside from hidden ones):
@@ -1283,6 +1297,7 @@ project-kill-buffers-display-buffer-list
:package-version '(project . "0.8.2")
:safe #'booleanp)
+;; UNUSED?
(defun project--buffer-list (pr)
"Return the list of all buffers in project PR."
(let ((conn (file-remote-p (project-root pr)))
next prev parent reply other threads:[~2022-11-10 17:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-09 17:40 bug#59153: List project buffers Juri Linkov
2022-11-09 18:01 ` Eli Zaretskii
2022-11-09 19:22 ` Akib Azmain Turja via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-10 7:56 ` Juri Linkov
2022-11-10 8:56 ` Akib Azmain Turja via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-10 17:59 ` Juri Linkov [this message]
2022-11-12 1:41 ` Dmitry Gutov
2022-11-12 18:02 ` Juri Linkov
2022-11-13 2:37 ` Dmitry Gutov
2022-11-13 17:57 ` Juri Linkov
2022-11-13 22:18 ` Dmitry Gutov
2022-11-15 8:36 ` Juri Linkov
2022-11-15 14:53 ` Dmitry Gutov
2022-11-15 18:55 ` Juri Linkov
2022-11-16 10:16 ` Pankaj Jangid
2022-11-18 7:09 ` Juri Linkov
2022-11-19 18:34 ` Dmitry Gutov
2022-11-19 18:48 ` Juri Linkov
2022-11-19 19:22 ` Dmitry Gutov
2022-11-10 21:21 ` Dmitry Gutov
2022-11-12 1:39 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86leoilmg3.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=59153@debbugs.gnu.org \
--cc=akib@disroot.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.