diff --git a/modules/completion/corfu/README.org b/modules/completion/corfu/README.org index 64935940e..fe9b09ee0 100644 --- a/modules/completion/corfu/README.org +++ b/modules/completion/corfu/README.org @@ -71,25 +71,25 @@ By default, completion gets triggered after typing 2 non-space consecutive characters, or by means of the [[kbd:][C-SPC]] keybinding at any moment. While the popup is visible, the following relevant keys are available: -| Keybind | Description | -|----------+---------------------------------------------------------| -| [[kbd:][]] | Go to next candidate | -| [[kbd:][]] | Go to previous candidate | -| [[kbd:][C-n]] | Go to next candidate | -| [[kbd:][C-p]] | Go to previous candidate | -| [[kbd:][C-j]] | (evil) Go to next candidate | -| [[kbd:][C-k]] | (evil) Go to previous candidate | -| [[kbd:][C-]] | Go to next doc line | -| [[kbd:][C-]] | Go to previous doc line | -| [[kbd:][C-S-n]] | Go to next doc line | -| [[kbd:][C-S-p]] | Go to previous doc line | -| [[kbd:][C-S-j]] | (evil) Go to next doc line | -| [[kbd:][C-S-k]] | (evil) Go to previous doc line | -| [[kbd:][C-h]] | Toggle documentation (if available) | +| Keybind | Description | +|----------+------------------------------------------------------------------| +| [[kbd:][]] | Go to next candidate | +| [[kbd:][]] | Go to previous candidate | +| [[kbd:][C-n]] | Go to next candidate | +| [[kbd:][C-p]] | Go to previous candidate | +| [[kbd:][C-j]] | (evil) Go to next candidate | +| [[kbd:][C-k]] | (evil) Go to previous candidate | +| [[kbd:][C-]] | Go to next doc line | +| [[kbd:][C-]] | Go to previous doc line | +| [[kbd:][C-S-n]] | Go to next doc line | +| [[kbd:][C-S-p]] | Go to previous doc line | +| [[kbd:][C-S-j]] | (evil) Go to next doc line | +| [[kbd:][C-S-k]] | (evil) Go to previous doc line | +| [[kbd:][C-h]] | Toggle documentation (if available) | | [[kbd:][M-m]] | Export to minibuffer (if [[doom-module::completion vertico]]) | | [[kbd:][M-j]] | (evil) Export to minibuffer (if [[doom-module::completion vertico]]) | -| [[kbd:][RET]] | Insert candidate | -| [[kbd:][SPC]] | Quit autocompletion after a wildcard or pass-through | +| [[kbd:][RET]] | Insert candidate | +| [[kbd:][SPC]] | Quit autocompletion after a wildcard or pass-through | | [[kbd:][C-SPC]] | Complete (unless [[doom-module::completion corfu +tng]]) | | [[kbd:][C-SPC]] | (when completing) Insert separator DWIM (see below) | @@ -112,7 +112,10 @@ completing inserts a space as separator. This allows searching with space-separated terms; each piece will match individually and in any order, with smart casing. Pressing just [[kbd:][SPC]] acts as normal and quits completion, so that when typing sentences it doesn't try to complete the whole sentence instead of -just the word. +just the word. Pressing [[kdb:][C-SPC]] with point after a separator escapes it with a +backslash, including the space in the search term, and pressing it with an +already escaped separator before point deletes it. Thus, you can cycle back if +you accidentaly press more than needed. Additionally, for users of evil and regular corfu style, [[kdb:][C-SPC]] is smart regarding your state. In normal-like states, enter insert then start corfu; in diff --git a/modules/completion/corfu/autoload.el b/modules/completion/corfu/autoload.el index c34cb8232..618aae42d 100644 --- a/modules/completion/corfu/autoload.el +++ b/modules/completion/corfu/autoload.el @@ -8,3 +8,18 @@ (let ((completion-extra-properties corfu--extra) (completion-cycle-threshold completion-cycling)) (apply #'consult-completion-in-region completion-in-region--data))) + +;;;###autoload +(defun +corfu-smart-sep-toggle-escape () + "Insert `corfu-separator' or toggle escape if it's already there." + (interactive) + (cond ((and (char-equal (char-before) corfu-separator) + (char-equal (char-before (1- (point))) ?\\)) + (save-excursion (delete-char -2))) + ((char-equal (char-before) corfu-separator) + (save-excursion (backward-char 1) + (insert-char ?\\))) + (t + ;; Without this corfu quits immediately. + (setq this-command #'corfu-insert-separator) + (call-interactively #'corfu-insert-separator)))) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index 9743b6946..27caee357 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -57,26 +57,27 @@ (when (modulep! +icons) (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter)) - (map! :map corfu-map - [return] #'corfu-insert - "RET" #'corfu-insert) - (when (modulep! +orderless) + (let ((cmds-del (cmds! (and (modulep! +tng) + (> corfu--index -1) + (eq corfu-preview-current 'insert)) + #'corfu-reset))) (map! :map corfu-map - "C-SPC" #'corfu-insert-separator)) - (when (modulep! +tng) - (map! :map corfu-map - [tab] #'corfu-next - [backtab] #'corfu-previous - "TAB" #'corfu-next - "S-TAB" #'corfu-previous) - (let ((cmds-del (cmds! (and (modulep! +tng) - (> corfu--index -1) - (eq corfu-preview-current 'insert)) - #'corfu-reset))) - (map! :map corfu-map + [return] #'corfu-insert + "RET" #'corfu-insert + (:when (modulep! +orderless) + " " #'+corfu-smart-sep-toggle-escape) + (:when (modulep! +tng) + [tab] #'corfu-next + [backtab] #'corfu-previous + "TAB" #'corfu-next + "S-TAB" #'corfu-previous [backspace] cmds-del "DEL" cmds-del))) + (when (modulep! +orderless) + (after! orderless + (setq orderless-component-separator #'orderless-escapable-split-on-space))) + (after! vertico (map! :map corfu-map "M-m" #'+corfu-move-to-minibuffer diff --git a/modules/completion/vertico/config.el b/modules/completion/vertico/config.el index f92bd85a2..f1037741b 100644 --- a/modules/completion/vertico/config.el +++ b/modules/completion/vertico/config.el @@ -107,7 +107,7 @@ orderless." ;; find-file etc. completion-category-overrides '((file (styles +vertico-basic-remote orderless partial-completion))) orderless-style-dispatchers '(+vertico-orderless-dispatch) - orderless-component-separator "[ &]") + orderless-component-separator #'orderless-escapable-split-on-space) ;; ...otherwise find-file gets different highlighting than other commands (set-face-attribute 'completions-first-difference nil :inherit nil))