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

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

[elpa] externals/corfu f98d239 02/29: Add support for cycling


From: Stefan Monnier
Subject: [elpa] externals/corfu f98d239 02/29: Add support for cycling
Date: Fri, 16 Apr 2021 18:44:12 -0400 (EDT)

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

    Add support for cycling
---
 README.org | 16 ++++++++++++++--
 corfu.el   | 14 ++++++++++++--
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/README.org b/README.org
index bcdff9e..6bd0139 100644
--- a/README.org
+++ b/README.org
@@ -53,10 +53,22 @@ completion. Here is an example configuration:
     :init
     (setq tab-always-indent 'complete))
 
-  ;; Enable corfu
+  ;; Configure corfu
   (use-package corfu
+    ;; Optionally use TAB for cycling, default is `corfu-complete'.
+    ;; :bind (:map corfu-map
+    ;;        ("TAB" . corfu-next)
+    ;;        ("S-TAB" . corfu-previous))
+
+    ;; Enable the overlay only for certain modes.
+    ;; For example it is not a useful UI for completions at point in the
+    ;; minibuffer.
     :hook ((prog-mode . corfu-mode)
-           (eshell-mode . corfu-mode)))
+           (eshell-mode . corfu-mode))
+
+    ;; Optionall enable cycling for `corfu-next' and `corfu-previous'.
+    ;; (setq corfu-cycle t)
+  )
 
   ;; Use the `orderless' completion style.
   ;; Enable `partial-completion' for files to allow path expansion.
diff --git a/corfu.el b/corfu.el
index 498b80c..31723f4 100644
--- a/corfu.el
+++ b/corfu.el
@@ -47,6 +47,10 @@
   "Maximal number of candidates to show."
   :type 'integer)
 
+(defcustom corfu-cycle nil
+  "Enable cycling for `corfu-next' and `corfu-previous'."
+  :type 'boolean)
+
 (defgroup corfu-faces nil
   "Faces used by Corfu."
   :group 'corfu
@@ -328,12 +332,18 @@
 (defun corfu-next ()
   "Go to next candidate."
   (interactive)
-  (corfu--goto (1+ corfu--index)))
+  (corfu--goto
+   (if (and corfu-cycle (= (1+ corfu--index) corfu--total))
+       -1
+     (1+ corfu--index))))
 
 (defun corfu-previous ()
   "Go to previous candidate."
   (interactive)
-  (corfu--goto (- corfu--index 1)))
+  (corfu--goto
+   (if (and corfu-cycle (< corfu--index 0))
+       (- corfu--total 1)
+     (- corfu--index 1))))
 
 (defun corfu-scroll-down ()
   "Go back by one page."



reply via email to

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