From: Manuel Uberti via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Dmitry Gutov <dgutov@yandex.ru>, 54100@debbugs.gnu.org
Subject: bug#54100: 29.0.50; Allow project-buffers to ignore some buffers
Date: Fri, 25 Feb 2022 07:44:51 +0100 [thread overview]
Message-ID: <48d94136-bda9-091e-0370-788f3d706a9d@inventati.org> (raw)
In-Reply-To: <93b67902-a322-d0f1-e25a-97ff3ac70785@yandex.ru>
[-- Attachment #1: Type: text/plain, Size: 1638 bytes --]
On 25/02/22 03:33, Dmitry Gutov wrote:
> Doesn't this mean that it won't do the (memq ... buffers) check and thus ignore
> the result of the (project-buffers pr) call?
>
> Instead, it could be a lambda like
>
> (lambda (buffer)
> ;; BUFFER is an entry (BUF-NAME . BUF-OBJ) of Vbuffer_alist.
> (and (memq (cdr buffer) buffers)
> (funcall predicate buffer)))
>
> Does that make sense?
Totally, thank you!
> (I would also try to shorten the new defcustom's docstring by referring to the
> existing one, but I can make that change myself.)
Done.
> Or if you wanted to stay on "or" but make it easier for certain usage pattern,
> you could call the var 'project-ignore-buffer-conditions' (or "hide" or etc),
> and change its use appropriately. Then the value could contain
>
> '((not mu-project-buffer-p)
> (derived-mode . comint-mode))
>
> ...and (not mu-project-buffer-p) could obviously be rewritten in a negated way
> in the function's definition.
I followed your suggestion and used `project-ignore-buffer-conditions' in the
attached patch.
Now everything works as expected when I use this:
(defun mu-project-ignore-buffer-p (buffer)
"Check if BUFFER is a member of `mu-ignored-buffers'."
(seq-contains-p mu-ignored-buffers (buffer-name buffer) #'string-match-p))
(setq-default project-ignore-buffer-conditions '(mu-project-ignore-buffer-p
(derived-mode . dired-mode)))
Again, thank you for the help on this.
--
Manuel Uberti
www.manueluberti.eu
[-- Attachment #2: 0001-Add-project-ignore-buffer-conditions.patch --]
[-- Type: text/x-patch, Size: 4894 bytes --]
From 2fbb408219a2f17928705be048510c630ef3175f Mon Sep 17 00:00:00 2001
From: Manuel Uberti <manuel.uberti@inventati.org>
Date: Wed, 23 Feb 2022 09:25:32 +0100
Subject: [PATCH] Add project-ignore-buffer-conditions
* lisp/progmodes/project.el (project-ignore-buffer-conditions):
New defcustom.
(project-switch-to-buffer):
Use it (bug#54100).
---
lisp/progmodes/project.el | 52 ++++++++++++++++++++++++++++++---------
1 file changed, 40 insertions(+), 12 deletions(-)
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 880c5b5517..78ccedf9fa 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1112,7 +1112,7 @@ project-compile
compilation-buffer-name-function)))
(call-interactively #'compile)))
-(defun project--read-project-buffer ()
+(defun project--read-project-buffer (&optional predicate)
(let* ((pr (project-current t))
(current-buffer (current-buffer))
(other-buffer (other-buffer current-buffer))
@@ -1121,7 +1121,8 @@ project--read-project-buffer
(predicate
(lambda (buffer)
;; BUFFER is an entry (BUF-NAME . BUF-OBJ) of Vbuffer_alist.
- (memq (cdr buffer) buffers))))
+ (and (memq (cdr buffer) buffers)
+ (funcall predicate buffer)))))
(read-buffer
"Switch to buffer: "
(when (funcall predicate (cons other-name other-buffer))
@@ -1129,6 +1130,27 @@ project--read-project-buffer
nil
predicate)))
+(defcustom project-ignore-buffer-conditions nil
+ "List of conditions to filter the buffers to be switched to.
+If any of these conditions are satisfied for a buffer in the
+current project, `project-switch-to-buffer' ignores it.
+See the doc string of `project-kill-buffer-conditions' for the
+general form of conditions."
+ :type '(repeat (choice regexp function symbol
+ (cons :tag "Major mode"
+ (const major-mode) symbol)
+ (cons :tag "Derived mode"
+ (const derived-mode) symbol)
+ (cons :tag "Negation"
+ (const not) sexp)
+ (cons :tag "Conjunction"
+ (const and) sexp)
+ (cons :tag "Disjunction"
+ (const or) sexp)))
+ :version "29.1"
+ :group 'project
+ :package-version '(project . "0.8.2"))
+
;;;###autoload
(defun project-switch-to-buffer (buffer-or-name)
"Display buffer BUFFER-OR-NAME in the selected window.
@@ -1136,7 +1158,12 @@ project-switch-to-buffer
current project. Two buffers belong to the same project if their
project instances, as reported by `project-current' in each
buffer, are identical."
- (interactive (list (project--read-project-buffer)))
+ (interactive
+ (list (project--read-project-buffer
+ (lambda (buffer)
+ (not
+ (project--buffer-check
+ (cdr buffer) project-ignore-buffer-conditions))))))
(switch-to-buffer buffer-or-name))
;;;###autoload
@@ -1239,11 +1266,12 @@ project--buffer-list
(push buf bufs)))
(nreverse bufs)))
-(defun project--kill-buffer-check (buf conditions)
+(defun project--buffer-check (buf conditions)
"Check if buffer BUF matches any element of the list CONDITIONS.
-See `project-kill-buffer-conditions' for more details on the form
-of CONDITIONS."
- (catch 'kill
+See `project-kill-buffer-conditions' or
+`project-ignore-buffer-conditions' for more details on the
+form of CONDITIONS."
+ (catch 'match
(dolist (c conditions)
(when (cond
((stringp c)
@@ -1258,15 +1286,15 @@ project--kill-buffer-check
(buffer-local-value 'major-mode buf)
(cdr c)))
((eq (car-safe c) 'not)
- (not (project--kill-buffer-check buf (cdr c))))
+ (not (project--buffer-check buf (cdr c))))
((eq (car-safe c) 'or)
- (project--kill-buffer-check buf (cdr c)))
+ (project--buffer-check buf (cdr c)))
((eq (car-safe c) 'and)
(seq-every-p
- (apply-partially #'project--kill-buffer-check
+ (apply-partially #'project--buffer-check
buf)
(mapcar #'list (cdr c)))))
- (throw 'kill t)))))
+ (throw 'match t)))))
(defun project--buffers-to-kill (pr)
"Return list of buffers in project PR to kill.
@@ -1274,7 +1302,7 @@ project--buffers-to-kill
in `project-kill-buffer-conditions'."
(let (bufs)
(dolist (buf (project-buffers pr))
- (when (project--kill-buffer-check buf project-kill-buffer-conditions)
+ (when (project--buffer-check buf project-kill-buffer-conditions)
(push buf bufs)))
bufs))
--
2.25.1
next prev parent reply other threads:[~2022-02-25 6:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-22 8:27 bug#54100: 29.0.50; Allow project-buffers to ignore some buffers Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-22 9:41 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-22 14:23 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-23 2:49 ` Dmitry Gutov
2022-02-23 6:56 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-23 9:48 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-23 9:55 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-23 15:00 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-24 7:18 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-25 2:33 ` Dmitry Gutov
2022-02-25 6:44 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-02-26 1:50 ` Dmitry Gutov
2022-02-26 6:32 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-27 3:27 ` Dmitry Gutov
2022-02-27 7:09 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-27 7:41 ` Eli Zaretskii
2022-02-27 7:43 ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
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=48d94136-bda9-091e-0370-788f3d706a9d@inventati.org \
--to=bug-gnu-emacs@gnu.org \
--cc=54100@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
--cc=manuel.uberti@inventati.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.