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

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

[elpa] externals/corfu 134aa0f: Minor simplification


From: ELPA Syncer
Subject: [elpa] externals/corfu 134aa0f: Minor simplification
Date: Sat, 27 Nov 2021 08:57:13 -0500 (EST)

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

    Minor simplification
---
 corfu.el | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/corfu.el b/corfu.el
index 3a5047f..c6267a9 100644
--- a/corfu.el
+++ b/corfu.el
@@ -1152,23 +1152,26 @@ there hasn't been any input, then quit."
     (remove-hook 'post-command-hook #'corfu--auto-post-command 'local)
     (kill-local-variable 'completion-in-region-function))))
 
+(defun corfu--capf-wrapper (fun)
+  "Wrapper for `completion-at-point' FUN.
+Determines if the capf is applicable at the current position."
+  (pcase (funcall fun)
+    ((and res `(,beg ,end ,table . ,plist))
+     (and (integer-or-marker-p beg) ;; Valid capf result
+          (<= beg (point) end) ;; Sanity checking
+          ;; For non-exclusive capfs, check for valid completion.
+          (or (not (eq 'no (plist-get plist :exclusive)))
+              (let* ((str (buffer-substring-no-properties beg end))
+                     (pt (- (point) beg))
+                     (pred (plist-get plist :predicate))
+                     (md (completion-metadata (substring str 0 pt) table 
pred)))
+                (completion-try-completion str table pred pt md)))
+          (cons fun res)))))
+
 (defun corfu--capf-wrapper-advice (orig fun which)
   "Around advice for `completion--capf-wrapper'.
 The ORIG function takes the FUN and WHICH arguments."
-  (if corfu-mode ;; Only enable the advice when Corfu is active
-      (let ((res (funcall fun)))
-        (when (and (consp res) (integer-or-marker-p (car res)) ;; Valid capf 
result
-                   (pcase-let ((`(,beg ,end ,table . ,plist) res))
-                     (and (<= beg (point) end) ;; Sanity checking
-                          ;; For non-exclusive capfs, check for valid 
completion.
-                          (or (not (eq 'no (plist-get plist :exclusive)))
-                              (let* ((str (buffer-substring-no-properties beg 
end))
-                                     (pt (- (point) beg))
-                                     (pred (plist-get plist :predicate))
-                                     (md (completion-metadata (substring str 0 
pt) table pred)))
-                                (completion-try-completion str table pred pt 
md))))))
-          (cons fun res)))
-    (funcall orig fun which)))
+  (if corfu-mode (corfu--capf-wrapper fun) (funcall orig fun which)))
 
 ;;;###autoload
 (define-globalized-minor-mode corfu-global-mode corfu-mode corfu--on :group 
'corfu)



reply via email to

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