我在 Emacs 中使用自动完成和 yasnippet,但我对它们的设置感到困惑。我将以下代码放入我的.emacs
:
(add-to-list 'load-path "~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(yas/global-mode 1)
(global-set-key (kbd "C-i") 'yas/expand)
(setq yas/also-auto-indent-first-line t)
(add-to-list 'load-path "~/.emacs.d/plugins/autocomplete/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/plugins/autocomplete/ac-dict")
(ac-config-default)
(setq ac-use-menu-map t)
(define-key ac-menu-map "\C-n" 'ac-next)
(define-key ac-menu-map "\C-p" 'ac-previous)
(defun ac-js-mode()
(setq ac-sources '(ac-source-yasnippet
ac-source-symbols
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-files-in-current-dir
)))
(add-hook 'js-mode-hook 'ac-js-mode)
我试图将 yasnippet 设置为自动完成弹出菜单中的第一个候选者。但是,如下例所示,这不适用于我当前的设置:当我输入单词时for
, formatItem
处于第一位置并且for
在第二。formatItem
只是当前缓冲区中的本地函数。
for_____________
|formatItem |
|for a|
|for s|
|force s|
|foreachv s|
----------------
所以我的问题是:如何使 yasnippet 成为自动完成中的第一个候选者?我的身上是否缺少了一些东西.emacs
config?
任何帮助表示赞赏。
ac-config-default
安装钩子来设置合理的默认值ac-sources
价值观。这些钩子(特别是ac-common-setup
)可能会干扰您的设置。
You can check this by looking at the actual value of ac-sources
(C-h vac-sources
) in a js-mode
buffer to see if it has been modified by comparison to your custom value.
如果是这种情况,我看到两种解决方案:
- 停止使用
ac-config-default
并指定所有autocomplete
设置,
- 建议放置有问题的钩子
ac-source-yasnippet
在。。。之初ac-sources
运行后。假设 ac-common-setup 确实是麻烦制造者,则如下所示:
(defadvice ac-common-setup (after give-yasnippet-highest-priority activate)
(setq ac-sources (delq 'ac-source-yasnippet ac-sources))
(add-to-list 'ac-sources 'ac-source-yasnippet))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)