Restore reset of local company-backends and add with-yas
param
This commit is contained in:
parent
cb43a91a15
commit
0fa0409523
|
@ -50,7 +50,7 @@ which require an initialization must be listed explicitly in the list.")
|
||||||
:mode (("CMakeLists\\.txt\\'" . cmake-mode) ("\\.cmake\\'" . cmake-mode))
|
:mode (("CMakeLists\\.txt\\'" . cmake-mode) ("\\.cmake\\'" . cmake-mode))
|
||||||
:init
|
:init
|
||||||
(progn
|
(progn
|
||||||
(spacemacs|add-mode-company-backend cmake-mode company-cmake))))
|
(spacemacs|add-local-company-backend cmake-mode company-cmake))))
|
||||||
|
|
||||||
(defun c-c++/init-company ()
|
(defun c-c++/init-company ()
|
||||||
;; .clang_complete file loading
|
;; .clang_complete file loading
|
||||||
|
@ -102,8 +102,8 @@ which require an initialization must be listed explicitly in the list.")
|
||||||
:defer t
|
:defer t
|
||||||
:init
|
:init
|
||||||
(progn
|
(progn
|
||||||
(spacemacs|add-mode-company-backend c-mode company-c-headers)
|
(spacemacs|add-local-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))))
|
||||||
|
|
||||||
(defun c-c++/init-flycheck ()
|
(defun c-c++/init-flycheck ()
|
||||||
(add-to-hooks 'flycheck-mode '(c-mode-hook c++-mode-hook)))
|
(add-to-hooks 'flycheck-mode '(c-mode-hook c++-mode-hook)))
|
||||||
|
|
|
@ -60,4 +60,4 @@
|
||||||
"mi" 'omnisharp-fix-usings
|
"mi" 'omnisharp-fix-usings
|
||||||
"m=" 'omnisharp-code-format
|
"m=" 'omnisharp-code-format
|
||||||
|
|
||||||
(spacemacs|add-mode-company-backend csharp-mode company-omnisharp)))
|
(spacemacs|add-local-company-backend csharp-mode company-omnisharp)))
|
||||||
|
|
|
@ -147,4 +147,4 @@ not play nicely with autoloads"
|
||||||
:defer t
|
:defer t
|
||||||
:init
|
:init
|
||||||
(progn
|
(progn
|
||||||
(spacemacs|add-mode-company-backend ess-mode company-ess-backend))))
|
(spacemacs|add-local-company-backend ess-mode company-ess-backend))))
|
||||||
|
|
|
@ -45,4 +45,4 @@ which require an initialization must be listed explicitly in the list.")
|
||||||
:defer t
|
:defer t
|
||||||
:init
|
:init
|
||||||
(progn
|
(progn
|
||||||
(spacemacs|add-mode-company-backend go-mode company-go))))
|
(spacemacs|add-local-company-backend go-mode company-go))))
|
||||||
|
|
|
@ -232,7 +232,7 @@
|
||||||
:defer t
|
:defer t
|
||||||
:init
|
:init
|
||||||
(progn
|
(progn
|
||||||
(spacemacs|add-mode-company-backend haskell-mode company-ghc))))
|
(spacemacs|add-local-company-backend haskell-mode company-ghc))))
|
||||||
|
|
||||||
(defun haskell/init-hi2 ()
|
(defun haskell/init-hi2 ()
|
||||||
(use-package hi2
|
(use-package hi2
|
||||||
|
|
|
@ -169,4 +169,4 @@ which require an initialization must be listed explicitly in the list.")
|
||||||
:defer t
|
:defer t
|
||||||
:init
|
:init
|
||||||
(progn
|
(progn
|
||||||
(spacemacs|add-mode-company-backend tern-mode company-tern))))
|
(spacemacs|add-local-company-backend tern-mode company-tern))))
|
||||||
|
|
|
@ -60,7 +60,7 @@ which require an initialization must be listed explicitly in the list.")
|
||||||
:defer t
|
:defer t
|
||||||
:init
|
:init
|
||||||
(progn
|
(progn
|
||||||
(spacemacs|add-mode-company-backend python-mode company-anaconda))))
|
(spacemacs|add-local-company-backend python-mode company-anaconda))))
|
||||||
|
|
||||||
(defun python/init-cython-mode ()
|
(defun python/init-cython-mode ()
|
||||||
(use-package cython-mode
|
(use-package cython-mode
|
||||||
|
|
|
@ -32,8 +32,8 @@ which require an initialization must be listed explicitly in the list.")
|
||||||
:defer t
|
:defer t
|
||||||
:init
|
:init
|
||||||
(progn
|
(progn
|
||||||
(spacemacs|add-mode-company-backend c-mode company-ycmd)
|
(spacemacs|add-local-company-backend c-mode company-ycmd)
|
||||||
(spacemacs|add-mode-company-backend c++-mode company-ycmd))))
|
(spacemacs|add-local-company-backend c++-mode company-ycmd))))
|
||||||
|
|
||||||
(defun ycmd/init-flycheck-ycmd ()
|
(defun ycmd/init-flycheck-ycmd ()
|
||||||
(use-package flycheck-ycmd
|
(use-package flycheck-ycmd
|
||||||
|
|
|
@ -777,25 +777,26 @@ If ASCII si not provided then UNICODE is used instead."
|
||||||
(let ((comint-buffer-maximum-size 0))
|
(let ((comint-buffer-maximum-size 0))
|
||||||
(comint-truncate-buffer)))
|
(comint-truncate-buffer)))
|
||||||
|
|
||||||
(defmacro spacemacs|reset-local-company-backends (mode)
|
(defun spacemacs//make-company-backends-buffer-local ()
|
||||||
"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 ()
|
|
||||||
"Helper to make `company-backends' buffer local and reset it."
|
"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)
|
(defmacro spacemacs|add-local-company-backend (mode backend &optional with-yas)
|
||||||
"Add a new `company-mode' backend for a specific mode."
|
"Helper macro to add local `company-mode' BACKEND for MODE.
|
||||||
(let ((back-hook-sym (intern (format "spacemacs//add-%S-%S" mode backend)))
|
|
||||||
(mode-hook-sym (intern (format "%S-hook" mode))))
|
If WITH-YAS is non nil then the the `company-yasnippet' is consed to BACKEND."
|
||||||
; Need the company *layer* for the backend-with-yas function, not just the package. See #961
|
(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)
|
`(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
|
||||||
(add-hook ',mode-hook-sym 'spacemacs//make-company-backends-local)
|
'spacemacs//make-company-backends-buffer-local)
|
||||||
(defun ,back-hook-sym ()
|
(defun ,add-backend ()
|
||||||
(add-to-list 'company-backends (spacemacs/company-backend-with-yas ',backend)))
|
,(format "Add %S backend to %S" backend mode)
|
||||||
(add-hook ',mode-hook-sym ',back-hook-sym t))))
|
(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))))
|
||||||
|
|
Loading…
Reference in a new issue