diff --git a/lisp/lib/buffers.el b/lisp/lib/buffers.el index 93816f6dc..bbc360110 100644 --- a/lisp/lib/buffers.el +++ b/lisp/lib/buffers.el @@ -91,12 +91,12 @@ If no project is active, return all buffers." ;;;###autoload (defun doom-special-buffer-p (buf) "Returns non-nil if BUF's name starts and ends with an *." - (equal (substring (buffer-name buf) 0 1) "*")) + (char-equal ?* (aref (buffer-name buf) 0))) ;;;###autoload (defun doom-temp-buffer-p (buf) "Returns non-nil if BUF is temporary." - (equal (substring (buffer-name buf) 0 1) " ")) + (char-equal ?\s (aref (buffer-name buf) 0))) ;;;###autoload (defun doom-visible-buffer-p (buf) @@ -111,12 +111,14 @@ If no project is active, return all buffers." ;;;###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))) + (not (buffer-file-name (or (buffer-base-buffer buf) buf)))) ;;;###autoload (defun doom-real-buffer-list (&optional buffer-list) "Return a list of buffers that satisfy `doom-real-buffer-p'." - (cl-remove-if-not #'doom-real-buffer-p (or buffer-list (doom-buffer-list)))) + (cl-loop for buf in (or buffer-list (doom-buffer-list)) + if (doom-real-buffer-p buf) + collect buf)) ;;;###autoload (defun doom-real-buffer-p (buffer-or-name) @@ -160,15 +162,13 @@ See `doom-real-buffer-p' for details on what that means." "Return a list of buffers whose `major-mode' is `eq' to MODE(S). If DERIVED-P, test with `derived-mode-p', otherwise use `eq'." - (let ((modes (ensure-list modes))) - (cl-remove-if-not (if derived-p - (lambda (buf) - (apply #'provided-mode-derived-p - (buffer-local-value 'major-mode buf) - modes)) - (lambda (buf) - (memq (buffer-local-value 'major-mode buf) modes))) - (or buffer-list (doom-buffer-list))))) + (cl-loop with modes = (ensure-list modes) + for buf in (or buffer-list (doom-buffer-list)) + for mode = (buffer-local-value 'major-mode buf) + if (if derived-p + (apply #'provided-mode-derived-p mode modes) + (memq mode modes)) + collect buf)) ;;;###autoload (defun doom-visible-windows (&optional window-list) @@ -187,20 +187,23 @@ If DERIVED-P, test with `derived-mode-p', otherwise use `eq'." if (window-list frame) nconc (mapcar #'window-buffer it))))) (if buffer-list - (cl-delete-if (lambda (b) (memq b buffer-list)) - buffers) - (delete-dups buffers)))) + (cl-loop for buf in buffers + unless (memq buf buffer-list) + collect buffers) + buffers))) ;;;###autoload (defun doom-buried-buffers (&optional buffer-list) "Get a list of buffers that are buried." - (cl-remove-if #'get-buffer-window (or buffer-list (doom-buffer-list)))) + (cl-loop for buf in (or buffer-list (doom-buffer-list)) + unless (doom-visible-buffer-p buf) + collect buf)) ;;;###autoload (defun doom-matching-buffers (pattern &optional buffer-list) "Get a list of all buffers that match the regex PATTERN." (cl-loop for buf in (or buffer-list (doom-buffer-list)) - when (string-match-p pattern (buffer-name buf)) + if (string-match-p pattern (buffer-name buf)) collect buf)) ;;;###autoload diff --git a/lisp/lib/files.el b/lisp/lib/files.el index 5a9d37d83..f5a153216 100644 --- a/lisp/lib/files.el +++ b/lisp/lib/files.el @@ -45,6 +45,7 @@ This is used by `file-exists-p!' and `project-file-exists-p!'." Ignores `nil' elements in SEGMENTS, and is intended as a fast compromise between `expand-file-name' (slow, but accurate), `file-name-concat' (fast, but inaccurate)." + (declare (side-effect-free t)) ;; PERF: An empty `file-name-handler-alist' = faster `expand-file-name'. (let (file-name-handler-alist) (expand-file-name @@ -69,7 +70,9 @@ If the glob ends in a slash, only returns matching directories." file-name-handler-alist (path (apply #'file-name-concat segments))) (if (string-suffix-p "/" path) - (cl-delete-if-not #'file-directory-p (file-expand-wildcards (substring path 0 -1))) + (cl-loop for file in (file-expand-wildcards (substring path 0 -1)) + if (file-directory-p file) + collect file) (file-expand-wildcards path)))) ;;;###autoload