This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/contrib/auto-completion
syl20bnr fdd4e944ef Reload dotfile and layer anywhere with SPC f e R
Replace `SPC m c c` and `C-c C-c` in the dotfile

Resolve #1210
2015-04-18 23:40:24 -04:00
..
config.el New layer auto-completion 2015-04-03 00:28:13 -04:00
funcs.el Refactor one more time the auto-completin macros 2015-04-09 00:03:51 -04:00
packages.el Reload dotfile and layer anywhere with SPC f e R 2015-04-18 23:40:24 -04:00
README.md Reload dotfile and layer anywhere with SPC f e R 2015-04-18 23:40:24 -04:00

Auto-Completion configuration layer for Spacemacs

Table of Contents

Description

This layer provides auto-completion to Spacemacs.

The following completion engines are supported:

Install

To use this configuration layer add it to your ~/.spacemacs

(setq-default dotspacemacs-configuration-layers '(auto-completion))

Company variables

To use tab instead of enter to complete your selection, dotspacemacs/init set auto-completion-use-tab-instead-of-enter to t, for example:

(setq-default dotspacemacs-configuration-layers
  '(auto-completion :variables
                    auto-completion-use-tab-instead-of-enter t))

To enable docstring tooltips set auto-completion-enable-company-help-tooltip to t

(setq-default dotspacemacs-configuration-layers
  '(auto-completion :variables
                    auto-completion-enable-company-help-tooltip t))

Configure

Enable company or auto-complete globally

By default Spacemacs enables auto-completion explicitly for each supported major-mode, it means that company and auto-complete are not enabled globally, it allows more flexibility to choose an auto-completion engine for a given mode.

You may want to enable company globally to get auto-completion everywhere even in the modes which are not configured by Spacemacs. To do so, you just have to add (global-company-mode) in the dotspacemacs/config function of your dotfile.

Note that if you want to enable auto-complete globally you will have to disable company first, see the next section to do so.

Replacing company by auto-complete

You can disable company by adding it to the dotspacemacs-excluded-packages variable, then you are free to enable auto-complete globally.

Add auto-completion in a layer

Here is an example to add company auto-completion to python buffer:

In config.el:

;; Define the buffer local company backend variable
(spacemacs|defvar-company-backends python-mode)

In packages.el:

;; Add the relevant packages to the layer
(setq python-packages
  '(...
    company
    company-anaconda
    ...))

;; Configure the packages
(when (configuration-layer/layer-usedp 'auto-completion)

  ;; Hook company to python-mode
  (defun python/post-init-company ()
    (spacemacs|add-company-hook python-mode))

  ;; Add the backend to the major-mode specific backend list
  (defun python/init-company-anaconda ()
    (use-package company-anaconda
      :if (configuration-layer/package-usedp 'company)
      :defer t
      :init (push 'company-anaconda company-backends-python-mode))))

Key Bindings

Company

Key Binding      |                 Description

---------------------|------------------------------------------------------------ C-j | go down in company dropdown menu C-k | go up in company dropdown menu C-/ | search in company dropdown C-M-/ | filter the company dropdown menu C-d | open minibuffer with documentation of thing at point in company dropdown

Auto-complete

Key Binding    |                 Description

-------------------|------------------------------------------------------------ C-j | select next candidate C-k | select previous candidate TAB | expand selection or select next candidate S-TAB | select previous candidate return | complete word, if word is already completed insert a carriage return