[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/consult 97671ebbbc 1/3: Refactor consult-info
From: |
ELPA Syncer |
Subject: |
[elpa] externals/consult 97671ebbbc 1/3: Refactor consult-info |
Date: |
Wed, 25 Jan 2023 15:57:26 -0500 (EST) |
branch: externals/consult
commit 97671ebbbcac451fb59e01040616f8a5c17f7132
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Refactor consult-info
---
consult-info.el | 57 ++++++++++++++++++++++++++-------------------------------
1 file changed, 26 insertions(+), 31 deletions(-)
diff --git a/consult-info.el b/consult-info.el
index 6682002e16..c05761f2cc 100644
--- a/consult-info.el
+++ b/consult-info.el
@@ -87,43 +87,37 @@
(push cand candidates))))))))
(nreverse candidates)))
-(defun consult-info--lookup (selected candidates &rest _)
- "Lookup info position marker given SELECTED candidate from CANDIDATES list."
- (when-let ((cand (car (member selected candidates)))
- (pos (get-text-property 0 'consult--info-position cand))
+(defun consult-info--position (cand)
+ "Return position information for CAND."
+ (when-let ((pos (get-text-property 0 'consult--info-position cand))
(node (get-text-property 0 'consult--prefix-group cand))
- (matches (consult--point-placement cand (1+ (length node)))))
- (save-restriction
- (widen)
- (cons node
- (cons
- (set-marker (make-marker) (+ (cdr pos) (car matches)) (car pos))
- (cdr matches))))))
+ (matches (consult--point-placement cand (1+ (length node))))
+ (dest (+ (cdr pos) (car matches))))
+ (list node dest (cons
+ (set-marker (make-marker) dest (car pos))
+ (cdr matches)))))
+
+(defun consult-info--jump (cand)
+ "Jump to info CAND."
+ (when-let ((pos (consult-info--position cand)))
+ (info (car pos))
+ (widen)
+ (goto-char (cadr pos))
+ (Info-select-node)
+ (run-hooks 'consult-after-jump-hook)))
(defun consult-info--state ()
"Info manual preview state."
(let ((preview (consult--jump-preview)))
(lambda (action cand)
- (if (not cand)
- (funcall preview action nil)
- (let* ((pos (get-text-property 0 'consult--info-position cand))
- (node (get-text-property 0 'consult--prefix-group cand))
- (matches (consult--point-placement cand (1+ (length node))))
- (dest (+ (cdr pos) (car matches))))
- (funcall preview action
- (cons
- (set-marker (make-marker) dest (car pos))
- (cdr matches)))
- (pcase action
- ('preview
- (let (Info-history Info-history-list Info-history-forward)
- (ignore-errors (Info-select-node))))
- ('return
- (info node)
- (widen)
- (goto-char dest)
- (Info-select-node)
- (run-hooks 'consult-after-jump-hook))))))))
+ (cond
+ ((not cand) (funcall preview action nil))
+ ((eq action 'preview)
+ (funcall preview 'preview (caddr (consult-info--position cand)))
+ (let (Info-history Info-history-list Info-history-forward)
+ (ignore-errors (Info-select-node))))
+ ((eq action 'return)
+ (consult-info--jump cand))))))
;;;###autoload
(defun consult-info (&rest manuals)
@@ -151,6 +145,7 @@
:prompt (format "Info (%s): " (string-join manuals ", "))
:require-match t
:sort nil
+ :category 'consult-info
:history '(:input consult-info--history)
:group #'consult--prefix-group
:initial (consult--async-split-initial "")