diff --git a/modules/completion/corfu/README.org b/modules/completion/corfu/README.org index fe9b09ee0..ce7464cad 100644 --- a/modules/completion/corfu/README.org +++ b/modules/completion/corfu/README.org @@ -71,27 +71,26 @@ 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) | -| [[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:][C-SPC]] | Complete (unless [[doom-module::completion corfu +tng]]) | -| [[kbd:][C-SPC]] | (when completing) Insert separator DWIM (see below) | +| 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:][C-S-s]] | Export to minibuffer (if [[doom-module::completion vertico]]) | +| [[kbd:][RET]] | Insert candidate | +| [[kbd:][SPC]] | Quit autocompletion or pass-through after a wildcard | +| [[kbd:][C-SPC]] | Complete (unless [[doom-module::completion corfu +tng]]) | +| [[kbd:][C-SPC]] | (when completing) Insert separator DWIM (see below) | If you prefer a [[kbd:][TAB]]-centric completion style, enable the [[doom-module::completion corfu +tng]] flag so that, instead, you trigger completion with [[kbd:][TAB]], getting the diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index 27caee357..e9ecbf69c 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -33,17 +33,6 @@ tab-always-indent (if (modulep! +tng) 'complete tab-always-indent)) (add-to-list 'completion-category-overrides `(lsp-capf (styles ,@completion-styles))) - (map! :map corfu-mode-map - :e "C-M-i" #'completion-at-point - :i "C-SPC" #'completion-at-point - :n "C-SPC" (cmd! (call-interactively #'evil-insert-state) - (call-interactively #'completion-at-point)) - :v "C-SPC" (cmd! (call-interactively #'evil-change) - (call-interactively #'completion-at-point))) - (map! :unless (modulep! :editor evil) - :map corfu-mode-map - "C-M-i" #'completion-at-point) - (add-hook! 'minibuffer-setup-hook (defun +corfu-enable-in-minibuffer () "Enable Corfu in the minibuffer if `completion-at-point' is bound." @@ -57,32 +46,9 @@ (when (modulep! +icons) (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter)) - (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 - (:when (modulep! :editor evil) - "M-J" #'+corfu-move-to-minibuffer)))) + (setq orderless-component-separator #'orderless-escapable-split-on-space)))) (use-package! cape :defer t @@ -176,16 +142,4 @@ (use-package! corfu-popupinfo :hook ((corfu-mode . corfu-popupinfo-mode)) :config - (setq corfu-popupinfo-delay '(0.5 . 1.0)) - (map! :map corfu-map - "C-" #'corfu-popupinfo-scroll-down - "C-" #'corfu-popupinfo-scroll-up - "C-S-p" #'corfu-popupinfo-scroll-down - "C-S-n" #'corfu-popupinfo-scroll-up - "C-h" #'corfu-popupinfo-toggle) - (map! :when (modulep! :editor evil) - :map corfu-popupinfo-map - ;; Reversed because popupinfo assumes opposite of what feels intuitive - ;; with evil. - "C-S-k" #'corfu-popupinfo-scroll-down - "C-S-j" #'corfu-popupinfo-scroll-up)) + (setq corfu-popupinfo-delay '(0.5 . 1.0))) diff --git a/modules/config/default/+emacs-bindings.el b/modules/config/default/+emacs-bindings.el index 7aa4dfc41..ab29c5977 100644 --- a/modules/config/default/+emacs-bindings.el +++ b/modules/config/default/+emacs-bindings.el @@ -511,7 +511,7 @@ "C-x C-b" #'ibuffer "C-x K" #'doom/kill-this-buffer-in-all-windows - ;;; company-mode + ;;; completion (in-buffer) (:when (modulep! :completion company) "C-;" #'+company/complete (:after company @@ -537,6 +537,13 @@ "C-p" #'company-search-repeat-backward "C-s" (cmd! (company-search-abort) (company-filter-candidates)))) + (:when (modulep! :completion corfu) + :after corfu + (:map corfu-mode-map + "C-M-i" #'completion-at-point) + (:map corfu-popupinfo-map + "C-S-h" #'corfu-popupinfo-toggle)) + ;;; ein notebooks (:after ein:notebook-multilang :map ein:notebook-multilang-mode-map diff --git a/modules/config/default/+evil-bindings.el b/modules/config/default/+evil-bindings.el index c79c078f6..4bcc92b69 100644 --- a/modules/config/default/+evil-bindings.el +++ b/modules/config/default/+evil-bindings.el @@ -43,7 +43,10 @@ #'yas-expand (and (bound-and-true-p company-mode) (modulep! :completion company +tng)) - #'company-indent-or-complete-common) + #'company-indent-or-complete-common + (and (bound-and-true-p corfu-mode) + (modulep! :completion corfu +tng)) + #'completion-at-point) :m [tab] (cmds! (and (modulep! :editor snippets) (evil-visual-state-p) (or (eq evil-visual-selection 'line) @@ -127,7 +130,7 @@ ;; ;;; Module keybinds -;;; :completion +;;; :completion (in-buffer) (map! (:when (modulep! :completion company) :i "C-@" (cmds! (not (minibufferp)) #'company-complete-common) :i "C-SPC" (cmds! (not (minibufferp)) #'company-complete-common) @@ -156,7 +159,31 @@ "C-s" #'company-filter-candidates [escape] #'company-search-abort))) - (:when (modulep! :completion ivy) + (:when (modulep! :completion corfu) + (:after corfu + (:map corfu-mode-map + :e "C-M-i" #'completion-at-point + (:unless (modulep! :completion corfu +tng) + :i "C-SPC" #'completion-at-point + :n "C-SPC" (cmd! (call-interactively #'evil-insert-state) + (call-interactively #'completion-at-point)) + :v "C-SPC" (cmd! (call-interactively #'evil-change) + (call-interactively #'completion-at-point)))) + (:map corfu-map + "C-u" (cmd! (let ((corfu-cycle nil)) + (funcall-interactively #'corfu-next (- corfu-count)))) + "C-d" (cmd! (let ((corfu-cycle nil)) + (funcall-interactively #'corfu-next corfu-count))))) + (:after corfu-popupinfo + :map corfu-popupinfo-map + ;; Reversed because popupinfo assumes opposite of what feels intuitive + ;; with evil. + "C-S-k" #'corfu-popupinfo-scroll-down + "C-S-j" #'corfu-popupinfo-scroll-up + "C-h" #'corfu-popupinfo-toggle))) + +;;; :completion (separate) +(map! (:when (modulep! :completion ivy) (:after ivy :map ivy-minibuffer-map "C-SPC" #'ivy-call-and-recenter ; preview file @@ -169,7 +196,8 @@ [C-return] #'+ivy/git-grep-other-window-action)) (:when (modulep! :completion helm) - (:after helm :map helm-map + (:after helm + :map helm-map [remap next-line] #'helm-next-line [remap previous-line] #'helm-previous-line [left] #'left-char @@ -371,8 +399,10 @@ ;;; c --- code (:prefix-map ("c" . "code") (:when (and (modulep! :tools lsp) (not (modulep! :tools lsp +eglot))) - :desc "LSP Execute code action" "a" #'lsp-execute-code-action - :desc "LSP Organize imports" "o" #'lsp-organize-imports + :desc "LSP" "l" #'+default/lsp-command-map + :desc "LSP Execute code action" "a" #'lsp-execute-code-action + :desc "LSP Organize imports" "o" #'lsp-organize-imports + :desc "LSP Rename" "r" #'lsp-rename (:when (modulep! :completion ivy) :desc "Jump to symbol in current workspace" "j" #'lsp-ivy-workspace-symbol :desc "Jump to symbol in any workspace" "J" #'lsp-ivy-global-workspace-symbol) @@ -387,12 +417,10 @@ :desc "Incoming call hierarchy" "y" #'lsp-treemacs-call-hierarchy :desc "Outgoing call hierarchy" "Y" (cmd!! #'lsp-treemacs-call-hierarchy t) :desc "References tree" "R" (cmd!! #'lsp-treemacs-references t) - :desc "Symbols" "S" #'lsp-treemacs-symbols) - :desc "LSP" "l" #'+default/lsp-command-map - :desc "LSP Rename" "r" #'lsp-rename) + :desc "Symbols" "S" #'lsp-treemacs-symbols)) (:when (modulep! :tools lsp +eglot) - :desc "LSP Execute code action" "a" #'eglot-code-actions - :desc "LSP Rename" "r" #'eglot-rename + :desc "LSP Execute code action" "a" #'eglot-code-actions + :desc "LSP Rename" "r" #'eglot-rename :desc "LSP Find declaration" "j" #'eglot-find-declaration (:when (modulep! :completion vertico) :desc "Jump to symbol in current workspace" "j" #'consult-eglot-symbols)) diff --git a/modules/config/default/config.el b/modules/config/default/config.el index e67adf1e3..f1d1c71e7 100644 --- a/modules/config/default/config.el +++ b/modules/config/default/config.el @@ -48,8 +48,8 @@ (time-to-seconds)) collect (epg-sub-key-fingerprint subkey)))) user-mail-address)) - ;; And suppress prompts if epa-file-encrypt-to has a default value (without - ;; overwriting file-local values). + ;; And suppress prompts if epa-file-encrypt-to has a default value (without + ;; overwriting file-local values). (defadvice! +default--dont-prompt-for-keys-a (&rest _) :before #'epa-file-write-region (unless (local-variable-p 'epa-file-encrypt-to) @@ -170,7 +170,7 @@ (and (sp-in-code-p id action context) (save-excursion (goto-char (line-beginning-position)) - (looking-at-p "[ ]*#include[^<]+")))) + (looking-at-p "[ \t]*#include[^<]+")))) ;; ...and leave it to smartparens (sp-local-pair '(c++-mode objc-mode) @@ -458,6 +458,49 @@ Continues comments if executed from a commented line. Consults '(evil-ex-completion-map))) "C-s" command)) + (map! :when (modulep! :completion corfu) + :after corfu + (:map corfu-mode-map + :prefix "C-x" + "C-l" #'cape-line + "C-k" #'cape-keyword + "C-f" #'cape-file + "s" #'cape-dict + "C-s" #'yasnippet-capf + "C-o" #'completion-at-point + "C-n" #'cape-dabbrev + "C-p" #'cape-history) + (:map corfu-map + [return] #'corfu-insert + "RET" #'corfu-insert + "C-S-s" #'+corfu-move-to-minibuffer + "C-p" #'corfu-previous + "C-n" #'corfu-next + (:when (modulep! :completion corfu +orderless) + " " #'+corfu-smart-sep-toggle-escape) + (:when (modulep! :completion corfu +tng) + [tab] #'corfu-next + "TAB" #'corfu-next + [backtab] #'corfu-previous + "S-TAB" #'corfu-previous)) + (:after corfu-popupinfo + :map corfu-popupinfo-map + "C-" #'corfu-popupinfo-scroll-down + "C-" #'corfu-popupinfo-scroll-up + "C-S-p" #'corfu-popupinfo-scroll-down + "C-S-n" #'corfu-popupinfo-scroll-up + "C-S-u" (cmd! (funcall-interactively #'corfu-popupinfo-scroll-down corfu-popupinfo-min-height)) + "C-S-d" (cmd! (funcall-interactively #'corfu-popupinfo-scroll-up corfu-popupinfo-min-height)))) + + (when-let ((cmds-del (and (modulep! :completion corfu +tng) + (cmds! (and (> corfu--index -1) + (eq corfu-preview-current 'insert)) + #'corfu-reset)))) + (map! :after corfu + :map corfu-map + [backspace] cmds-del + "DEL" cmds-del)) + ;; Smarter C-a/C-e for both Emacs and Evil. C-a will jump to indentation. ;; Pressing it again will send you to the true bol. Same goes for C-e, except ;; it will ignore comments+trailing whitespace before jumping to eol.