From c0acfe4054d86eba3f34a0e14662a763b22b8b8c Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Wed, 15 Mar 2023 12:16:11 +0100 Subject: Replace company with corfu. --- init.org | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/init.org b/init.org index 43f01f2..391d780 100644 --- a/init.org +++ b/init.org @@ -710,17 +710,30 @@ TODO: here’s the rest of my shell configuration: * Completion -Company mode provides automatic completion. I like to enable it in all programming modes. I don’t use the global company mode because that would enable it in =org-mode= where the pop-up looks terrible with =variable-pitch-mode= enabled. +Corfu provides automatic completion. I like to enable it in all modes, because it also integrates with dabbrev. #+BEGIN_SRC elisp -(add-hook 'prog-mode-hook 'company-mode) -#+END_SRC - -I like automatic completion, but it’s nice to also have a key to trigger completion. - -#+BEGIN_SRC elisp -(setq company-idle-delay 0.5) -(define-key company-mode-map (kbd "C-c ") 'company-complete) +(use-package corfu + :init + (global-corfu-mode) + :config + (defun corfu-enable-in-minibuffer () + "Enable Corfu in the minibuffer if `completion-at-point' is bound." + (when (where-is-internal #'completion-at-point (list (current-local-map))) + (setq-local corfu-echo-delay nil ;Disable automatic echo and popup + corfu-popupinfo-delay nil) + (corfu-mode 1))) + (add-hook 'minibuffer-setup-hook #'corfu-enable-in-minibuffer)) + +;; Use Dabbrev with Corfu! +(use-package dabbrev + ;; Swap M-/ and C-M-/ + :bind (("M-/" . dabbrev-completion) + ("C-M-/" . dabbrev-expand)) + ;; Other useful Dabbrev configurations. + :custom + (dabbrev-ignored-buffer-regexps + '("\\.\\(?:pdf\\|jpe?g\\|png\\)\\'"))) #+END_SRC Hippie expand is a neat way to expand text based on already existing text. Unfortunately, it collides with paredit (or smartparens) in that it may insert expansions that include unmatched parentheses. To avoid this I disable two types of expansions: @@ -1185,23 +1198,6 @@ This is even more stuff to be done after initialising packages. I still need to (setq fci-dash-pattern 0.3) (add-hook 'prog-mode-hook 'fci-mode) -;; This is a workaround to display the company-mode completion popup -;; when fci-mode is enabled. It was taken from here: -;; https://github.com/company-mode/company-mode/issues/180#issuecomment-55047120 -(defvar-local company-fci-mode-on-p nil) - -(defun company-turn-off-fci (&rest ignore) - (when (boundp 'fci-mode) - (setq company-fci-mode-on-p fci-mode) - (when fci-mode (fci-mode -1)))) - -(defun company-maybe-turn-on-fci (&rest ignore) - (when company-fci-mode-on-p (fci-mode 1))) - -(add-hook 'company-completion-started-hook 'company-turn-off-fci) -(add-hook 'company-completion-finished-hook 'company-maybe-turn-on-fci) -(add-hook 'company-completion-cancelled-hook 'company-maybe-turn-on-fci) - ;; expand region (global-set-key (kbd "M-@") 'er/expand-region) -- cgit v1.2.3