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

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

[elpa] externals/corfu 4ad4c1af4a 2/3: corfu-popupinfo: Improve corfu-po


From: ELPA Syncer
Subject: [elpa] externals/corfu 4ad4c1af4a 2/3: corfu-popupinfo: Improve corfu-popupinfo--get-location
Date: Sat, 19 Nov 2022 23:57:35 -0500 (EST)

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

    corfu-popupinfo: Improve corfu-popupinfo--get-location
---
 extensions/corfu-popupinfo.el | 60 ++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/extensions/corfu-popupinfo.el b/extensions/corfu-popupinfo.el
index 9bdfbdf0d1..57db7bad66 100644
--- a/extensions/corfu-popupinfo.el
+++ b/extensions/corfu-popupinfo.el
@@ -152,35 +152,37 @@ all values are in pixels relative to the origin. See
 
 (defun corfu-popupinfo--get-location (candidate)
   "Get source at location of CANDIDATE."
-  (save-excursion
-    (when-let* ((fun (plist-get corfu--extra :company-location))
-                ;; BUG: company-location may throw errors if location is not 
found
-                (loc (ignore-errors (funcall fun candidate)))
-                (buf (or (and (bufferp (car loc)) (car loc))
-                         (let ((inhibit-message t)
-                               (enable-dir-local-variables nil)
-                               (enable-local-variables :safe)
-                               (non-essential t)
-                               (delay-mode-hooks t))
-                           (find-file-noselect (car loc) t)))))
-      (unwind-protect
-          (with-current-buffer buf
-            (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)))
-                  ;; Support a little bit of scrolling.
-                  (forward-line (* 10 corfu-popupinfo-max-height))
-                  (when jit-lock-mode
-                    (jit-lock-fontify-now beg (point)))
-                  (let ((res (buffer-substring beg (point))))
-                    (and (not (string-blank-p res)) res))))))
-        (unless (bufferp (car loc))
-          (kill-buffer buf))))))
+  (let (cleanup)
+    (unwind-protect
+        (save-excursion
+          (when-let* ((fun (plist-get corfu--extra :company-location))
+                      ;; BUG: company-location may throw errors if location is 
not found
+                      (loc (ignore-errors (funcall fun candidate)))
+                      (buf (or (and (bufferp (car loc)) (car loc))
+                               (get-file-buffer (car loc))
+                               (let ((inhibit-message t)
+                                     (enable-dir-local-variables nil)
+                                     (enable-local-variables :safe)
+                                     (non-essential t)
+                                     (delay-mode-hooks t))
+                                 (setq cleanup (find-file-noselect (car loc) 
t))))))
+            (with-current-buffer buf
+              (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)))
+                    ;; Support a little bit of scrolling.
+                    (forward-line (* 10 corfu-popupinfo-max-height))
+                    (when jit-lock-mode
+                      (jit-lock-fontify-now beg (point)))
+                    (let ((res (buffer-substring beg (point))))
+                      (and (not (string-blank-p res)) res))))))))
+    (unless (bufferp (car loc))
+      (kill-buffer buf))))))
 
 (defun corfu-popupinfo--get-documentation (candidate)
   "Get the documentation for CANDIDATE."



reply via email to

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