chore(navigation/consult): update consult and custom query functions

This commit is contained in:
2022-05-12 00:34:01 +01:00
parent 8e686b7826
commit c8a1170641
2 changed files with 37 additions and 37 deletions

View File

@@ -150,7 +150,7 @@ DIR can be project, not-project, nil or a path."
(dir (expand-file-name dir))))
(cl-defun siren-consult--buffer-query (&key sort directory mode as predicate (filter t)
include (exclude consult-buffer-filter))
include (exclude consult-buffer-filter))
"Buffer query function.
DIRECTORY can either be project, not-project or a path.
SORT can be visibility, alpha or nil.
@@ -163,40 +163,40 @@ AS is a conversion function."
;; 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 (or (siren-consult--normalize-directory directory) t))
(let ((buffers (buffer-list))
(not-project (eq directory 'not-project)))
(when sort
(setq buffers (funcall (intern (format "consult--buffer-sort-%s" sort)) buffers)))
(when (or filter mode as (stringp root))
(let ((mode (consult--ensure-list mode))
(exclude-re (consult--regexp-filter exclude))
(include-re (consult--regexp-filter include)))
(consult--keep! buffers
(and
(or (not mode)
(apply #'provided-mode-derived-p
(buffer-local-value 'major-mode it) mode))
(pcase-exhaustive filter
('nil t)
((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))
(let ((in-project (string-prefix-p root
(if (and (/= 0 (length dir)) (eq (aref dir 0) ?/))
dir
(expand-file-name dir)))))
(or (and not-project (not in-project))
(and (not not-project) in-project)))))
(or (not predicate) (funcall predicate it))
(if as (funcall as it) it)))))
buffers))))
(let ((root (siren-consult--normalize-directory directory))
(buffers (buffer-list))
(not-project (eq directory 'not-project)))
(when sort
(setq buffers (funcall (intern (format "consult--buffer-sort-%s" sort)) buffers)))
(when (or filter mode as root)
(let ((mode (ensure-list mode))
(exclude-re (consult--regexp-filter exclude))
(include-re (consult--regexp-filter include)))
(consult--keep! buffers
(and
(or (not mode)
(apply #'provided-mode-derived-p
(buffer-local-value 'major-mode it) mode))
(pcase-exhaustive filter
('nil t)
((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 root)
(when-let (dir (buffer-local-value 'default-directory it))
(let ((in-project (string-prefix-p root
(if (and (/= 0 (length dir)) (eq (aref dir 0) ?/))
dir
(expand-file-name dir)))))
(or (and not-project (not in-project))
(and (not not-project) in-project)))))
(or (not predicate) (funcall predicate it))
(if as (funcall as it) it)))))
buffers)))
(provide 'siren-consult)
;;; siren-consult.el ends here