(use-package company
:ensure t
:config
(global-company-mode t)
(setq company-idle-delay 0)
(setq company-minimum-prefix-length 3)
(setq company-backends
'((company-files
company-keywords
company-capf
company-yasnippet
)
(company-abbrev company-dabbrev))))
(add-hook 'emacs-lisp-mode-hook (lambda ()
(add-to-list (make-local-variable 'company-backends)
'(company-elisp))))
Ctrl-h v company-backends
顯示目前的設定值
add-to-list
,原先的預設會設為第二順序跟第三順序,例如要載入檔案,會使用到 company-files 後端
M-x company diag
來看,例如剛剛的例子
(add-hook 'emacs-lisp-mode-hook (lambda ()
(set (make-local-variable 'company-backends)
'(company-elisp))))
Meta-n
跟 Meta-p
來移動游標,但這跟我們平常使用的習慣有點不同,我們可以來改一下設定(with-eval-after-load 'company
(define-key company-active-map (kbd "\C-n") #'company-select-next)
(define-key company-active-map (kbd "\C-p") #'company-select-previous)
(define-key company-active-map (kbd "M-n") nil)
(define-key company-active-map (kbd "M-p") nil))
Ctrl-n
跟 Ctrl-p
就像我們在主緩衝區使用的游標移動方式一樣(advice-add 'company-complete-common :before (lambda ()
(setq my-company-point (point))))
(advice-add 'company-complete-common :after (lambda ()
(when (equal my-company-point (point)) (yas-expand))))