Improve consult-project-buffer

This commit is contained in:
David Morgan 2021-09-17 16:37:43 +01:00
parent be55778d76
commit 1447feb491
1 changed files with 22 additions and 16 deletions

View File

@ -336,31 +336,37 @@ DEFS is a plist associating completion categories to commands."
(add-to-list 'consult-buffer-sources 'consult--source-perspective-files t) (add-to-list 'consult-buffer-sources 'consult--source-perspective-files t)
;; Versions of consult--source-project-buffer and consult--source-project-file for use by consult-project-buffer ;; Versions of consult--source-project-buffer and consult--source-project-file for use by consult-project-buffer
;; They allow narrowing with b and f (instead of p) ;; They allow narrowing with b, f and a (instead of p)
;; The file version uses fd to find items, so that all files (rather than using recentf) are listed, respecing .gitignore ;; f is the recentf version provided by consult
;; a is an "all files" version based on fd (respecting .gitignore, hidden by default)
(defvar consult--project-source-project-buffer (defvar consult--project-source-project-buffer
(plist-put (plist-put (copy-sequence consult--source-project-buffer) (plist-put (plist-put (copy-sequence consult--source-project-buffer)
:hidden nil) :hidden nil)
:narrow '(?b . "Buffer"))) :narrow '(?b . "Buffer")))
(defvar consult--project-source-project-file (defvar consult--project-source-project-file-recentf
(plist-put (plist-put (plist-put (copy-sequence consult--source-project-file) (plist-put (plist-put (copy-sequence consult--source-project-file)
:hidden nil) :hidden nil)
:narrow '(?f . "File")) :narrow '(?f . "File (Recentf)")))
(defvar consult--project-source-project-file-all
(plist-put (plist-put (copy-sequence consult--source-project-file)
:narrow '(?a . "File (All)"))
:items '(lambda () :items '(lambda ()
(when-let (root (consult--project-root)) (when (eq 0 (call-process-shell-command "fd"))
(let ((len (length root)) (when-let (root (consult--project-root))
(inv-root (propertize root 'invisible t))) (let ((len (length root))
(mapcar (lambda (x) (inv-root (propertize root 'invisible t)))
(concat inv-root (substring x len))) (mapcar (lambda (x)
(split-string (concat inv-root (substring x len)))
(shell-command-to-string (split-string
(format "fd --color never -t f -0 . %s" root)) (shell-command-to-string
"\0" t))))))) (format "fd --color never -t f -0 . %s" root))
"\0" t))))))))
(defun consult-project-buffer () (defun consult-project-buffer ()
(interactive) (interactive)
(let ((consult-buffer-sources '(consult--project-source-project-buffer (let ((consult-buffer-sources '(consult--project-source-project-buffer
consult--project-source-project-file))) consult--project-source-project-file-recentf
consult--project-source-project-file-all)))
(consult-buffer))) (consult-buffer)))
(defun consult--orderless-regexp-compiler (input type) (defun consult--orderless-regexp-compiler (input type)