Facing strange problem with auto-completion company-mode. I use the packages Company mode and Yasnippet. When I'm typing in a buffer, I get autocompletion suggestions from Company with Yasnipper.
But for some reason it stop showing any Yasnippet snippets with company suggestion. And taking much longer time to load than before!
Before my company suggestion was like this :
Here is my settings for company-mode
and yasnippet
:
(use-package company-box
:delight
:after company
:hook (company-mode . company-box-mode))
(use-package company
:defer 2
:commands company-mode
:hook (after-init . global-company-mode)
:custom
(company-dabbrev-ignore-case t)
(company-etags-ignore-case t)
(company-idle-delay 0.0)
(company-echo-delay 0)
(completion-ignore-case t)
(company-require-match nil)
(company-show-quick-access t)
(company-selection-wrap-around t)
(company-minimum-prefix-length 1)
(company-dabbrev-code-modes t)
:config
;; Add yasnippet support for all company backends
;; https://github.com/syl20bnr/spacemacs/pull/179
(defvar company-mode/enable-yas t "Enable yasnippet for all backends.")
(defun company-mode/backend-with-yas (backend)
(if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend)))
backend
(append (if (consp backend) backend (list backend))
'(:with company-yasnippet))))
(setq company-backends (mapcar #'company-mode/backend-with-yas company-backends))
(setq company-backends '((company-capf :with company-yasnippet)))
)
(use-package yasnippet
:delight yas-minor-mode " ¥"
:commands yas-reload-all
;; :hook ((prog-mode minibuffer-inactive-mode org-mode) . yas-minor-mode)
:bind
(("C-c y n" . yas-new-snippet)
("C-c y v" . yas-visit-snippet-file)
("C-c y i" . yas-insert-snippet))
:custom (yas-snippet-dirs '("~/.emacs.d/etc/yasnippet/snippets"))
:config
;; enalbe nested snippet expansion
(setq yas-triggers-in-field t)
(yas-global-mode)
)
(use-package yasnippet-snippets
:delight
:after yas
:custom (yasnippet-snippets-dirs '("~/.emacs.d/etc/yasnippet/snippets"))
:config (yasnippet-snippets-initialize))
Also I've try this solution but the result is still same!
Another thing which I'd like to say, that I configure a way working this with eglot
:
(use-package eglot
:config
(add-to-list 'eglot-server-programs '(c-mode . ("clangd")))
(add-to-list 'eglot-server-programs '(c++-mode . ("clangd")))
(add-to-list 'eglot-server-programs '(python-mode . ("pyls")))
(add-to-list 'eglot-server-programs '(LaTeX-mode . ("digestif")))
(add-hook 'c-mode-hook 'eglot-ensure)
(add-hook 'c++-mode-hook 'eglot-ensure)
(add-hook 'python-mode-hook 'eglot-ensure)
(add-hook 'LaTeX-mode-hook 'eglot-ensure)
;; format on save
(add-hook 'c-mode-hook '(lambda() (add-hook 'before-save-hook 'eglot-format-buffer nil t)))
(add-hook 'c++-mode-hook '(lambda() (add-hook 'before-save-hook 'eglot-format-buffer nil t)))
(add-hook 'python-mode-hook '(lambda() (add-hook 'before-save-hook 'eglot-format-buffer nil t)))
(define-key eglot-mode-map (kbd "C-c R") 'eglot-rename)
(define-key eglot-mode-map (kbd "C-c C-i") 'eglot-find-implementation))
(add-hook 'eglot-managed-mode-hook (lambda ()
(add-to-list 'company-backends
'(company-capf :with company-yasnippet))))
But it does work only with those mode which I add-hook
within eglot
.
So basically my question is, Is there a way to load Yasnippet with company globally?