[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/corfu 4e5a41b8fd 2/7: Add corfu-docframe-location and c
From: |
ELPA Syncer |
Subject: |
[elpa] externals/corfu 4e5a41b8fd 2/7: Add corfu-docframe-location and corfu-docframe-documentation |
Date: |
Fri, 18 Nov 2022 05:57:33 -0500 (EST) |
branch: externals/corfu
commit 4e5a41b8fde566b5437b7875635e863e7a65b29a
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add corfu-docframe-location and corfu-docframe-documentation
---
extensions/corfu-docframe.el | 55 +++++++++++++++++++++++++++++---------------
1 file changed, 37 insertions(+), 18 deletions(-)
diff --git a/extensions/corfu-docframe.el b/extensions/corfu-docframe.el
index a39e4375d4..942ec2b1f0 100644
--- a/extensions/corfu-docframe.el
+++ b/extensions/corfu-docframe.el
@@ -36,6 +36,8 @@
;; `corfu-docframe-toggle' to a key in `corfu-map':
;;
;; (define-key corfu-map "\M-d" #'corfu-docframe-toggle)
+;; (define-key corfu-map "\M-g" #'corfu-docframe-location)
+;; (define-key corfu-map "\M-h" #'corfu-docframe-documentation)
;;; Code:
@@ -83,7 +85,7 @@
"Local docframe toggle state.")
(defvar-local corfu-docframe--function
- #'corfu-docframe--documentation
+ #'corfu-docframe--get-documentation
"Documentation function.")
(defvar corfu-docframe--frame nil
@@ -120,25 +122,29 @@ See `frame-edges' for details.")
(and (frame-live-p corfu-docframe--frame)
(frame-visible-p corfu-docframe--frame)))
-(defun corfu-docframe--get-source (candidate)
+(defun corfu-docframe--get-location (candidate)
+ "Get source at location of CANDIDATE."
+ (save-excursion
(when-let* ((fun (plist-get corfu--extra :company-location))
(loc (funcall fun candidate))
(res (or (and (bufferp (car loc)) (car loc))
(find-file-noselect (car loc) t))))
- (save-window-excursion
- (with-current-buffer res
- (save-excursion
- (save-restriction
- (widen)
- (if (bufferp (car loc))
- (goto-char (cdr loc))
- (goto-char (point-min))
- (forward-line (1- (cdr loc))))
- (setq res (buffer-substring (point) (point-max)))
- (and (not (string-blank-p res)) res)))))))
+ (with-current-buffer res
+ (save-excursion
+ (save-restriction
+ (widen)
+ (if (bufferp (car loc))
+ (goto-char (cdr loc))
+ (goto-char (point-min))
+ (forward-line (1- (cdr loc))))
+ (let ((beg (point)))
+ (forward-line (* 2 corfu-docframe-max-height))
+ (when jit-lock-mode
+ (jit-lock-fontify-now beg (point)))
+ (setq res (buffer-substring beg (point)))
+ (and (not (string-blank-p res)) res))))))))
(defun corfu-docframe--get-documentation (candidate)
- "Get the documentation for CANDIDATE.
-Returns nil if an error occurs or the documentation content is empty."
+ "Get the documentation for CANDIDATE."
(when-let* ((fun (plist-get corfu--extra :company-doc-buffer))
(res (save-excursion
(let ((inhibit-message t)
@@ -293,7 +299,7 @@ the corfu popup, its value is 'bottom, 'top, 'right or
'left."
(new-edges (frame-edges corfu--frame 'inner-edges))
(edges-changed (not (equal new-edges corfu-docframe--edges))))
(when doc-changed
- (if-let (doc (corfu-docframe--get-source candidate))
+ (if-let (doc (funcall corfu-docframe--function candidate))
(with-current-buffer (corfu--make-buffer " *corfu-docframe*" doc)
;; TODO extract settings
(setq-local line-move-visual t
@@ -346,12 +352,25 @@ If ARG is omitted or nil, scroll down by a near full
screen."
(interactive "p")
(corfu-docframe-scroll-up (- (or n 1))))
-(defun corfu-docframe-show-location ()
- (setq corfu-docframe--function #'corfu-)
+(defun corfu-docframe--set-function (fun)
+ "Set popup documentation getter FUN."
+ (setq corfu-docframe--function fun
+ corfu-docframe--candidate nil
+ corfu-docframe--toggle t)
(when-let (candidate (and (>= corfu--index 0)
(nth corfu--index corfu--candidates)))
(corfu-docframe--show candidate)))
+(defun corfu-docframe-documentation ()
+ "Show documentation in popup."
+ (interactive)
+ (corfu-docframe--set-function #'corfu-docframe--get-documentation))
+
+(defun corfu-docframe-location ()
+ "Show location in popup."
+ (interactive)
+ (corfu-docframe--set-function #'corfu-docframe--get-location))
+
(defun corfu-docframe-toggle ()
"Toggle the doc popup display or hide.
- [elpa] externals/corfu updated (9f735cf4e6 -> cfc97d4885), ELPA Syncer, 2022/11/18
- [elpa] externals/corfu 4e0ee2f98e 5/7: corfu-infoframe: Update commentary, ELPA Syncer, 2022/11/18
- [elpa] externals/corfu 7aa006e000 6/7: corfu-infoframe: Remap scroll commands, ELPA Syncer, 2022/11/18
- [elpa] externals/corfu cfc97d4885 7/7: corfu-infoframe: Reduce print length (Fix #249), ELPA Syncer, 2022/11/18
- [elpa] externals/corfu 52f6701197 1/7: Try to implement location support for docframe, ELPA Syncer, 2022/11/18
- [elpa] externals/corfu 4e5a41b8fd 2/7: Add corfu-docframe-location and corfu-docframe-documentation,
ELPA Syncer <=
- [elpa] externals/corfu de6c1dd044 3/7: Rename to corfu-infoframe, ELPA Syncer, 2022/11/18
- [elpa] externals/corfu 82f8ae9c9e 4/7: Add corfu-infoframe-map, ELPA Syncer, 2022/11/18