New layer auto-completion

Move company and auto-complete to a common layer.
They are not enabled globally anymore, each mode using them
must explicitly declare a hook.
Only one frontend is supported for a given mode, we have to
choose the best between the two.
Only one key binding to toggle auto-completion on `SPC t a` no
matter if it is company or auto-complete. The lighter in the
mode-line is Ⓐ for both frontends.
This commit is contained in:
syl20bnr 2015-04-03 00:28:13 -04:00
parent 2905190dc8
commit 769d54da02
22 changed files with 350 additions and 284 deletions

View File

@ -0,0 +1,77 @@
# Auto-Completion configuration layer for Spacemacs
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc/generate-toc again -->
**Table of Contents**
- [Colors contribution layer for Spacemacs](#colors-contribution-layer-for-spacemacs)
- [Description](#description)
- [Install](#install)
- [Enable rainbow-identifiers](#enable-rainbow-identifiers)
- [Enable Nyan cat](#enable-nyan-cat)
- [Key bindings](#key-bindings)
- [Rainbow Identifiers](#rainbow-identifiers)
- [Rainbow Mode](#rainbow-mode)
<!-- markdown-toc end -->
## Description
This layer provides auto-completion to Spacemacs.
The following front-ends are supported:
- [company][]
- [auto-complete][]
**Notes***
- `company` is the most supported and preferred front-end in Spacemacs.
- For a given language, Spacemacs supports one and only one front-end.
## Install
To use this contribution add it to your `~/.spacemacs`
```elisp
(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:
``` elisp
(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`
``` elisp
(setq-default dotspacemacs-configuration-layers
'(auto-completion :variables
auto-completion-enable-company-help-tooltip t))
```
## Key Bindings
### Company
No Debug | Description
---------------------|------------------------------------------------------------
<kbd>C-j</kbd> | go down in company dropdown menu
<kbd>C-k</kbd> | go up in company dropdown menu
<kbd>C-/</kbd> | search in company dropdown
<kbd>C-M-/</kbd> | filter the company dropdown menu
<kbd>C-d</kbd> | open minibuffer with documentation of thing at point in company dropdown
### Auto-complete
Key Binding | Description
-------------------|------------------------------------------------------------
<kbd>C-j</kbd> | select next candidate
<kbd>C-k</kbd> | select previous candidate
<kbd>TAB</kbd> | expand selection or select next candidate
<kbd>S-TAB</kbd> | select previous candidate
<kbd>return</kbd> | complete word, if word is already completed insert a carriage return

View File

@ -0,0 +1,32 @@
;;; config.el --- Auto-completion configuration File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
;; Company -------------------------------------------------------------------
;; not used for now
(defvar auto-completion-enable-company-yasnippet t
"If non nil enable yasnippet for all company backends.
Not used for now.")
(defvar auto-completion-enable-company-help-tooltip nil
"If non nil the docstring appears in a tooltip.")
(defvar auto-completion-use-tab-instead-of-enter nil
"If non nil use tab instead of enter for completion.")
(defvar company-mode-completion-cancel-keywords
'("do"
"then"
"begin"
"case")
"Keywords on which to cancel completion so that you can use RET
to complet without blocking common line endings.")

View File

@ -0,0 +1,89 @@
;;; funcs.el --- Auto-completion functions File
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(spacemacs|add-toggle auto-completion
:status
(if (eq 'company auto-completion-front-end)
company-mode
auto-complete-mode)
:on
(progn
(if (eq 'company auto-completion-front-end)
(company-mode)
(auto-complete-mode))
(message "Enabled %S." auto-completion-front-end))
:off
(progn
(if (eq 'company auto-completion-front-end)
(company-mode -1)
(auto-complete-mode -1))
(message "Disabled %S." auto-completion-front-end))
:documentation "Activate auto-completion."
:evil-leader "ta")
;; Company -------------------------------------------------------------------
(defmacro spacemacs|enable-company (mode &optional hook)
"Enable company for the given MODE.
MODE must match the symbol passed in `spacemacs|init-company-backends'.
By default the initialization function is hooked to `MODE-hook', it is
possible to explicitly define a hook with HOOK."
(when (configuration-layer/layer-declaredp 'auto-completion)
(let ((mode-hook (if hook hook
(intern (format "%S-hook" mode))))
(func (intern (format "spacemacs//init-company-%S" mode))))
`(progn
(defun ,func ()
,(format "Initialize company for %S" mode)
(set (make-variable-buffer-local 'auto-completion-front-end)
'company)
(set (make-variable-buffer-local 'company-backends)
,(intern (format "company-backends-%S" mode))))
(add-hook ',mode-hook ',func)
(add-hook ',mode-hook 'company-mode)))))
(defun spacemacs/company-backend-with-yas (backend)
"Return BACKEND with support for yasnippet candidates."
backend
;; ------------------
;; syl20bnr: For now adding company-snippet to some backend like anaconda
;; has weird side effects, I need to investigate a little more on this
;; ------------------
;; (if (and (configuration-layer/package-declaredp 'yasnippet)
;; auto-completion-enable-company-yasnippet
;; (not (eq 'company-semantic backend)))
;; (unless (and (listp backend) (member 'company-yasnippet backend))
;; (append (if (listp backend) backend (list backend))
;; (list :with 'company-yasnippet)))
;; ;; (cons backend '(company-yasnippet)))
;; backend)
)
;; Auto-complete -------------------------------------------------------------
(defmacro spacemacs|enable-auto-complete (mode &optional hook)
"Enable auto-complete for the given MODE.
By default the initialization function is hooked to `MODE-hook', it is
possible to explicitly define a hook with HOOK."
(when (configuration-layer/layer-declaredp 'auto-completion)
(let ((mode-hook (if hook hook
(intern (format "%S-hook" mode))))
(func (intern (format "spacemacs//init-auto-complete-%S" mode))))
`(progn
(defun ,func ()
,(format "Initialize auto-complete for %S" mode)
(set (make-variable-buffer-local 'auto-completion-front-end)
'auto-complete)
(set (make-variable-buffer-local 'company-backends)
,(intern (format "company-backends-%S" mode))))
(add-hook ',mode-hook ',func)
(add-hook ',mode-hook 'auto-complete-mode)))))

View File

@ -0,0 +1,122 @@
;;; packages.el --- Auto-completion Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defvar auto-completion-packages
'(
company
ac-ispell
auto-complete
))
;; company-quickhelp from MELPA is not compatible with 24.3 anymore
(unless (version< emacs-version "24.4")
(push 'company-quickhelp auto-completion-packages))
(defvar auto-completion-excluded-packages '()
"Packages that use auto-complete that are no longer necessary and might
conflict.")
(defun auto-completion/init-ac-ispell ()
(use-package ac-ispell
:defer t
:init
(progn
(setq ac-ispell-requires 4)
(eval-after-load "auto-complete"
'(ac-ispell-setup))
;; (add-hook 'markdown-mode-hook 'ac-ispell-ac-setup)
)))
(defun auto-completion/init-auto-complete ()
(use-package auto-complete
:defer t
:init
(setq ac-auto-start 0
ac-delay 0.2
ac-quick-help-delay 1.
ac-use-fuzzy t
ac-fuzzy-enable t
ac-comphist-file (concat spacemacs-cache-directory "ac-comphist.dat")
tab-always-indent 'complete ; use 'complete when auto-complete is disabled
ac-dwim t)
:config
(progn
(require 'auto-complete-config)
(ac-config-default)
(when (configuration-layer/package-declaredp 'yasnippet)
(push 'ac-source-yasnippet ac-sources))
(add-to-list 'completion-styles 'initials t)
(define-key ac-completing-map (kbd "C-j") 'ac-next)
(define-key ac-completing-map (kbd "C-k") 'ac-previous)
(define-key ac-completing-map (kbd "<S-tab>") 'ac-previous)
(spacemacs|diminish auto-complete-mode "" " A"))))
(defun auto-completion/init-company ()
(use-package company
:defer t
:init
(setq company-idle-delay 0.2
company-minimum-prefix-length 2
company-require-match nil
company-dabbrev-ignore-case nil
company-dabbrev-downcase nil
company-tooltip-flip-when-above t
company-frontends '(company-pseudo-tooltip-frontend)
company-clang-prefix-guesser 'company-mode/more-than-prefix-guesser)
:config
(progn
(spacemacs|diminish company-mode "" " A")
;; Set the completion key
(if auto-completion-use-tab-instead-of-enter
(progn
;; have tab stand in for enter
(define-key company-active-map (kbd "TAB") 'company-complete-selection)
(define-key company-active-map (kbd "<tab>") 'company-complete-selection)
(define-key company-active-map [tab] 'company-complete-selection)
;;disable enter
(define-key company-active-map [return] nil)
(define-key company-active-map (kbd "RET") nil))
;; Fix integration of company and yasnippet
(define-key company-active-map (kbd "TAB") nil)
(define-key company-active-map (kbd "<tab>") nil)
(define-key company-active-map [tab] nil))
;; key bindings
(define-key company-active-map (kbd "C-j") 'company-select-next)
(define-key company-active-map (kbd "C-k") 'company-select-previous)
(define-key company-active-map (kbd "C-/") 'company-search-candidates)
(define-key company-active-map (kbd "C-M-/") 'company-filter-candidates)
(define-key company-active-map (kbd "C-d") 'company-show-doc-buffer)
;; Nicer looking faces
(custom-set-faces
'(company-tooltip-common
((t (:inherit company-tooltip :weight bold :underline nil))))
'(company-tooltip-common-selection
((t (:inherit company-tooltip-selection :weight bold :underline nil)))))
;; Transformers
(defun spacemacs//company-transformer-cancel (candidates)
"Cancel completion if prefix is in the list
`company-mode-completion-cancel-keywords'"
(unless (and (member company-prefix company-mode-completion-cancel-keywords)
(not auto-completion-use-tab-instead-of-enter))
candidates))
(setq company-transformers '(spacemacs//company-transformer-cancel
company-sort-by-occurrence))
;; Backends
(setq company-backends
(mapcar 'spacemacs/company-backend-with-yas company-backends)))))
(defun auto-completion/init-company-quickhelp ()
(use-package company-quickhelp
:if (and auto-completion-enable-company-help-tooltip
(display-graphic-p))
:defer t
:init (add-hook 'company-mode-hook 'company-quickhelp-mode)))

View File

@ -1,49 +0,0 @@
# Company Mode
This contrib layer switches spacemacs to use company-mode for
autocompletion. It automatically uninstalls all auto-complete-mode
related packages when you include it.
## Clang Fanciness
In `funcs.el` there are some fancy improvements to `company-clang`.
It includes a hook to load a projects `.clang_complete` file, which is
just a text file with one clang flag per line, a format also used by
other text editor clang plugins.
Not only does this allow proper autocomplete on projects with extra
includes and flags, but I also hooked it into flycheck so that the
error messages don't complain about missing header files and skip the
actual problems.
Basically, Spacemacs now has better Clang/C++ than any other Emacs
config.
## Key Bindings
No Debug | Description
---------------------|------------------------------------------------------------
<kbd>C-j</kbd> | go down in company dropdown menu
<kbd>C-k</kbd> | go up in company dropdown menu
<kbd>C-/</kbd> | search in company dropdown
<kbd>C-M-/</kbd> | filter the company dropdown menu
<kbd>C-d</kbd> | open minibuffer with documentation of thing at point in company dropdown
## Settings
To use tab instead of enter to complete your selection,
`dotspacemacs/init` set `company-mode-use-tab-instead-of-enter` to
true, for example:
``` elisp
(defun dotspacemacs/init ()
"User initialization for Spacemacs. This function is called at the very
startup."
(setq company-mode-use-tab-instead-of-enter t)
)
```
## Maintainer
This contrib layer was written by and should be maintained by @trishume, everyone else is
welcome to contribute.

View File

@ -1,27 +0,0 @@
;;; config.el --- Company mode configuration File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
;; Variables
(defvar company-mode-enable-yas t
"If non nil enable yasnippet for all backends.")
(defvar company-mode-use-tab-instead-of-enter nil
"If non nil use tab instead of enter for completion in company-mode")
(defvar company-mode-completion-cancel-keywords
'("do"
"then"
"begin"
"case")
"Keywords on which to cancel completion so that you can use RET
to complet without blocking common line endings.")

View File

@ -1,29 +0,0 @@
;;; funcs.el --- Company Layer functions File
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defun spacemacs/company-backend-with-yas (backend)
"Return BACKEND with support for yasnippet candidates."
backend
;; ------------------
;; syl20bnr: For now adding company-snippet to some backend like anaconda
;; has weird side effects, I need to investigate a little more on this
;; ------------------
;; (if (and (configuration-layer/package-declaredp 'yasnippet)
;; company-mode-enable-yas
;; (not (eq 'company-semantic backend)))
;; (unless (and (listp backend) (member 'company-yasnippet backend))
;; (append (if (listp backend) backend (list backend))
;; (list :with 'company-yasnippet)))
;; ;; (cons backend '(company-yasnippet)))
;; backend)
)

View File

@ -1,72 +0,0 @@
(defvar company-mode-packages '(company))
;; company-quickhelp from MELPA is not compatible with 24.3 anymore
(unless (version< emacs-version "24.4")
(push 'company-quickhelp company-mode-packages))
(defvar company-mode-excluded-packages
'(auto-complete ac-ispell tern-auto-complete auto-complete-clang edts)
"Packages that use auto-complete that are no longer necessary and might
conflict.")
(defun company-mode/init-company ()
(use-package company
:defer t
:init
(progn
(setq company-idle-delay 0.5
company-minimum-prefix-length 2
company-require-match nil
company-dabbrev-ignore-case nil
company-dabbrev-downcase nil
company-tooltip-flip-when-above t
company-frontends '(company-pseudo-tooltip-frontend)
company-clang-prefix-guesser 'company-mode/more-than-prefix-guesser)
(add-hook 'prog-mode-hook 'global-company-mode))
:config
(progn
(spacemacs|diminish company-mode "" " C")
;; Set the completion key
(if company-mode-use-tab-instead-of-enter
(progn
;; have tab stand in for enter
(define-key company-active-map (kbd "TAB") 'company-complete-selection)
(define-key company-active-map (kbd "<tab>") 'company-complete-selection)
(define-key company-active-map [tab] 'company-complete-selection)
;;disable enter
(define-key company-active-map [return] nil)
(define-key company-active-map (kbd "RET") nil))
;; Fix integration of company and yasnippet
(define-key company-active-map (kbd "TAB") nil)
(define-key company-active-map (kbd "<tab>") nil)
(define-key company-active-map [tab] nil))
;; key bindings
(define-key company-active-map (kbd "C-j") 'company-select-next)
(define-key company-active-map (kbd "C-k") 'company-select-previous)
(define-key company-active-map (kbd "C-/") 'company-search-candidates)
(define-key company-active-map (kbd "C-M-/") 'company-filter-candidates)
(define-key company-active-map (kbd "C-d") 'company-show-doc-buffer)
;; Nicer looking faces
(custom-set-faces
'(company-tooltip-common
((t (:inherit company-tooltip :weight bold :underline nil))))
'(company-tooltip-common-selection
((t (:inherit company-tooltip-selection :weight bold :underline nil)))))
;; Transformers
(defun spacemacs//company-transformer-cancel (candidates)
"Cancel completion if prefix is in the list
`company-mode-completion-cancel-keywords'"
(unless (and (member company-prefix company-mode-completion-cancel-keywords)
(not company-mode-use-tab-instead-of-enter))
candidates))
(setq company-transformers '(spacemacs//company-transformer-cancel
company-sort-by-occurrence))
;; Backends
(setq company-backends
(mapcar 'spacemacs/company-backend-with-yas company-backends)))))
(defun company-mode/init-company-quickhelp ()
(use-package company-quickhelp
:if (display-graphic-p)
:defer t
:init (add-hook 'company-mode-hook 'company-quickhelp-mode)))

View File

@ -26,8 +26,16 @@ for demos in some programming languages.
- Support common refactoring with [semantic-refactor][]. See [this page][srefactor-demos]
for demonstration of refactoring features.
**This layer is not fully adapted for Spacemacs, it needs you, C/C++ experts, to
improve it and make it consistent with the Spacemacs experience.**
### Clang Fanciness
This layer adds some fancy improvements to `company-clang`.
It includes a hook to load a projects `.clang_complete` file, which is
just a text file with one clang flag per line, a format also used by
other text editor clang plugins.
Not only does this allow proper autocomplete on projects with extra
includes and flags, but there is also support for flycheck so that it
doesn't complain about missing header files.
## Key Bindings

View File

@ -102,7 +102,7 @@ which require an initialization must be listed explicitly in the list.")
(defun c-c++/init-company-c-headers ()
(use-package company-c-headers
:if (configuration-layer/layer-declaredp 'company-mode)
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init (push 'company-c-headers company-backends-c-c++)))

View File

@ -31,7 +31,7 @@ which require an initialization must be listed explicitly in the list.")
(defun ess/init-company-ess ()
(use-package company-ess
:if (configuration-layer/layer-declaredp 'company-mode)
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init (push '(company-ess-backend :with company-yasnippet)
company-backends-ess-mode)))

View File

@ -43,7 +43,7 @@ which require an initialization must be listed explicitly in the list.")
)
(defun go/init-company-go ()
(use-package company-go
:if (configuration-layer/layer-declaredp 'company-mode)
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init (push '(company-go :with company-yasnippet)
company-backends-go-mode)))

View File

@ -28,7 +28,7 @@
(defun haskell/init-company-ghc ()
(use-package company-ghc
:if (configuration-layer/layer-declaredp 'company-mode)
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init (push '(company-ghc :with company-yasnippet)
company-backends-haskell-mode)))

View File

@ -46,7 +46,7 @@ which require an initialization must be listed explicitly in the list.")
(defun javascript/init-company-tern ()
(use-package company-tern
:if (and (configuration-layer/package-declaredp 'tern)
(configuration-layer/layer-declaredp 'company-mode))
(configuration-layer/layer-declaredp 'auto-completion))
:defer t
:init (push '(company-tern :with company-yasnippet)
company-backends-js2-mode)))

View File

@ -22,11 +22,7 @@ which require an initialization must be listed explicitly in the list.")
(use-package markdown-mode
:mode ("\\.md" . markdown-mode)
:defer t
:init
(progn
(add-hook 'markdown-mode-hook 'smartparens-mode)
(when (configuration-layer/layer-declaredp 'company-mode)
(add-hook 'markdown-mode-hook (lambda () (company-mode -1)))))
:init (add-hook 'markdown-mode-hook 'smartparens-mode)
:config
;; Don't do terrible things with Github code blocks (```)
(when (fboundp 'sp-local-pair)

View File

@ -60,7 +60,7 @@ which require an initialization must be listed explicitly in the list.")
(defun python/init-company-anaconda ()
(use-package company-anaconda
:if (configuration-layer/layer-declaredp 'company-mode)
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init
;; we don't use the yasnippet backend here because it

View File

@ -13,7 +13,7 @@ which require an initialization must be listed explicitly in the list.")
(defun ycmd/init-company-ycmd ()
(use-package company-ycmd
:if (configuration-layer/layer-declaredp 'company-mode)
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init (push '(company-ycmd :with company-yasnippet)
company-backends-c-c++)))

View File

@ -122,7 +122,6 @@
- [Indent text object](#indent-text-object)
- [Region narrowing](#region-narrowing)
- [Line formatting](#line-formatting)
- [Auto-completion](#auto-completion)
- [Replacing text with iedit](#replacing-text-with-iedit)
- [iedit states key bindings](#iedit-states-key-bindings)
- [State transitions](#state-transitions)
@ -1923,18 +1922,6 @@ Line formatting commands start with `j`:
Used together these key bindings are very powerful to quickly reformat the code.
### Auto-completion
`Spacemacs` uses [auto-complete][] auto-completion engine.
Key Binding | Description
-------------------|------------------------------------------------------------
<kbd>C-j</kbd> | select next candidate
<kbd>C-k</kbd> | select previous candidate
<kbd>TAB</kbd> | expand selection or select next candidate
<kbd>S-TAB</kbd> | select previous candidate
<kbd>return</kbd> | complete word, if word is already completed insert a carriage return
### Replacing text with iedit
`Spacemacs` uses the powerful [iedit][] mode through [evil-iedit-state][] to

View File

@ -107,6 +107,7 @@ It runs `tabulated-list-revert-hook', then calls `tabulated-list-print'."
;; Edit
;; ---------------------------------------------------------------------------
(spacemacs|init-company-backends emacs-lisp-mode)
;; start scratch in text mode (usefull to get a faster Emacs load time
;; because it avoids autoloads of elisp modes)
(setq initial-major-mode 'text-mode)

View File

@ -28,6 +28,7 @@
spray
zoom-frm
;; hack to be able to wrap built-in emacs modes in an init function
emacs-builtin-emacs-lisp
emacs-builtin-process-menu
))
@ -174,5 +175,13 @@
(global-set-key (kbd "C-<wheel-up>") 'spacemacs/zoom-frm-in)
(global-set-key (kbd "C-<wheel-down>") 'spacemacs/zoom-frm-out))))
(defun spacemacs/init-emacs-builtin-emacs-lisp ()
(when (configuration-layer/layer-declaredp 'auto-completion)
;; from lower priority to higher
(push 'company-dabbrev company-backends-emacs-lisp-mode)
(push 'company-files company-backends-emacs-lisp-mode)
(push 'company-capf company-backends-emacs-lisp-mode)
(spacemacs|enable-company emacs-lisp-mode)))
(defun spacemacs/init-emacs-builtin-process-menu ()
(evilify process-menu-mode process-menu-mode-map))

View File

@ -828,25 +828,10 @@ If ASCII si not provided then UNICODE is used instead."
(let ((comint-buffer-maximum-size 0))
(comint-truncate-buffer)))
;; cannot move it to auto-completion layer since it is
;; required in config.el file of the layers
(defmacro spacemacs|init-company-backends (mode)
"Initialize a MODE specific company backend variable.
The variable name format is company-backends-MODE."
`(defvar ,(intern (format "company-backends-%S" mode)) nil
,(format "Company backend list for %S" mode)))
(defmacro spacemacs|enable-company (mode &optional hook)
"Enable company for the given MODE.
MODE must match the symbol passed in `spacemacs|init-company-backends'.
By default the initialization function is hooked to `MODE-hook', it is
possible to explicitly define a hook with HOOK."
(when (configuration-layer/layer-declaredp 'company-mode)
(let ((mode-hook (if hook hook
(intern (format "%S-hook" mode))))
(func (intern (format "spacemacs//init-company-%S" mode))))
`(progn
(defun ,func ()
,(format "Initialize company for %S" mode)
(set (make-variable-buffer-local 'company-backends)
,(intern (format "company-backends-%S" mode))))
(add-hook ',mode-hook ',func)))))

View File

@ -12,12 +12,9 @@
(defvar spacemacs-packages
'(
ac-ispell
ace-jump-mode
ace-window
aggressive-indent
auto-complete
auto-complete-clang
auto-dictionary
auto-highlight-symbol
base16-theme
@ -124,18 +121,6 @@ which require an initialization must be listed explicitly in the list.")
;; Initialization of packages
(defun spacemacs/init-ac-ispell ()
(use-package ac-ispell
:defer t
:init
(progn
(custom-set-variables
'(ac-ispell-requires 4))
(eval-after-load "auto-complete"
'(progn
(ac-ispell-setup)))
(add-hook 'markdown-mode-hook 'ac-ispell-ac-setup))))
(defun spacemacs/init-ace-jump-mode ()
(use-package ace-jump-mode
:defer t
@ -189,54 +174,6 @@ which require an initialization must be listed explicitly in the list.")
:config
(spacemacs|diminish aggressive-indent-mode "" " I")))
(defun spacemacs/init-auto-complete ()
(use-package auto-complete
:commands global-auto-complete-mode
:init
(add-to-hooks 'auto-complete-mode '(org-mode-hook
prog-mode-hook))
:config
(progn
(require 'auto-complete-config)
(ac-config-default)
(when (configuration-layer/package-declaredp 'yasnippet)
(push 'ac-source-yasnippet ac-sources))
(add-to-list 'completion-styles 'initials t)
(evil-leader/set-key "ta" 'auto-complete-mode)
(define-key ac-completing-map (kbd "C-j") 'ac-next)
(define-key ac-completing-map (kbd "C-k") 'ac-previous)
(define-key ac-completing-map (kbd "<S-tab>") 'ac-previous)
;; customization
(setq ac-auto-start 0
ac-delay 0.2
ac-quick-help-delay 1.
ac-use-fuzzy t
ac-fuzzy-enable t
ac-comphist-file (concat spacemacs-cache-directory "ac-comphist.dat")
tab-always-indent 'complete ; use 'complete when auto-complete is disabled
ac-dwim t)
(spacemacs|diminish auto-complete-mode "" " A"))))
(defun spacemacs/init-auto-complete-clang ()
(use-package auto-complete-clang
:defer t
:config
(progn
(setq ac-clang-flags
(mapcar (lambda (item)(concat "-I" item))
(split-string
"
/usr/include/c++/4.7
/usr/include/i386-linux-gnu/c++/4.7/.
/usr/include/c++/4.7/backward
/usr/lib/gcc/i686-linux-gnu/4.7/include
/usr/local/include
/usr/lib/gcc/i686-linux-gnu/4.7/include-fixed
/usr/include/i386-linux-gnu
/usr/include
"
))))))
(defun spacemacs/init-auto-dictionary ()
(use-package auto-dictionary
:disabled t