(provide 'eos-completion)
This contains all the code that I use for things like completion. Right now this is mostly company-mode as well as other things I’ve been trying out…
Dabbrev is built in to Emacs, being something that is great at greedy completion.
;; 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\\)\\'"))
(setq dabbrev-case-fold-search nil))
(use-package hippie-exp
:init
;; force hippie-expand completions to be case-sensitive
(defadvice hippie-expand (around hippie-expand-case-fold activate)
"Try to do case-sensitive matching (not effective with all functions)."
(let ((case-fold-search nil))
ad-do-it))
:config
(setq hippie-expand-try-functions-list
'(;; Try to expand word "dynamically", searching the current buffer.
try-expand-dabbrev
;; Try to expand word "dynamically", searching all other buffers.
try-expand-dabbrev-all-buffers
;; Try to expand word "dynamically", searching the kill ring.
try-expand-dabbrev-from-kill
;; Try to complete text as a file name, as many characters as unique.
try-complete-file-name-partially
;; Try to complete text as a file name.
try-complete-file-name
;; Try to expand word before point according to all abbrev tables.
try-expand-all-abbrevs
;; Try to complete the current line to an entire line in the buffer.
try-expand-list
;; Try to complete the current line to an entire line in the buffer.
try-expand-line
;; Try to complete the current line to an entire line in a different
;; buffer.
try-expand-line-all-buffers
;; Try to complete as an Emacs Lisp symbol, as many characters as
;; unique.
try-complete-lisp-symbol-partially
;; Try to complete word as an Emacs Lisp symbol.
try-complete-lisp-symbol)))
I use company
for a lot of things, so let’s just enable it everywhere.
(use-package company
:ensure t
:disabled t
:diminish company-mode
;; stupid flyspell steals the binding I really want, `C-.`
:bind (("C-c ." . company-complete)
("C-." . company-complete))
:init
(add-hook 'after-init-hook #'global-company-mode)
(use-package company-quickhelp
:ensure t
:init (add-hook 'company-mode-hook #'company-quickhelp-mode)
:config (setq company-quickhelp-delay 2))
;; Set up statistics for company completions
(use-package company-statistics
:ensure t
:init (add-hook 'after-init-hook #'company-statistics-mode))
:config
(setq company-selection-wrap-around t
;; do or don't automatically start completion after <idle time>
company-idle-delay 1.0
;; at least 3 letters need to be there though
company-minimum-prefix-length 3
;; show completion numbers for hotkeys
company-show-numbers t
;; align annotations to the right
company-tooltip-align-annotations t
company-search-regexp-function #'company-search-flex-regexp)
(bind-keys :map company-active-map
("C-n" . company-select-next)
("C-p" . company-select-previous)
("C-d" . company-show-doc-buffer)
("C-l" . company-show-location)
("<tab>" . company-complete)))
There are also a few things to configure for Company’s dabbrev completion:
(use-package company-dabbrev
:disabled t
:init
(setq company-dabbrev-ignore-case nil
;; don't downcase dabbrev suggestions
company-dabbrev-downcase nil
company-dabbrev-downcase nil))
(use-package company-dabbrev-code
:disabled t
:init
(setq company-dabbrev-code-modes t
company-dabbrev-code-ignore-case nil))
Used smart-tab to complete everywhere except for ERC, shell and mu4e.
(use-package smart-tab
:ensure t
:defer t
:diminish ""
:init
(global-smart-tab-mode 1)
(setq smart-tab-using-hippie-expand t)
:config
(add-to-list 'smart-tab-disabled-major-modes 'mu4e-compose-mode)
(add-to-list 'smart-tab-disabled-major-modes 'erc-mode)
(add-to-list 'smart-tab-disabled-major-modes 'shell-mode))