[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."
- [elpa] externals/corfu ce983a0 17/29: README: Expand configuration, (continued)
- [elpa] externals/corfu ce983a0 17/29: README: Expand configuration, Stefan Monnier, 2021/04/16
- [elpa] externals/corfu 2f9e154 18/29: Use completion--replace, Stefan Monnier, 2021/04/16
- [elpa] externals/corfu 219afe2 21/29: Deactivate fancy border if line spacing is used (Fix #1), Stefan Monnier, 2021/04/16
- [elpa] externals/corfu 5bacf55 20/29: Simplifications, Stefan Monnier, 2021/04/16
- [elpa] externals/corfu e6bfd22 26/29: Add corfu-min-width, Stefan Monnier, 2021/04/16
- [elpa] externals/corfu a61992d 29/29: Rework popup function, Stefan Monnier, 2021/04/16
- [elpa] externals/corfu a5fd9ad 22/29: Simplifications, Stefan Monnier, 2021/04/16
- [elpa] externals/corfu 145481d 19/29: corfu-insert: Call :exit-function, Stefan Monnier, 2021/04/16
- [elpa] externals/corfu 171b305 23/29: README: Add caveats section, Stefan Monnier, 2021/04/16
- [elpa] externals/corfu 30126c4 27/29: Add support for annotation and affixation function, Stefan Monnier, 2021/04/16
- [elpa] externals/corfu 74bc9d0 25/29: Add corfu-abort,
Stefan Monnier <=
- [elpa] externals/corfu ab68d45 24/29: Add support for help buffer (company-location, company-doc-buffer), Stefan Monnier, 2021/04/16
- [elpa] externals/corfu 408bc11 28/29: Add corfu--completion-in-region, Stefan Monnier, 2021/04/16