New doom-unreal-buffer-functions function & doom-real-buffer-p spec
This commit is contained in:
parent
3d5d1b65b3
commit
e0c8e6daef
1 changed files with 34 additions and 17 deletions
|
@ -2,10 +2,22 @@
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defvar doom-real-buffer-functions '()
|
(defvar doom-real-buffer-functions '()
|
||||||
"A list of predicate functions run to determine if a buffer is real. These
|
"A list of predicate functions run to determine if a buffer is real, unlike
|
||||||
functions are iterated over with one argument, the buffer in question. If any
|
`doom-unreal-buffer-functions'. They are passed one argument: the buffer to be
|
||||||
function returns non-nil, the procession stops and the buffer is qualified as
|
tested.
|
||||||
real.")
|
|
||||||
|
Should any of its function returns non-nil, the rest of the functions are
|
||||||
|
ignored and the buffer is considered real.")
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defvar doom-unreal-buffer-functions
|
||||||
|
'(minibufferp doom-special-buffer-p doom-non-file-visiting-buffer-p)
|
||||||
|
"A list of predicate functions run to determine if a buffer is *not* real,
|
||||||
|
unlike `doom-real-buffer-functions'. They are passed one argument: the buffer to
|
||||||
|
be tested.
|
||||||
|
|
||||||
|
Should any of these functions return non-nil, the rest of the functions are
|
||||||
|
ignored and the buffer is considered unreal.")
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defvar-local doom-real-buffer-p nil
|
(defvar-local doom-real-buffer-p nil
|
||||||
|
@ -42,6 +54,16 @@ If no project is active, return all buffers."
|
||||||
collect buf)
|
collect buf)
|
||||||
buffers)))
|
buffers)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom-special-buffer-p (buf)
|
||||||
|
"Returns non-nil if BUF's name starts and ends with an *."
|
||||||
|
(string-match-p "^\\s-*\\*" (buffer-name buf)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom-non-file-visiting-buffer-p (buf)
|
||||||
|
"Returns non-nil if BUF does not have a value for `buffer-file-name'."
|
||||||
|
(not (buffer-file-name buf)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-real-buffer-list (&optional buffer-list)
|
(defun doom-real-buffer-list (&optional buffer-list)
|
||||||
"Return a list of buffers that satify `doom-real-buffer-p'."
|
"Return a list of buffers that satify `doom-real-buffer-p'."
|
||||||
|
@ -51,25 +73,20 @@ If no project is active, return all buffers."
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-real-buffer-p (&optional buffer-or-name)
|
(defun doom-real-buffer-p (&optional buffer-or-name)
|
||||||
"Returns t if BUFFER-OR-NAME is a 'real' buffer. The complete criteria for a
|
"Returns t if BUFFER-OR-NAME is a 'real' buffer. The criteria for a real
|
||||||
real buffer is:
|
buffer is:
|
||||||
|
|
||||||
1. The buffer-local value of `doom-real-buffer-p' (variable) is non-nil OR
|
1. A non-nil value for the buffer-local value of the `doom-real-buffer-p'
|
||||||
2. Any function in `doom-real-buffer-functions' must return non-nil when
|
variable OR
|
||||||
passed this buffer OR
|
2. Any function in `doom-real-buffer-functions' returns non-nil OR
|
||||||
3. The current buffer:
|
3. None of the functions in `doom-unreal-buffer-functions' must return
|
||||||
a) has a `buffer-file-name' defined AND
|
non-nil.
|
||||||
b) is not in a popup window (see `doom-popup-p') AND
|
|
||||||
c) is not a special buffer (its name isn't something like *Help*)
|
|
||||||
|
|
||||||
If BUFFER-OR-NAME is omitted or nil, the current buffer is tested."
|
If BUFFER-OR-NAME is omitted or nil, the current buffer is tested."
|
||||||
(when-let* ((buf (ignore-errors (window-normalize-buffer buffer-or-name))))
|
(when-let* ((buf (ignore-errors (window-normalize-buffer buffer-or-name))))
|
||||||
(or (buffer-local-value 'doom-real-buffer-p buf)
|
(or (buffer-local-value 'doom-real-buffer-p buf)
|
||||||
(run-hook-with-args-until-success 'doom-real-buffer-functions buf)
|
(run-hook-with-args-until-success 'doom-real-buffer-functions buf)
|
||||||
(not (or (doom-popup-p buf)
|
(not (run-hook-with-args-until-success 'doom-unreal-buffer-functions buf)))))
|
||||||
(minibufferp buf)
|
|
||||||
(string-match-p "^\\s-*\\*" (buffer-name buf))
|
|
||||||
(not (buffer-file-name buf)))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-buffers-in-mode (modes &optional buffer-list derived-p)
|
(defun doom-buffers-in-mode (modes &optional buffer-list derived-p)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue