emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/corfu 2019688dfb: corfu-info-location/documentation: Pr


From: ELPA Syncer
Subject: [elpa] externals/corfu 2019688dfb: corfu-info-location/documentation: Prefix arg for persistent buffer and window.
Date: Sat, 13 May 2023 11:57:30 -0400 (EDT)

branch: externals/corfu
commit 2019688dfb59f73b54573a25bc5111367fa6e0a3
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    corfu-info-location/documentation: Prefix arg for persistent buffer and 
window.
    
    Fix #328
---
 CHANGELOG.org                 |  2 ++
 extensions/corfu-info.el      | 61 +++++++++++++++++++++++++++----------------
 extensions/corfu-popupinfo.el |  2 +-
 3 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 7760c3b69e..7f1ba79c50 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 9c4ab1e5f1..89d660e6ed 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 51ff88b11b..2567346cb3 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]