summaryrefslogtreecommitdiff
path: root/corfu.el
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2024-01-03 15:01:08 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2024-01-03 15:01:56 +0100
commitadfccae7be2dff68ecbded1b47d5029e4e86dc00 (patch)
tree96ad428ef99cd8a04f7029b7b3fbc15843188c7c /corfu.el
parent61a20a50369de2cae77d649269d3c047fbbc27ec (diff)
Store extra properties in completion-in-region--data
Diffstat (limited to 'corfu.el')
-rw-r--r--corfu.el51
1 files changed, 23 insertions, 28 deletions
diff --git a/corfu.el b/corfu.el
index dbdf6f1..941005b 100644
--- a/corfu.el
+++ b/corfu.el
@@ -295,9 +295,6 @@ See also the settings `corfu-auto-delay', `corfu-auto-prefix' and
(defvar corfu--preview-ov nil
"Current candidate overlay.")
-(defvar corfu--extra nil
- "Extra completion properties.")
-
(defvar corfu--change-group nil
"Undo change group.")
@@ -316,7 +313,6 @@ See also the settings `corfu-auto-delay', `corfu-auto-prefix' and
corfu--input
corfu--total
corfu--preview-ov
- corfu--extra
corfu--change-group
corfu--metadata))
"Initial Corfu state.")
@@ -684,7 +680,7 @@ FRAME is the existing frame."
(defun corfu--update (&optional interruptible)
"Update state, optionally INTERRUPTIBLE."
- (pcase-let* ((`(,beg ,end ,table ,pred) completion-in-region--data)
+ (pcase-let* ((`(,beg ,end ,table ,pred . ,_) completion-in-region--data)
(pt (- (point) beg))
(str (buffer-substring-no-properties beg end))
(input (cons str pt)))
@@ -863,7 +859,7 @@ Lookup STR in CANDS to restore text properties."
(defun corfu--done (str status cands)
"Exit completion and call the exit function with STR and STATUS.
Lookup STR in CANDS to restore text properties."
- (let ((completion-extra-properties corfu--extra))
+ (let ((completion-extra-properties (nth 4 completion-in-region--data)))
;; For successful completions, amalgamate undo operations,
;; such that completion can be undone in a single step.
(undo-amalgamate-change-group corfu--change-group)
@@ -875,8 +871,7 @@ Lookup STR in CANDS to restore text properties."
See `completion-in-region' for the arguments BEG, END, TABLE, PRED."
(setq beg (if (markerp beg) beg (copy-marker beg))
end (if (and (markerp end) (marker-insertion-type end)) end (copy-marker end t))
- completion-in-region--data (list beg end table pred)
- corfu--extra completion-extra-properties)
+ completion-in-region--data (list beg end table pred completion-extra-properties))
(completion-in-region-mode 1)
(activate-change-group (setq corfu--change-group (prepare-change-group)))
(setcdr (assq #'completion-in-region-mode minor-mode-overriding-map-alist) corfu-map)
@@ -1088,25 +1083,25 @@ A scroll bar is displayed from LO to LO+BAR."
(cl-defgeneric corfu--affixate (cands)
"Annotate CANDS with annotation function."
- (setq cands
- (if-let ((aff (or (corfu--metadata-get 'affixation-function)
- (plist-get corfu--extra :affixation-function))))
- (funcall aff cands)
- (if-let ((ann (or (corfu--metadata-get 'annotation-function)
- (plist-get corfu--extra :annotation-function))))
- (cl-loop for cand in cands collect
- (let ((suffix (or (funcall ann cand) "")))
- ;; The default completion UI adds the
- ;; `completions-annotations' face if no other faces are
- ;; present. We use a custom `corfu-annotations' face to
- ;; allow further styling which fits better for popups.
- (unless (text-property-not-all 0 (length suffix) 'face nil suffix)
- (setq suffix (propertize suffix 'face 'corfu-annotations)))
- (list cand "" suffix)))
- (cl-loop for cand in cands collect (list cand "" "")))))
- (let* ((dep (plist-get corfu--extra :company-deprecated))
- (completion-extra-properties corfu--extra)
+ (let* ((completion-extra-properties (nth 4 completion-in-region--data))
+ (dep (plist-get completion-extra-properties :company-deprecated))
(mf (run-hook-with-args-until-success 'corfu-margin-formatters corfu--metadata)))
+ (setq cands
+ (if-let ((aff (or (corfu--metadata-get 'affixation-function)
+ (plist-get completion-extra-properties :affixation-function))))
+ (funcall aff cands)
+ (if-let ((ann (or (corfu--metadata-get 'annotation-function)
+ (plist-get completion-extra-properties :annotation-function))))
+ (cl-loop for cand in cands collect
+ (let ((suff (or (funcall ann cand) "")))
+ ;; The default completion UI adds the
+ ;; `completions-annotations' face if no other faces are
+ ;; present. We use a custom `corfu-annotations' face to
+ ;; allow further styling which fits better for popups.
+ (unless (text-property-not-all 0 (length suff) 'face nil suff)
+ (setq suff (propertize suff 'face 'corfu-annotations)))
+ (list cand "" suff)))
+ (cl-loop for cand in cands collect (list cand "" "")))))
(cl-loop for x in cands for (c . _) = x do
(when mf
(setf (cadr x) (funcall mf c)))
@@ -1137,7 +1132,7 @@ A scroll bar is displayed from LO to LO+BAR."
(cl-defgeneric corfu--exhibit (&optional auto)
"Exhibit Corfu UI.
AUTO is non-nil when initializing auto completion."
- (pcase-let ((`(,beg ,end ,table ,pred) completion-in-region--data)
+ (pcase-let ((`(,beg ,end ,table ,pred . ,_) completion-in-region--data)
(`(,str . ,pt) (corfu--update 'interruptible)))
(cond
;; 1) Single exactly matching candidate and no further completion is possible.
@@ -1278,7 +1273,7 @@ first."
"Try to complete current input.
If a candidate is selected, insert it."
(interactive)
- (pcase-let ((`(,beg ,end ,table ,pred) completion-in-region--data))
+ (pcase-let ((`(,beg ,end ,table ,pred . ,_) completion-in-region--data))
(if (>= corfu--index 0)
;; Continue completion with selected candidate. Exit with status
;; 'finished if input is a valid match and no further completion is