From 899cb2c54944b9925f312ba1b0763f449f32f7ff Mon Sep 17 00:00:00 2001 From: Luigi Sartor Piucco Date: Mon, 11 Dec 2023 19:12:54 -0300 Subject: [PATCH] fix(corfu): move binds to `:config default` Bindings were moved to the `:config default` module and some keys were adjusted to match Company/other modules. Small formatting issues and some apparently inintended nestings were corrected as well. --- modules/completion/corfu/config.el | 61 +---------------------- modules/config/default/+emacs-bindings.el | 9 +++- modules/config/default/+evil-bindings.el | 50 +++++++++++++++---- modules/config/default/config.el | 39 +++++++++++++-- 4 files changed, 85 insertions(+), 74 deletions(-) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index dd37c3006..1c32a7c2b 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -37,17 +37,6 @@ major mode regardless of size.") 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! corfu-mode (defun +corfu-mode-unbinds () ;; In `corfu-mode', unbind C-SPC from `global-map', so Emacs keeps searching. @@ -67,32 +56,9 @@ major mode regardless of size.") (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 @@ -121,17 +87,6 @@ major mode regardless of size.") eshell-mode) (defun +corfu-add-cape-dabbrev-h () (add-hook 'completion-at-point-functions #'cape-dabbrev 20 t))))) - (when (modulep! +line) - ;; Set up `cape-line' options. - (defun +cape-line-buffers () - (cl-loop for buf in (buffer-list) - if (or (eq major-mode (buffer-local-value 'major-mode buf)) - (< (buffer-size buf) +corfu-buffer-scanning-size-limit)) - collect buf)) - (setq cape-line-buffer-function #'+cape-line-buffers) - (add-hook! (text-mode comint-mode minibuffer-setup) - (defun +corfu-add-cape-line-h () - (add-hook 'completion-at-point-functions #'cape-line 20 t)))) ;; Complete emojis :). (when (and (modulep! +emoji) (> emacs-major-version 28)) (add-hook! (prog-mode conf-mode) @@ -197,16 +152,4 @@ major mode regardless of size.") (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 a62541d4c..496a8abfe 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 f4a301488..58befa14f 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) @@ -165,7 +165,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) @@ -453,6 +453,39 @@ 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-map + [return] #'corfu-insert + "RET" #'corfu-insert + "C-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.