[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 0d0dc1af59 2/2: Add new user option switch-to-prev-buffer-skip-re
From: |
Lars Ingebrigtsen |
Subject: |
master 0d0dc1af59 2/2: Add new user option switch-to-prev-buffer-skip-regexp |
Date: |
Wed, 11 May 2022 21:35:56 -0400 (EDT) |
branch: master
commit 0d0dc1af591c2cb687462e88631561fbf2690ba4
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Add new user option switch-to-prev-buffer-skip-regexp
* doc/lispref/windows.texi (Window History): Document it.
* lisp/window.el (switch-to-prev-buffer-skip): Mention it.
(switch-to-prev-buffer-skip-regexp): New user option (bug#19070).
(switch-to-prev-buffer-skip-p): Use it.
---
doc/lispref/windows.texi | 7 +++++++
etc/NEWS | 6 ++++++
lisp/window.el | 33 ++++++++++++++++++++++++++++-----
3 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index 57763c146d..f0d5f9fc20 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -4173,6 +4173,13 @@ ignore this option, for example, when there is only one
buffer left
these functions can switch to.
@end defopt
+@defopt switch-to-prev-buffer-skip-regexp
+This user option should be either a regular expression, or a list of
+regular expressions, and buffers that have names that match this
+option will be ignored by @code{switch-to-prev-buffer} and
+@code{switch-to-next-buffer} (except when there's no other buffer to
+switch to).
+@end defopt
@node Dedicated Windows
@section Dedicated Windows
diff --git a/etc/NEWS b/etc/NEWS
index 5e4e2e98ec..d9777eecd6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -256,6 +256,12 @@ startup. Previously, these functions ignored
* Changes in Emacs 29.1
++++
+*** New user option 'switch-to-prev-buffer-skip-regexp'.
+This should be a regexp or a list of regexps, and buffers with names
+matching this will be ignored by 'switch-to-prev-buffer' and
+'switch-to-next-buffer'.
+
** Menus
---
diff --git a/lisp/window.el b/lisp/window.el
index dd16b83377..1495b2e0ad 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -4578,7 +4578,9 @@ as well. In that case, if this option specifies a
function, it
will be called with the third argument nil.
Under certain circumstances `switch-to-prev-buffer' may ignore
-this option, for example, when there is only one buffer left."
+this option, for example, when there is only one buffer left.
+
+Also see `switch-to-prev-buffer-skip-regexp'."
:type
'(choice (const :tag "Never" nil)
(const :tag "This frame" this)
@@ -4589,16 +4591,37 @@ this option, for example, when there is only one buffer
left."
:version "27.1"
:group 'windows)
+(defcustom switch-to-prev-buffer-skip-regexp nil
+ "Regexp matching buffers that should be skipped by `switch-to-prev-buffer'.
+This also affects `switch-to-next-buffer'.
+
+This can either be a regexp or a list of regexps.
+
+Also see `switch-to-prev-buffer-skip'."
+ :type '(choice regexp
+ (repeat regexp))
+ :version "29.1"
+ :group 'windows)
+
(defun switch-to-prev-buffer-skip-p (skip window buffer &optional bury-or-kill)
"Return non-nil if `switch-to-prev-buffer' should skip BUFFER.
SKIP is a value derived from `switch-to-prev-buffer-skip', WINDOW
the window `switch-to-prev-buffer' acts upon. Optional argument
BURY-OR-KILL is passed unchanged by `switch-to-prev-buffer' and
omitted in calls from `switch-to-next-buffer'."
- (when skip
- (if (functionp skip)
- (funcall skip window buffer bury-or-kill)
- (get-buffer-window buffer skip))))
+ (or (and skip
+ (if (functionp skip)
+ (funcall skip window buffer bury-or-kill)
+ (get-buffer-window buffer skip)))
+ (and switch-to-prev-buffer-skip-regexp
+ (or (and (stringp switch-to-prev-buffer-skip-regexp)
+ (string-match-p switch-to-prev-buffer-skip-regexp
+ (buffer-name buffer)))
+ (and (consp switch-to-prev-buffer-skip-regexp)
+ (catch 'found
+ (dolist (regexp switch-to-prev-buffer-skip-regexp)
+ (when (string-match-p regexp (buffer-name buffer))
+ (throw 'tag t)))))))))
(defun switch-to-prev-buffer (&optional window bury-or-kill)
"In WINDOW switch to previous buffer.