Skip to content

Commit

Permalink
fix(corfu): move binds to :config default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LuigiPiucco committed Dec 11, 2023
1 parent 79e9fb3 commit 899cb2c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 74 deletions.
61 changes: 2 additions & 59 deletions modules/completion/corfu/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
"<remap> <completion-at-point>" #'+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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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-<up>" #'corfu-popupinfo-scroll-down
"C-<down>" #'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)))
9 changes: 8 additions & 1 deletion modules/config/default/+emacs-bindings.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
50 changes: 39 additions & 11 deletions modules/config/default/+evil-bindings.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -371,8 +399,10 @@
;;; <leader> 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)
Expand All @@ -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))
Expand Down
39 changes: 36 additions & 3 deletions modules/config/default/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
"<remap> <completion-at-point>" #'+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-<up>" #'corfu-popupinfo-scroll-down
"C-<down>" #'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.
Expand Down

0 comments on commit 899cb2c

Please sign in to comment.