Restore reset of local company-backends and add with-yas param

This commit is contained in:
syl20bnr 2015-03-30 00:46:32 -04:00
parent cb43a91a15
commit 0fa0409523
9 changed files with 31 additions and 30 deletions

View file

@ -50,7 +50,7 @@ which require an initialization must be listed explicitly in the list.")
:mode (("CMakeLists\\.txt\\'" . cmake-mode) ("\\.cmake\\'" . cmake-mode))
:init
(progn
(spacemacs|add-mode-company-backend cmake-mode company-cmake))))
(spacemacs|add-local-company-backend cmake-mode company-cmake))))
(defun c-c++/init-company ()
;; .clang_complete file loading
@ -102,8 +102,8 @@ which require an initialization must be listed explicitly in the list.")
:defer t
:init
(progn
(spacemacs|add-mode-company-backend c-mode company-c-headers)
(spacemacs|add-mode-company-backend c++-mode company-c-headers))))
(spacemacs|add-local-company-backend c-mode company-c-headers)
(spacemacs|add-local-company-backend c++-mode company-c-headers))))
(defun c-c++/init-flycheck ()
(add-to-hooks 'flycheck-mode '(c-mode-hook c++-mode-hook)))

View file

@ -60,4 +60,4 @@
"mi" 'omnisharp-fix-usings
"m=" 'omnisharp-code-format
(spacemacs|add-mode-company-backend csharp-mode company-omnisharp)))
(spacemacs|add-local-company-backend csharp-mode company-omnisharp)))

View file

@ -147,4 +147,4 @@ not play nicely with autoloads"
:defer t
:init
(progn
(spacemacs|add-mode-company-backend ess-mode company-ess-backend))))
(spacemacs|add-local-company-backend ess-mode company-ess-backend))))

View file

@ -45,4 +45,4 @@ which require an initialization must be listed explicitly in the list.")
:defer t
:init
(progn
(spacemacs|add-mode-company-backend go-mode company-go))))
(spacemacs|add-local-company-backend go-mode company-go))))

View file

@ -232,7 +232,7 @@
:defer t
:init
(progn
(spacemacs|add-mode-company-backend haskell-mode company-ghc))))
(spacemacs|add-local-company-backend haskell-mode company-ghc))))
(defun haskell/init-hi2 ()
(use-package hi2

View file

@ -169,4 +169,4 @@ which require an initialization must be listed explicitly in the list.")
:defer t
:init
(progn
(spacemacs|add-mode-company-backend tern-mode company-tern))))
(spacemacs|add-local-company-backend tern-mode company-tern))))

View file

@ -60,7 +60,7 @@ which require an initialization must be listed explicitly in the list.")
:defer t
:init
(progn
(spacemacs|add-mode-company-backend python-mode company-anaconda))))
(spacemacs|add-local-company-backend python-mode company-anaconda))))
(defun python/init-cython-mode ()
(use-package cython-mode

View file

@ -32,8 +32,8 @@ which require an initialization must be listed explicitly in the list.")
:defer t
:init
(progn
(spacemacs|add-mode-company-backend c-mode company-ycmd)
(spacemacs|add-mode-company-backend c++-mode company-ycmd))))
(spacemacs|add-local-company-backend c-mode company-ycmd)
(spacemacs|add-local-company-backend c++-mode company-ycmd))))
(defun ycmd/init-flycheck-ycmd ()
(use-package flycheck-ycmd

View file

@ -777,25 +777,26 @@ If ASCII si not provided then UNICODE is used instead."
(let ((comint-buffer-maximum-size 0))
(comint-truncate-buffer)))
(defmacro spacemacs|reset-local-company-backends (mode)
"Helper to make `company-backends' buffer local and reset it.
Use *only* if a default backend interferes with completion in a specific mode."
`(add-hook ',(intern (format "%S-hook" mode))
(lambda ()
(set (make-variable-buffer-local 'company-backends) nil))))
(defun spacemacs//make-company-backends-local ()
(defun spacemacs//make-company-backends-buffer-local ()
"Helper to make `company-backends' buffer local and reset it."
(make-variable-buffer-local 'company-backends))
(set (make-variable-buffer-local 'company-backends) nil))
(defmacro spacemacs|add-mode-company-backend (mode backend)
"Add a new `company-mode' backend for a specific mode."
(let ((back-hook-sym (intern (format "spacemacs//add-%S-%S" mode backend)))
(mode-hook-sym (intern (format "%S-hook" mode))))
; Need the company *layer* for the backend-with-yas function, not just the package. See #961
(defmacro spacemacs|add-local-company-backend (mode backend &optional with-yas)
"Helper macro to add local `company-mode' BACKEND for MODE.
If WITH-YAS is non nil then the the `company-yasnippet' is consed to BACKEND."
(let ((mode-hook (intern (format "%S-hook" mode)))
(add-backend (intern (format "spacemacs//%S-add-%S-backend"
mode backend)))
(backend2 (if with-yas
`(spacemacs/company-backend-with-yas ',backend)
`(quote ,backend))))
`(when (configuration-layer/layer-declaredp 'company-mode)
;; this hook will be added once even if this macro is used multiple times on the same mode.
(add-hook ',mode-hook-sym 'spacemacs//make-company-backends-local)
(defun ,back-hook-sym ()
(add-to-list 'company-backends (spacemacs/company-backend-with-yas ',backend)))
(add-hook ',mode-hook-sym ',back-hook-sym t))))
(add-hook ',mode-hook
'spacemacs//make-company-backends-buffer-local)
(defun ,add-backend ()
,(format "Add %S backend to %S" backend mode)
(add-to-list 'company-backends ,backend2))
;; important to append this function to the hook in order to
;; execute it at the end
(add-hook ',mode-hook ',add-backend t))))