2015-04-11 19:10:21 +00:00
|
|
|
;;; core-auto-completion.el --- Spacemacs Core 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
|
|
|
|
|
|
|
|
;; Company -------------------------------------------------------------------
|
|
|
|
|
|
|
|
(defmacro spacemacs|defvar-company-backends (mode)
|
|
|
|
"Define a MODE specific company backend variable with default backends.
|
|
|
|
The variable name format is company-backends-MODE."
|
|
|
|
`(defvar ,(intern (format "company-backends-%S" mode))
|
2015-04-30 03:54:30 +00:00
|
|
|
'((company-dabbrev-code company-gtags company-etags company-keywords)
|
2015-04-11 19:10:21 +00:00
|
|
|
company-files company-dabbrev)
|
|
|
|
,(format "Company backend list for %S" mode)))
|
|
|
|
|
|
|
|
(defmacro spacemacs|add-company-hook (mode)
|
|
|
|
"Enable company for the given MODE.
|
|
|
|
MODE must match the symbol passed in `spacemacs|defvar-company-backends'.
|
|
|
|
The initialization function is hooked to `MODE-hook'."
|
|
|
|
(let ((mode-hook (intern (format "%S-hook" mode)))
|
2015-06-17 07:06:19 +00:00
|
|
|
(func (intern (format "spacemacs//init-company-%S" mode)))
|
|
|
|
(backend-list (intern (format "company-backends-%S" mode))))
|
2015-04-11 19:10:21 +00:00
|
|
|
`(when (configuration-layer/package-usedp 'company)
|
|
|
|
(defun ,func ()
|
|
|
|
,(format "Initialize company for %S" mode)
|
2015-09-12 06:56:51 +00:00
|
|
|
(when auto-completion-enable-snippets-in-popup
|
|
|
|
(setq ,backend-list (mapcar 'spacemacs//show-snippets-in-company
|
|
|
|
,backend-list)))
|
2015-04-11 19:10:21 +00:00
|
|
|
(set (make-variable-buffer-local 'auto-completion-front-end)
|
|
|
|
'company)
|
|
|
|
(set (make-variable-buffer-local 'company-backends)
|
2015-06-17 07:06:19 +00:00
|
|
|
,backend-list))
|
2015-04-11 19:10:21 +00:00
|
|
|
(add-hook ',mode-hook ',func t)
|
|
|
|
(add-hook ',mode-hook 'company-mode t))))
|
|
|
|
|
|
|
|
(defmacro spacemacs|disable-company (mode)
|
|
|
|
"Disable company for the given MODE.
|
|
|
|
MODE parameter must match the parameter used in the call to
|
|
|
|
`spacemacs|add-company-hook'."
|
|
|
|
(let ((mode-hook (intern (format "%S-hook" mode)))
|
|
|
|
(func (intern (format "spacemacs//init-company-%S" mode))))
|
|
|
|
`(progn
|
|
|
|
(remove-hook ',mode-hook ',func)
|
|
|
|
(remove-hook ',mode-hook 'company-mode))))
|
|
|
|
|
2015-06-17 07:06:19 +00:00
|
|
|
(defun spacemacs//show-snippets-in-company (backend)
|
2015-07-01 05:30:55 +00:00
|
|
|
(if (or (not auto-completion-enable-snippets-in-popup)
|
2015-06-17 07:06:19 +00:00
|
|
|
(and (listp backend) (member 'company-yasnippet backend)))
|
|
|
|
backend
|
|
|
|
(append (if (consp backend) backend (list backend))
|
|
|
|
'(:with company-yasnippet))))
|
|
|
|
|
2015-04-11 19:10:21 +00:00
|
|
|
;; Auto-complete -------------------------------------------------------------
|
|
|
|
|
|
|
|
(defmacro spacemacs|enable-auto-complete (mode)
|
|
|
|
"Enable auto-complete for the given MODE.
|
|
|
|
The initialization function is hooked to `MODE-hook'."
|
|
|
|
(let ((mode-hook (intern (format "%S-hook" mode)))
|
|
|
|
(func (intern (format "spacemacs//init-auto-complete-%S" mode))))
|
|
|
|
`(when (configuration-layer/package-usedp 'auto-complete)
|
|
|
|
(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))))
|
|
|
|
|
|
|
|
(provide 'core-auto-completion)
|