[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult 0abeee7ea8 1/3: Add consult--source-file-regist
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult 0abeee7ea8 1/3: Add consult--source-file-register |
Date: |
Wed, 19 Oct 2022 04:57:33 -0400 (EDT) |
branch: externals/consult
commit 0abeee7ea8f0b45cc26f44cf433255dd7106e858
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add consult--source-file-register
I had this source sitting for a while in my personal configuration.
---
CHANGELOG.org | 6 ++++++
README.org | 14 ++++++++------
consult-register.el | 22 ++++++++++++++--------
consult.el | 15 +++++++++++++++
4 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/CHANGELOG.org b/CHANGELOG.org
index 18dfa88600..ae4eb845fc 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -2,6 +2,12 @@
#+author: Daniel Mendler
#+language: en
+* Development
+
+- Add =consult--source-file-register=, and make the registers available in
+ =consult-buffer=.Registers are often used as quick access keys for files,
e.g.,
+ =(add-to-list 'register-alist '(?i file . "~/.emacs.d/init.el")))=.
+
* Version 0.20 (2022-10-16)
- Bugfixes
diff --git a/README.org b/README.org
index 8f465af85b..386390f96a 100644
--- a/README.org
+++ b/README.org
@@ -97,6 +97,7 @@ their descriptions.
- SPC Hidden buffers
- * Modified buffers
- f Files (Requires =recentf-mode=)
+ - r File registers
- m Bookmarks
- p Project
- Custom [[#multiple-sources][other sources]] configured in
=consult-buffer-sources=.
@@ -436,8 +437,8 @@ to be considered.
(consult-customize
consult-ripgrep consult-git-grep consult-grep
consult-bookmark consult-recent-file consult-xref
- consult--source-bookmark consult--source-recent-file
- consult--source-project-recent-file
+ consult--source-bookmark consult--source-file-register
+ consult--source-recent-file consult--source-project-recent-file
;; my/command-wrapping-consult ;; disable auto previews inside my
command
;; :preview-key '(:debounce 0.2 any) ;; Option 1: Delay preview
:preview-key (kbd "M-.")) ;; Option 2: Manual preview
@@ -614,8 +615,9 @@ configure a manual preview as follows.
#+begin_src emacs-lisp
(consult-customize
- consult--source-bookmark consult--source-recent-file
- consult--source-project-recent-file :preview-key (kbd "M-."))
+ consult--source-bookmark consult--source-file-register
+ consult--source-recent-file consult--source-project-recent-file
+ :preview-key (kbd "M-."))
#+end_src
Sources can be added directly to the =consult-buffer-source= list for
convenience.
@@ -843,8 +845,8 @@ configuration examples.
:preview-key '(:debounce 0.2 any)
consult-ripgrep consult-git-grep consult-grep
consult-bookmark consult-recent-file consult-xref
- consult--source-bookmark consult--source-recent-file
- consult--source-project-recent-file
+ consult--source-bookmark consult--source-file-register
+ consult--source-recent-file consult--source-project-recent-file
:preview-key (kbd "M-."))
;; Optionally configure the narrowing key.
diff --git a/consult-register.el b/consult-register.el
index 7b5f0f71b1..dbfb9ed586 100644
--- a/consult-register.el
+++ b/consult-register.el
@@ -160,14 +160,22 @@ If COMPLETION is non-nil format the register for
completion."
str))
str))
-(defun consult-register--alist (&optional noerror)
- "Return sorted register list.
+(defun consult-register--alist (&optional noerror filter)
+ "Return register list, sorted and filtered with FILTER.
Raise an error if the list is empty and NOERROR is nil."
- ;; Sometimes, registers are made without a `cdr'.
- ;; Such registers don't do anything, and can be ignored.
- (or (sort (seq-filter #'cdr register-alist) #'car-less-than-car)
+ (or (sort (seq-filter
+ ;; Sometimes, registers are made without a `cdr'.
+ ;; Such registers don't do anything, and can be ignored.
+ (lambda (x) (and (cdr x) (or (not filter) (funcall filter x))))
+ register-alist)
+ #'car-less-than-car)
(and (not noerror) (user-error "All registers are empty"))))
+(defun consult-register--candidates (&optional filter)
+ "Return formatted completion candidates, filtered with FILTER."
+ (mapcar (lambda (reg) (consult-register-format reg 'completion))
+ (consult-register--alist nil filter)))
+
;;;###autoload
(defun consult-register (&optional arg)
"Load register and either jump to location or insert the stored text.
@@ -181,9 +189,7 @@ built-in register access functions. The command supports
narrowing, see
(interactive "P")
(consult-register-load
(consult--read
- (mapcar (lambda (reg)
- (consult-register-format reg 'completion))
- (consult-register--alist))
+ (consult-register--candidates)
:prompt "Register: "
:category 'multi-category
:state
diff --git a/consult.el b/consult.el
index bd0dcd4d89..ec9287b435 100644
--- a/consult.el
+++ b/consult.el
@@ -221,6 +221,7 @@ character, the *Completions* buffer and a few log buffers."
consult--source-modified-buffer
consult--source-buffer
consult--source-recent-file
+ consult--source-file-register
consult--source-bookmark
consult--source-project-buffer
consult--source-project-recent-file)
@@ -4256,6 +4257,20 @@ If NORECORD is non-nil, do not record the buffer switch
in the buffer list."
:as #'buffer-name)))
"Buffer candidate source for `consult-buffer'.")
+(defun consult--file-register-p (reg)
+ "Return non-nil if REG is a file register."
+ (memq (car-safe (cdr reg)) '(file-query file)))
+
+(autoload 'consult-register--candidates "consult-register")
+(defvar consult--source-file-register
+ `(:name "File Register"
+ :narrow (?r . "Register")
+ :category file
+ :state ,#'consult--file-state
+ :enabled ,(lambda () (seq-some #'consult--file-register-p register-alist))
+ :items ,(lambda () (consult-register--candidates
#'consult--file-register-p)))
+ "File register source.")
+
(defvar consult--source-recent-file
`(:name "File"
:narrow ?f