summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2023-03-15 12:16:11 +0100
committerRicardo Wurmus <rekado@elephly.net>2023-03-15 12:16:11 +0100
commitc0acfe4054d86eba3f34a0e14662a763b22b8b8c (patch)
tree5f93e979741b72ceaf8478d6e0daf9104a941484
parent09ca1504912fad2a912985fa6a7c409c3b7cfcea (diff)
Replace company with corfu.
-rw-r--r--init.org48
1 files 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 <tab>") '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)