使用EGLOT时如何显示Yasnippets的建议
我目前正在使用EGLOT(最小LSP客户端)的Emacs。但是,当我一起使用摘要库(例如,Yasnippet,Tempel)时,没有出现摘要的完成。 现在,我可以指定摘要名称并将其扩展在代码中。但是我希望emacs像键入摘要的名称一样工作,它显示了摘要的建议。
如果有一种方法在使用EGLOT时有一种建议,我将不胜感激。 我的Emacs配置如下所示。
- EGLOT
(use-package eglot
:ensure t
: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 '(go-mode . ("gopls")))
(add-to-list 'eglot-server-programs '(rustic-mode . ("rust-analyzer")))
(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 'go-mode-hook 'eglot-ensure)
(add-hook 'rustic-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))
- YASNIPPET
(use-package yasnippet
:ensure t
:hook
(prog-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))
:config
(yas-reload-all)
(setq yas-snippet-dirs
'("~/.emacs.d/snippets")))
公司(我现在不使用公司,转到Corfu / Cape。)
(use-package company
:ensure t
:diminish company-mode
:bind
(("C-M-i" . company-complete)
:map company-active-map
("M-n" . nil)
("M-p" . nil)
("C-h" . nil)
("C-n" . company-select-next)
("C-p" . company-select-previous)
("C-s" . company-filter-candidates)
("C-i" . company-complete-selection)
([tab] . company-complete-selection))
:hook
(after-init . global-company-mode)
:config
(setq company-backends '((company-capf :with company-yasnippet)))
(setq company-idle-delay 0
company-minimum-prefix-length 2
company-selection-wrap-around t
completion-ignore-case t
company-show-quick-access t))
- Corfu / Cape
(use-package corfu
:ensure t
:custom
(corfu-cycle t)
(corfu-auto t)
(corfu-quit-at-boundary nil)
(corfu-scroll-margin 5)
(corfu-echo-documentation t)
:bind
(:map corfu-map
("TAB" . corfu-insert)
([tab] . corfu-insert)
("C-n" . corfu-next)
("C-p" . corfu-previous))
:init
(global-corfu-mode))
;;;;; cape ;;;;;
(use-package cape
:ensure t
:config
(add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-yasnippet)))
- 等
I'm currently using Emacs with eglot (minimal lsp client). However, no completions for snippets have appeared when I use the snippet library (e.g., YASnippet, tempel) together.
Now I can specify the snippet name and expand it in the code. But I want emacs to work like when I type the snippet's name, it shows suggestions of the snippet.
I'll appreciate it if there's a way to show suggestions for snippets when using eglot.
My emacs configuration is shown below.
- eglot
(use-package eglot
:ensure t
: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 '(go-mode . ("gopls")))
(add-to-list 'eglot-server-programs '(rustic-mode . ("rust-analyzer")))
(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 'go-mode-hook 'eglot-ensure)
(add-hook 'rustic-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))
- YASnippet
(use-package yasnippet
:ensure t
:hook
(prog-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))
:config
(yas-reload-all)
(setq yas-snippet-dirs
'("~/.emacs.d/snippets")))
Company (I do not use company right now, transferred to corfu/cape instead.)
(use-package company
:ensure t
:diminish company-mode
:bind
(("C-M-i" . company-complete)
:map company-active-map
("M-n" . nil)
("M-p" . nil)
("C-h" . nil)
("C-n" . company-select-next)
("C-p" . company-select-previous)
("C-s" . company-filter-candidates)
("C-i" . company-complete-selection)
([tab] . company-complete-selection))
:hook
(after-init . global-company-mode)
:config
(setq company-backends '((company-capf :with company-yasnippet)))
(setq company-idle-delay 0
company-minimum-prefix-length 2
company-selection-wrap-around t
completion-ignore-case t
company-show-quick-access t))
- Corfu / Cape
(use-package corfu
:ensure t
:custom
(corfu-cycle t)
(corfu-auto t)
(corfu-quit-at-boundary nil)
(corfu-scroll-margin 5)
(corfu-echo-documentation t)
:bind
(:map corfu-map
("TAB" . corfu-insert)
([tab] . corfu-insert)
("C-n" . corfu-next)
("C-p" . corfu-previous))
:init
(global-corfu-mode))
;;;;; cape ;;;;;
(use-package cape
:ensure t
:config
(add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-yasnippet)))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于从Emacs-JP Slack获得了解决方案。我将重印它们,希望他们会为同样困扰的其他人提供帮助。
I finally got the solution from emacs-jp slack. I will reprint them in the hope that they will be of help to others who are similarly troubled.