emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/consult b74393d 1/2: consult--buffer-query: Add include


From: ELPA Syncer
Subject: [elpa] externals/consult b74393d 1/2: consult--buffer-query: Add include and exclude arguments
Date: Tue, 27 Jul 2021 07:57:08 -0400 (EDT)

branch: externals/consult
commit b74393db756c30fe72b97b73e2b7326c6737cec2
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    consult--buffer-query: Add include and exclude arguments
---
 consult.el | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/consult.el b/consult.el
index 19129f1..c66956d 100644
--- a/consult.el
+++ b/consult.el
@@ -684,7 +684,9 @@ The line beginning/ending BEG/END is bound in BODY."
 
 (defun consult--regexp-filter (regexps)
   "Create filter regexp from REGEXPS."
-  (mapconcat (lambda (x) (concat "\\(?:" x "\\)")) regexps "\\|"))
+  (if (stringp regexps)
+      regexps
+    (mapconcat (lambda (x) (concat "\\(?:" x "\\)")) regexps "\\|")))
 
 (defun consult--directory-prompt-1 (prompt dir)
   "Format PROMPT, expand directory DIR and return them as a pair."
@@ -3602,15 +3604,17 @@ The command supports previewing the currently selected 
theme."
           nil)))
     (nconc (nreverse hidden) buffers (list (current-buffer)))))
 
-(cl-defun consult--buffer-query (&key sort (filter t) directory mode as)
+(cl-defun consult--buffer-query (&key sort directory mode as (filter t)
+                                      include (exclude consult-buffer-filter) )
   "Buffer query function.
 DIRECTORY can either be project or a path.
 SORT can be visibility, alpha or nil.
-FILTER can be t, hidden or nil.
+FILTER can be either t, nil or invert.
+EXCLUDE is a list of regexps.
+INCLUDE is a list of regexps.
 MODE can be a mode or a list of modes to restrict the returned buffers.
 AS is a conversion function."
-  ;; This function is quite messy but optimized to avoid unnecessary
-  ;; allocations. It is the backbone of most `consult-buffer' source. The
+  ;; This function is the backbone of most `consult-buffer' source. The
   ;; function supports filtering by various criteria which are used throughout
   ;; Consult.
   (when-let (root (pcase-exhaustive directory
@@ -3622,7 +3626,8 @@ AS is a conversion function."
         (setq buffers (funcall (intern (format "consult--buffer-sort-%s" 
sort)) buffers)))
       (when (or filter mode as (stringp root))
         (let ((mode (if (listp mode) mode (list mode)))
-              (re (consult--regexp-filter consult-buffer-filter)))
+              (exclude-re (consult--regexp-filter exclude))
+              (include-re (consult--regexp-filter include)))
           (consult--keep! buffers
             (and
              (or (not mode)
@@ -3630,8 +3635,13 @@ AS is a conversion function."
                         (buffer-local-value 'major-mode it) mode))
              (pcase-exhaustive filter
                ('nil t)
-               ('hidden (string-match-p re (buffer-name it)))
-               ('t (not (string-match-p re (buffer-name it)))))
+               ((or 't 'invert)
+                (eq (eq filter t)
+                    (and
+                     (or (not exclude)
+                         (not (string-match-p exclude-re (buffer-name it))))
+                     (or (not include)
+                         (not (not (string-match-p include-re (buffer-name 
it)))))))))
              (or (not (stringp root))
                  (when-let (dir (buffer-local-value 'default-directory it))
                    (string-prefix-p root
@@ -3740,7 +3750,7 @@ If NORECORD is non-nil, do not record the buffer switch 
in the buffer list."
     :action   ,#'consult--buffer-action
     :items
     ,(lambda () (consult--buffer-query :sort 'visibility
-                                       :filter 'hidden
+                                       :filter 'invert
                                        :as #'buffer-name)))
   "Hidden buffer candidate source for `consult-buffer'.")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]