diff --git a/modules/completion/corfu/README.org b/modules/completion/corfu/README.org index 252423567..9f0f7093c 100644 --- a/modules/completion/corfu/README.org +++ b/modules/completion/corfu/README.org @@ -148,7 +148,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. | Keybind | Description | |---------+-------------------------------------------------| diff --git a/modules/completion/corfu/autoload.el b/modules/completion/corfu/autoload.el index c34cb8232..5003d3b7c 100644 --- a/modules/completion/corfu/autoload.el +++ b/modules/completion/corfu/autoload.el @@ -8,3 +8,15 @@ (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 (call-interactively #'corfu-insert-separator)))) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index ae2e8409a..bfa302546 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -46,6 +46,7 @@ Possible values are: (add-to-list 'completion-category-overrides `(lsp-capf (styles ,@completion-styles))) (add-to-list 'corfu-auto-commands #'lispy-colon) (add-to-list 'corfu-continue-commands #'+corfu-move-to-minibuffer) + (add-to-list 'corfu-continue-commands #'+corfu-smart-sep-toggle-escape) (add-hook 'evil-insert-state-exit-hook #'corfu-quit)) (use-package! cape @@ -118,3 +119,15 @@ Possible values are: :init (after! corfu (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))) + +;; If vertico is not enabled, orderless will be installed but not configured. +;; That may break smart separator behavior, so we conditionally configure it. +(use-package! orderless + :when (and (not (modulep! :completion vertico)) + (modulep! +orderless)) + :config + (setq completion-styles '(orderless basic) + completion-category-defaults nil + completion-category-overrides '((file (styles orderless partial-completion))) + orderless-component-separator #'orderless-escapable-split-on-space) + (set-face-attribute 'completions-first-difference nil :inherit nil)) diff --git a/modules/completion/vertico/config.el b/modules/completion/vertico/config.el index 0d52ab950..3f2bf3f30 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)) diff --git a/modules/config/default/config.el b/modules/config/default/config.el index e3becc12a..21aa7268d 100644 --- a/modules/config/default/config.el +++ b/modules/config/default/config.el @@ -461,6 +461,7 @@ Continues comments if executed from a commented line. Consults (map! :when (modulep! :completion corfu) :after corfu (:map corfu-map + [remap corfu-insert-separator] #'+corfu-smart-sep-toggle-escape "C-S-s" #'+corfu-move-to-minibuffer "C-p" #'corfu-previous "C-n" #'corfu-next