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

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

[elpa] externals/corfu 6e9b8ef 10/14: Add corfu-completion-styles


From: Protesilaos Stavrou
Subject: [elpa] externals/corfu 6e9b8ef 10/14: Add corfu-completion-styles
Date: Sat, 17 Apr 2021 10:25:43 -0400 (EDT)

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

    Add corfu-completion-styles
    
    It may be useful to set a special completion style only for completion in
    region, since completion in region has special requirements regarding the
    handling of the completion prefix (See #5).
---
 corfu.el | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/corfu.el b/corfu.el
index cf45558..93f4aaf 100644
--- a/corfu.el
+++ b/corfu.el
@@ -55,6 +55,11 @@
   "Enable cycling for `corfu-next' and `corfu-previous'."
   :type 'boolean)
 
+;; XXX Maybe there should be a `completion-in-region-styles' variable in Emacs
+(defcustom corfu-completion-styles nil
+  "Completion styles to use for completion in region, defaults to 
`completion-styles'."
+  :type '(choice (const nil) (repeat symbol)))
+
 (defgroup corfu-faces nil
   "Faces used by Corfu."
   :group 'corfu
@@ -270,7 +275,8 @@ If `line-spacing/=nil' or in text-mode, the background 
color is used instead.")
               (lambda (pattern cands)
                 (setq hl (lambda (x) (orderless-highlight-matches pattern x)))
                 cands)))
-    (cons (apply #'completion-all-completions args) hl)))
+    (let ((completion-styles (or corfu-completion-styles completion-styles)))
+      (cons (apply #'completion-all-completions args) hl))))
 
 (defun corfu--sort-predicate (x y)
   "Sorting predicate which compares X and Y."
@@ -471,11 +477,11 @@ If `line-spacing/=nil' or in text-mode, the background 
color is used instead.")
         (other other-window-scroll-buffer)
         (restore (make-symbol "corfu--restore")))
     (fset restore (lambda ()
-                 (when (eq this-command #'corfu-abort)
-                   (setq this-command #'ignore))
-                 (remove-hook 'pre-command-hook restore)
-                 (setq other-window-scroll-buffer other)
-                 (set-window-configuration config)))
+                    (when (eq this-command #'corfu-abort)
+                      (setq this-command #'ignore))
+                    (remove-hook 'pre-command-hook restore)
+                    (setq other-window-scroll-buffer other)
+                    (set-window-configuration config)))
     (run-at-time 0 nil (lambda () (add-hook 'pre-command-hook restore)))))
 
 ;; Company support, taken from `company.el', see `company-show-doc-buffer'.
@@ -522,7 +528,8 @@ If `line-spacing/=nil' or in text-mode, the background 
color is used instead.")
                  (pt (max 0 (- (point) beg)))
                  (str (buffer-substring-no-properties beg end))
                  (metadata (completion-metadata (substring str 0 pt) table 
pred)))
-      (pcase (completion-try-completion str table pred pt metadata)
+      (pcase (let ((completion-styles (or corfu-completion-styles 
completion-styles)))
+               (completion-try-completion str table pred pt metadata))
         ((and `(,newstr . ,newpt) (guard (not (equal str newstr))))
          (completion--replace beg end newstr)
          (goto-char (+ beg newpt)))))))
@@ -564,7 +571,8 @@ If `line-spacing/=nil' or in text-mode, the background 
color is used instead.")
 
 (defun corfu--completion-in-region (&rest args)
   "Corfu completion in region function passing ARGS to 
`completion--in-region'."
-  (let ((completion-show-inline-help)
+  (let ((completion-styles (or corfu-completion-styles completion-styles))
+        (completion-show-inline-help)
         (completion-auto-help))
     (apply #'completion--in-region args)))
 



reply via email to

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