summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-05-13 16:57:10 +0200
committerDaniel Mendler <mail@daniel-mendler.de>2023-05-13 16:57:50 +0200
commit2019688dfb59f73b54573a25bc5111367fa6e0a3 (patch)
tree34095746cb059be6fbb6ce8c8093e21ef93914a1
parentdb8745f616b859266a0b26fbad061bc576b93c27 (diff)
corfu-info-location/documentation: Prefix arg for persistent buffer and window.
Fix #328
-rw-r--r--CHANGELOG.org2
-rw-r--r--extensions/corfu-info.el61
-rw-r--r--extensions/corfu-popupinfo.el2
3 files changed, 41 insertions, 24 deletions
diff --git a/CHANGELOG.org b/CHANGELOG.org
index 7760c3b..7f1ba79 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -8,6 +8,8 @@
- Close popup when window selection changes.
- Remove =corfu-history-length=. Instead set the =history-length= property of
=corfu-history= variable.
+- =corfu-info-documentation=, =corfu-info-location=: Make buffer and window
+ persistent if called with prefix argument.
* Version 0.36 (2023-03-27)
diff --git a/extensions/corfu-info.el b/extensions/corfu-info.el
index 9c4ab1e..89d660e 100644
--- a/extensions/corfu-info.el
+++ b/extensions/corfu-info.el
@@ -52,26 +52,41 @@
(set-window-configuration config))))
(add-hook 'pre-command-hook restore)))
+(defun corfu-info--display-buffer (buffer name)
+ "Display BUFFER and return window displaying the buffer.
+Make the buffer persistent with NAME if non-nil."
+ (if name
+ (unless (buffer-local-value 'buffer-file-name buffer)
+ (if-let ((old (get-buffer name)))
+ (setq buffer (prog1 old (kill-buffer buffer)))
+ (with-current-buffer buffer
+ (rename-buffer name))))
+ (corfu-info--restore-on-next-command))
+ (setq other-window-scroll-buffer buffer)
+ (display-buffer buffer t))
+
;;;###autoload
-(defun corfu-info-documentation ()
- "Show documentation of current candidate."
- (interactive)
+(defun corfu-info-documentation (&optional arg)
+ "Show documentation of current candidate.
+If called with a prefix ARG, the buffer is persistent."
+ (interactive "P")
;; Company support, taken from `company.el', see `company-show-doc-buffer'.
(when (< corfu--index 0)
(user-error "No candidate selected"))
(let ((cand (nth corfu--index corfu--candidates)))
(if-let ((fun (plist-get corfu--extra :company-doc-buffer))
(res (funcall fun cand)))
- (let ((buf (or (car-safe res) res)))
- (corfu-info--restore-on-next-command)
- (setq other-window-scroll-buffer (get-buffer buf))
- (set-window-start (display-buffer buf t) (or (cdr-safe res) (point-min))))
+ (set-window-start (corfu-info--display-buffer
+ (get-buffer (or (car-safe res) res))
+ (and arg (format "*corfu doc: %s*" cand)))
+ (or (cdr-safe res) (point-min)))
(user-error "No documentation available for `%s'" cand))))
;;;###autoload
-(defun corfu-info-location ()
- "Show location of current candidate."
- (interactive)
+(defun corfu-info-location (&optional arg)
+ "Show location of current candidate.
+If called with a prefix ARG, the buffer is persistent."
+ (interactive "P")
;; Company support, taken from `company.el', see `company-show-location'.
(when (< corfu--index 0)
(user-error "No candidate selected"))
@@ -79,19 +94,19 @@
;; BUG: company-location may throw errors if location is not found
(if-let ((fun (ignore-errors (plist-get corfu--extra :company-location)))
(loc (funcall fun cand)))
- (let ((buf (or (and (bufferp (car loc)) (car loc))
- (find-file-noselect (car loc) t))))
- (corfu-info--restore-on-next-command)
- (setq other-window-scroll-buffer buf)
- (with-selected-window (display-buffer buf t)
- (save-restriction
- (widen)
- (goto-char (point-min))
- (when-let (pos (cdr loc))
- (if (bufferp (car loc))
- (goto-char pos)
- (forward-line (1- pos))))
- (set-window-start nil (point)))))
+ (with-selected-window
+ (corfu-info--display-buffer
+ (or (and (bufferp (car loc)) (car loc))
+ (find-file-noselect (car loc) t))
+ (and arg (format "*corfu loc: %s*" cand)))
+ (save-restriction
+ (widen)
+ (goto-char (point-min))
+ (when-let (pos (cdr loc))
+ (if (bufferp (car loc))
+ (goto-char pos)
+ (forward-line (1- pos))))
+ (set-window-start nil (point))))
(user-error "No location available for `%s'" cand))))
;; Emacs 28: Do not show Corfu commands with M-X
diff --git a/extensions/corfu-popupinfo.el b/extensions/corfu-popupinfo.el
index 51ff88b..2567346 100644
--- a/extensions/corfu-popupinfo.el
+++ b/extensions/corfu-popupinfo.el
@@ -103,7 +103,7 @@ documentation is usually expensive."
:group 'corfu)
(defcustom corfu-popupinfo-direction '(right left vertical)
- "Preferred directionse for the popup in order."
+ "Preferred directions for the popup in order."
:type '(repeat
(choice
(const left)