branch: externals/beframe commit 7dd8bc1fb7fe478622dd88917e81b6cb5e7a64d1 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Make stylistic changes to beframe--global-buffers We do not use the cl-loop elsewhere, so I prefer to be consistent. Makes it easier to follow the entire code base. --- beframe.el | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/beframe.el b/beframe.el index b338634986..020104f247 100644 --- a/beframe.el +++ b/beframe.el @@ -166,6 +166,31 @@ through `beframe--remove-internal-buffers'." (string-match-p regexp (buffer-name buffer)))) buffers))) +(defun beframe--parse-global-buffers () + "Parse `beframe-global-buffers' into (regexp . symbols). +Make strings a single regular expression out of all strings and collect +any symbols into a list." + (let ((strings nil) + (symbols nil)) + (dolist (element beframe-global-buffers) + (or (and (stringp element) (push element strings)) + (and (symbolp element) (push element symbols)))) + (cons (string-join strings "\\|") symbols))) + +(defun beframe--global-buffers () + "Return list of `beframe-global-buffers' buffer objects." + (pcase-let* ((public-buffers (beframe--get-buffers 'public)) + (global-buffers nil) + (`(,regexp . ,modes) (beframe--parse-global-buffers))) + (dolist (buffer public-buffers) + (cond + ((string-match-p regexp (buffer-name buffer)) + (push buffer global-buffers)) + ((with-current-buffer buffer + (when (derived-mode-p modes) + (push buffer global-buffers)))))) + global-buffers)) + (defun beframe--get-buffers (&optional arg) "Return list of buffers from different sources depending on ARG. @@ -200,19 +225,6 @@ The following values of ARG can be used: (beframe--remove-internal-buffers (frame-parameter arg 'buffer-list))) (_ (user-error "Wrong argument in `beframe--get-buffers' pcase")))) -(defun beframe--global-buffers () - "Return list of `beframe-global-buffers' buffer objects." - (pcase-let* ((pub-buffs (beframe--get-buffers 'public)) - (`(,str-re ,modes-lst) - (cl-loop for E in beframe-global-buffers - if (stringp E) collect E into str - else if (symbolp E) collect E into sym - finally return (list (string-join str "\\|") sym)))) - (cl-loop for b in pub-buffs - if (string-match-p str-re (buffer-name b)) collect b - else if (with-current-buffer b (derived-mode-p modes-lst)) - collect b))) - (cl-defun beframe-buffer-list (&optional frame &key sort) "Return list of buffers that are used by the current frame. With optional FRAME as an object that satisfies `framep', return