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

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

[elpa] externals/corfu 74bc9d0 25/29: Add corfu-abort


From: Stefan Monnier
Subject: [elpa] externals/corfu 74bc9d0 25/29: Add corfu-abort
Date: Fri, 16 Apr 2021 18:44:18 -0400 (EDT)

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

    Add corfu-abort
---
 README.org | 17 +++++++++--------
 corfu.el   | 44 ++++++++++++++++++++++++++------------------
 2 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/README.org b/README.org
index 9e1e71d..7fb0225 100644
--- a/README.org
+++ b/README.org
@@ -112,15 +112,16 @@ minibuffer completion system. Vertico is the minibuffer 
counterpart of Corfu.
 This package is experimental and new. I am not yet claiming that this package
 works correctly. There are a few known caveats.
 
-+ Annotations are not supported (~annotation-function~, ~company-kind~)
-+ Company metadata is not shown (~company-docsig~)
-+ No caching, the completion table is called directly.
-+ The =:exit-function= handling is probably insufficient.
-+ The thin popup borders are only drawn if =line-spacing=nil=.
-+ The abort handling could be improved. Undo the completion input?
-+ The completion exit predicate is deliberatly ignored in order to
+- Annotations are not supported (~annotation-function~, ~company-kind~)
+- Company metadata is not shown (~company-docsig~)
+- No caching, the completion table is called directly.
+- The =:exit-function= handling is probably insufficient.
+- The overlay popup is brittle (Alternatives: Posframe, Postip?)
+- The thin popup borders are only drawn if =line-spacing=nil=.
+- The abort handling could be improved. Undo the completion input?
+- The completion exit predicate is deliberatly ignored in order to
   give the completion style full control.
-+ Completion is terminated if there are no matches. Add optional confirmation?
+- Completion is terminated if there are no matches. Add optional confirmation?
 
 * Contributions
 
diff --git a/corfu.el b/corfu.el
index e87141e..0507149 100644
--- a/corfu.el
+++ b/corfu.el
@@ -99,7 +99,8 @@
     (define-key map [remap next-line] #'corfu-next)
     (define-key map [remap previous-line] #'corfu-previous)
     (define-key map [remap completion-at-point] #'corfu-complete)
-    (define-key map "\e\e\e" #'keyboard-quit)
+    (define-key map "\e\e\e" #'corfu-abort)
+    (define-key map "\C-g" #'corfu-abort)
     (define-key map "\r" #'corfu-insert)
     (define-key map "\t" #'corfu-complete)
     (define-key map "\eg" #'corfu-show-location)
@@ -135,6 +136,19 @@
   "\\`\\(corfu-\\|scroll-other-window\\)"
   "Keep Corfu popup alive during commands matching this regexp.")
 
+(defconst corfu--state-vars
+  '(corfu--base
+    corfu--candidates
+    corfu--highlight
+    corfu--index
+    corfu--input
+    corfu--total
+    corfu--overlays
+    corfu--extra-properties
+    completion-show-inline-help
+    completion-auto-help)
+  "Buffer-local state variables used by Corfu.")
+
 (defun corfu--char-size ()
   "Return character size in pixels."
   (let ((lh (line-pixel-height)))
@@ -148,7 +162,7 @@
                               (make-string (- w (abs width)) ?1)))))
     (propertize
      " " 'display
-     `(image :data ,(format "P1\n %s %s\n%s" w h
+     `(image :data ,(format "P1\n%s %s\n%s" w h
                             (mapconcat (lambda (_) row) (number-sequence 1 h) 
""))
              :type pbm :scale 1 :ascent center
              :background ,(face-attribute color :foreground)
@@ -300,11 +314,15 @@
   "Delete overlays."
   (mapc #'delete-overlay corfu--overlays)
   (setq corfu--overlays nil)
-  (when (and (>= corfu--index 0)
-             (not (string-match-p corfu--keep-alive (prin1-to-string 
this-command)))
-             (not (eq this-command 'keyboard-quit)))
+  (unless (or (< corfu--index 0)
+              (string-match-p corfu--keep-alive (prin1-to-string 
this-command)))
     (corfu-insert)))
 
+(defun corfu-abort ()
+  "Abort Corfu completion."
+  (interactive)
+  (completion-in-region-mode -1))
+
 (defun corfu--update-display ()
   "Refresh Corfu UI."
   (pcase-let* ((`(,beg ,end ,table ,pred) completion-in-region--data)
@@ -329,8 +347,7 @@
                (string-match-p corfu--keep-alive (prin1-to-string 
this-command))
                (/= beg end))
            ;; Input after boundary is empty
-           (not (and (= (car bounds) (length str))
-                     (test-completion str table pred)))
+           (not (and (= (car bounds) (length str)) (test-completion str table 
pred)))
            ;; XXX Completion is terminated if there are no matches. Add 
optional confirmation?
            corfu--candidates
            ;; Single candidate
@@ -484,19 +501,10 @@
 
 (defun corfu--teardown ()
   "Teardown Corfu."
-  (mapc #'delete-overlay corfu--overlays)
   (remove-hook 'pre-command-hook #'corfu--pre-command-hook 'local)
   (remove-hook 'post-command-hook #'corfu--post-command-hook 'local)
-  (mapc #'kill-local-variable '(corfu--base
-                                corfu--candidates
-                                corfu--highlight
-                                corfu--index
-                                corfu--input
-                                corfu--total
-                                corfu--overlays
-                                corfu--extra-properties
-                                completion-show-inline-help
-                                completion-auto-help)))
+  (mapc #'delete-overlay corfu--overlays)
+  (mapc #'kill-local-variable corfu--state-vars))
 
 (defun corfu--mode-hook ()
   "Corfu mode hook."



reply via email to

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