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

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

[elpa] externals/corfu 53ecf48 03/14: corfu-show-location/documentation:


From: Protesilaos Stavrou
Subject: [elpa] externals/corfu 53ecf48 03/14: corfu-show-location/documentation: Add error messages
Date: Sat, 17 Apr 2021 10:25:41 -0400 (EDT)

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

    corfu-show-location/documentation: Add error messages
---
 corfu.el | 52 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/corfu.el b/corfu.el
index 0e0a05b..5e3c1e1 100644
--- a/corfu.el
+++ b/corfu.el
@@ -459,43 +459,49 @@
   "Restore window configuration before next command."
   (let ((config (current-window-configuration))
         (other other-window-scroll-buffer)
-        (hide (make-symbol "corfu--hide-help")))
-    (fset hide (lambda ()
+        (restore (make-symbol "corfu--restore")))
+    (fset restore (lambda ()
                  (when (eq this-command #'corfu-abort)
                    (setq this-command #'ignore))
-                 (remove-hook 'pre-command-hook hide)
+                 (remove-hook 'pre-command-hook restore)
                  (setq other-window-scroll-buffer other)
                  (set-window-configuration config)))
-    (run-at-time 0 nil (lambda () (add-hook 'pre-command-hook hide)))))
+    (run-at-time 0 nil (lambda () (add-hook 'pre-command-hook restore)))))
 
 ;; Company support, taken from `company.el', see `company-show-doc-buffer'.
 (defun corfu-show-documentation ()
   "Show documentation of current candidate."
   (interactive)
-  (when-let* ((fun (and (>= corfu--index 0) (plist-get corfu--extra-properties 
:company-doc-buffer)))
-              (res (funcall fun (nth corfu--index corfu--candidates))))
-    (let ((buf (or (car-safe res) res)))
-      (corfu--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))))))
+  (when (< corfu--index 0)
+    (user-error "No candidate selected"))
+  (if-let* ((fun (plist-get corfu--extra-properties :company-doc-buffer))
+            (res (funcall fun (nth corfu--index corfu--candidates))))
+      (let ((buf (or (car-safe res) res)))
+        (corfu--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))))
+    (user-error "No documentation available")))
 
 ;; Company support, taken from `company.el', see `company-show-location'.
 (defun corfu-show-location ()
   "Show location of current candidate."
   (interactive)
-  (when-let* ((fun (and (>= corfu--index 0) (plist-get corfu--extra-properties 
:company-location)))
-              (loc (funcall fun (nth corfu--index corfu--candidates))))
-    (let ((buf (or (and (bufferp (car loc)) (car loc)) (find-file-noselect 
(car loc) t))))
-      (corfu--restore-on-next-command)
-      (with-selected-window (display-buffer buf t)
-        (setq other-window-scroll-buffer (current-buffer))
-        (save-restriction
-          (widen)
-          (if (bufferp (car loc))
-              (goto-char (cdr loc))
-            (goto-char (point-min))
-            (forward-line (1- (cdr loc))))
-          (set-window-start nil (point)))))))
+  (when (< corfu--index 0)
+    (user-error "No candidate selected"))
+  (if-let* ((fun (plist-get corfu--extra-properties :company-location))
+            (loc (funcall fun (nth corfu--index corfu--candidates))))
+      (let ((buf (or (and (bufferp (car loc)) (car loc)) (find-file-noselect 
(car loc) t))))
+        (corfu--restore-on-next-command)
+        (with-selected-window (display-buffer buf t)
+          (setq other-window-scroll-buffer (current-buffer))
+          (save-restriction
+            (widen)
+            (if (bufferp (car loc))
+                (goto-char (cdr loc))
+              (goto-char (point-min))
+              (forward-line (1- (cdr loc))))
+            (set-window-start nil (point)))))
+    (user-error "No candidate location available")))
 
 (defun corfu-complete ()
   "Try to complete current input."



reply via email to

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