EOS: Completion Module

Table of Contents

(provide 'eos-completion)

EOS Completion Module

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-package dabbrev
  (setq dabbrev-case-fold-search nil))


(use-package hippie-exp
  ;; 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))

  (setq hippie-expand-try-functions-list
        '(;; Try to expand word "dynamically", searching the current buffer.
          ;; Try to expand word "dynamically", searching all other buffers.
          ;; Try to expand word "dynamically", searching the kill ring.
          ;; Try to complete text as a file name, as many characters as unique.
          ;; Try to complete text as a file name.
          ;; Try to expand word before point according to all abbrev tables.
          ;; Try to complete the current line to an entire line in the buffer.
          ;; Try to complete the current line to an entire line in the buffer.
          ;; Try to complete the current line to an entire line in a different
          ;; buffer.
          ;; Try to complete as an Emacs Lisp symbol, as many characters as
          ;; unique.
          ;; Try to complete word as an Emacs Lisp symbol.

Autocomplete with Company

I use company for a lot of things, so let's just enable it everywhere.

(use-package company
  :ensure t
  :diminish company-mode
  ;; stupid flyspell steals the binding I really want, `C-.`
  :bind (("C-c ." . company-complete)
         ("C-." . company-complete))
  (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))
  (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
  (setq company-dabbrev-ignore-case nil
        ;; don't downcase dabbrev suggestions
        company-dabbrev-downcase nil
        company-dabbrev-downcase nil))

(use-package company-dabbrev-code
  (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 ""
  (global-smart-tab-mode 1)
  (setq smart-tab-using-hippie-expand t)
  (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))

Author: Lee Hinman

Created: 2017-08-21 Mon 14:28