[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/beframe cf56beca8e 3/4: Merge pull request #7 from BBoa
From: |
ELPA Syncer |
Subject: |
[elpa] externals/beframe cf56beca8e 3/4: Merge pull request #7 from BBoal/collect-bufs |
Date: |
Thu, 15 Aug 2024 09:57:28 -0400 (EDT) |
branch: externals/beframe
commit cf56beca8ede0e995033c23aefc2efac517ca063
Merge: af8ef10149 3009b26402
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: GitHub <noreply@github.com>
Merge pull request #7 from BBoal/collect-bufs
General refactoring refinements
---
beframe.el | 68 +++++++++++++++++++++++++++++---------------------------------
1 file changed, 32 insertions(+), 36 deletions(-)
diff --git a/beframe.el b/beframe.el
index 0e807262de..00e1e0bac9 100644
--- a/beframe.el
+++ b/beframe.el
@@ -127,38 +127,34 @@ automatically, use `customize-set-variable' or `setopt'
(Emacs
(beframe--functions-in-frames))
:type 'symbol)
-(defun beframe--frame-buffers (&optional frame)
- "Produce list of buffers for either specified or current FRAME."
- (seq-filter
- (lambda (buf)
- (and (bufferp buf)
- (not (string-prefix-p " " (buffer-name buf)))))
- (frame-parameter frame 'buffer-list)))
-
-(defun beframe--public-buffers ()
- "Return list of buffers from all frames.
-This is the same as the output of the `buffer-list' function
-minus all the internal buffers."
- (seq-filter
- (lambda (buf)
- (and (bufferp buf)
- (not (string-prefix-p " " (buffer-name buf)))))
- (buffer-list)))
-
-(defun beframe--global-buffers ()
- "Return list of `beframe-global-buffers' buffer objects."
- (mapcan
- (lambda (regexp-or-symbol)
- (seq-filter
- (lambda (buffer)
- (when (or (and (stringp regexp-or-symbol)
- (string-match-p regexp-or-symbol (buffer-name buffer)))
- (and (symbolp regexp-or-symbol)
- (with-current-buffer buffer
- (derived-mode-p regexp-or-symbol))))
- buffer))
- (beframe--public-buffers)))
- beframe-global-buffers))
+
+(defun beframe--remove-internal-buffers (buffers)
+ "Removes internal buffers from BUFFERS list."
+ (cl-flet ((beframe--filter-internal-p (buffer)
+ (string-prefix-p " " (buffer-name buffer))))
+ (seq-remove #'beframe--filter-internal-p buffers)))
+
+
+
+(defun beframe--get-buffers (&optional arg)
+ "Return list of buffers from different sources depending on ARG.
+
+The following values of ARG can be used:
+
+- nil or \\='public\\=' to consider the return value of the `buffer-list'
+ function.
+
+- \\='global\\=' to consider the user-custom option in `beframe-global-buffers'
+
+ARG can be the symbol \\='public or nil for `buffer-list' return value."
+ (pcase arg
+ ((or 'public (pred null))
+ (beframe--remove-internal-buffers (buffer-list)))
+ ('global (beframe--global-buffers))
+ ((or (and 'frame (let frame nil))
+ (and (pred frame-live-p) (let frame arg)))
+ (beframe--remove-internal-buffers (frame-parameter frame 'buffer-list)))
+ (_ (user-error "Wrong argument in `beframe--get-buffers' pcase"))))
(cl-defun beframe-buffer-list (&optional frame &key sort)
"Return list of buffers that are used by the current frame.
@@ -174,7 +170,7 @@ Include `beframe-global-buffers' in the list."
(funcall (or sort #'identity)
(delq nil
(delete-dups
- (append (beframe--frame-buffers frame)
+ (append (beframe--get-buffers frame)
(beframe--global-buffers))))))
(define-obsolete-function-alias
@@ -191,7 +187,7 @@ more information."
(defun beframe--buffer-names-consolidated ()
"Return list of names of all buffers as strings."
- (mapcar #'buffer-name (beframe--public-buffers)))
+ (mapcar #'buffer-name (beframe--get-buffers 'public)))
(define-obsolete-function-alias
'beframe--buffer-names
@@ -526,7 +522,7 @@ Also see the other Beframe commands:
"Assume the consolidated buffer list (all frames)."
(declare (interactive-only t))
(interactive)
- (beframe--assume (beframe--public-buffers)))
+ (beframe--assume (beframe--get-buffers 'public)))
;;;###autoload
(defun beframe-unassume-all-buffers-no-prompts ()
@@ -538,7 +534,7 @@ Also see the other Beframe commands:
\\{beframe-prefix-map}"
(declare (interactive-only t))
(interactive)
- (beframe--unassume (beframe--public-buffers))
+ (beframe--unassume (beframe--get-buffers 'public))
(beframe--assume (beframe--global-buffers)))
;;; Minor mode setup