company について前回晒してから、はや 1 年。この間に lsp を導入したり、ivy から consult へも変更したりしてるので、 再確認の機会になればと晒してみる。
主な変更は、 company-backends の設定を、対象モード側ではなく、 company のフックで統一したこと。だけだった。
環境は、 Debian の 5.10.140-1 Bullesye で、emacs は 27.1 。 org-mode でのメモ書きと python が主用途で変らず。
(leaf company :ensure t :require t
:url "https://github.com/company-mode/company-mode"
:doc "http://company-mode.github.io"
:blackout t
:hook ((text-mode-hook python-mode-hook emacs-lisp-mode-hook)
;; backends は ここで設定するのがよさそう
(plantuml-mode-hook . (lambda ()
(set (make-local-variable 'company-backends)
'(company-yasnippet company-dabbrev))))
(emacs-lisp-mode-hook . (lambda ()
(set (make-local-variable 'company-backends)
'(company-semantic company-files company-elisp company-dabbrev-code))))
(org-mode-hook . (lambda ()
(set (make-local-variable 'company-backends)
'(company-ispell company-dabbrev company-yasnippet company-files))))
(rst-mode-hook . (lambda ()
(set (make-local-variable 'company-backends)
'(company-ispell company-dabbrev company-yasnippet company-files))))
(python-mode-hook . (lambda ()
(set (make-local-variable 'company-backends)
'(company-jedi company-dabbrev-code company-ispell company-yasnippet))))
(html-mode-hook . (lambda ()
(set (make-local-variable 'company-backends)
'(company-capf company-web-html company-dabbrev-code company-yasnippet company-files company-ispell))))
(nxml-mode-hook . (lambda ()
(set (make-local-variable 'company-backends)
'(company-capf company-nxml company-dabbrev-code company-yasnippet company-files company-ispell))))
(css-mode-hook . (lambda ()
(set (make-local-variable 'company-backends)
'(company-capf company-css company-dabbrev-code company-yasnippet company-files company-ispell))))
;; company-gtags
)
:bind (
;; ("<tab>" . company-indent-or-complete-common)
(company-active-map ;; enabled during an active completion
("M-p")
("M-n")
("<tab>" . company-quit)
("C-n" . company-select-next)
("C-p" . company-select-previous)
("C-o" . company-other-backend)
;; lsp-mode で時々うまく機能しないことがある
("C-v" . company-next-page)
("M-v" . company-previous-page)
("C-s" . company-filter-candidates))
(company-search-map ;; incrementally searching the completion candidates
("<tab>" . company-quit)
("C-p" . company-select-previous)
("C-n" . company-select-next)
("C-v" . company-next-page)
("M-v" . company-previous-page))
)
:config
(setq auto-complete-mode nil) ;; required by jedi-2019
(setq company-idle-delay 0.1) ;; defailt 0.5
(setq company-show-numbers nil)
(setq company-selection-wrap-around t) ;; 候補の最後の次は先頭に戻る
(setq-default company-minimum-prefix-length 1) ;; original 3
;; (setq completion-ignore-case t) ;; c-source
(setq company-dabbrev-downcase nil)
;; (setq company-dabbrev-other-buffers nil) ;; 少しでも反応よくしたい
(setq company-dabbrev-other-buffers t) ;; If t, all buffers with major modes 間違えていた(221019)
(setq company-dabbrev-code-other-buffers 'code) ;; 間違えていた(221019)
(setq company-dabbrev-code-everywhere t) ;; include comments and strings.
;; (setq company-dabbrev-ignore-buffers "\\`\\'")
;; (setq company-eclim-auto-save nil) ;; for eclipse
;; (setq company-tooltip-align-annotations nil) ;; default nil
(setq company-tooltip-limit 8)
(setq company-require-match 'never) ;; If enabled, disallow non-matching input.
(defun company-quit nil
"Insert any selected completion and quit completing.
https://gist.github.com/rswgnu/85ca5c69bb26551f3f27500855893dbe#file-rsw-company-config-el"
(interactive)
(when (and company-selection-changed company--manual-action
(boundp 'company-tng--overlay)
company-tng--overlay)
(company--insert-candidate
(nth company-selection company-candidates)))
(company-cancel))
:defer-config
;; (leaf company-gtags :ensure nil :require t)
;; (setq company-gtags-insert-arguments t) ;; original t
;; for web
(leaf company-web :ensure t :disabled t
:url "https://github.com/osv/company-web"
:doc "Company-web support integration with emmet-mode and emmet-preview and
add some advices to make C-g and RET keys work properly."
:init
(leaf web-completion-data :ensure t :require t)
)
(leaf company-jedi :ensure t
:after (python-mode)
:init
(leaf python-environment :ensure t :require t
:doc "Required by: jedi-core"
)
(leaf jedi-core :ensure t :require t
;; :custom (
;; (jedi:environment-root . "~/.pyenv/versions/3.9.10/bin/python3")
;; )
:commands (jedi:setup)
;; :config
;; (setq jedi:server-command (list (executable-find "jediepcserver")))
) ;; ends jedi-core
:config
(setq jedi:tooltip-method nil) ;; pos-tip and/or popup, nil is minibuffer
(setq-local jedi:complete-on-dot t)
(setq-local jedi:use-shortcuts nil) ;; M-. and M-,
) ;; ends company-jedi. _____
;; start a specific backend.
;; (setq company-begin-backend 'company-ispell)
(leaf company-prescient :ensure t :require t :disabled nil
:url "https://github.com/raxod502/prescient.el"
:config
(company-prescient-mode t))
;; skip to the next matching backend in the backend list.
;; [2021-05-07] (setq company-other-backend '(company-eclim company-bbdd company-cmake company-files company-oddmuse))
;; lsp-ui-doc があるので、company-quickhelp を不要とする。
)
なんか、冗長になっているのではと思ってしまう。 もっと、シンプルにならないものかと思うが、ハードル高そう。 どこかに良きサンプルはないだろうか。
vim も、未だ使っている。が、その出番は少なくなってるように思う。 最近設定をいじった記憶がないと、思っていたが、 vim-tiny と neovim を aliase で使い分けるようしてた。
emacs を使う時は、少し構えているのかもしれない。
まあ、なんとなく使えているので、よしとしよう。
0 件のコメント:
コメントを投稿