【发布时间】:2011-05-22 00:24:08
【问题描述】:
如果我使用Meta-/ 来自动完成ThisClass 之类的单词,emacs 会感到困惑并给我THISCLASS 或thisclass。更糟糕的是,如果我输入了ThisC,然后自动完成它会给出Thisclass,这非常令人沮丧。
有没有办法修改这种行为?
【问题讨论】:
标签: emacs autocomplete
如果我使用Meta-/ 来自动完成ThisClass 之类的单词,emacs 会感到困惑并给我THISCLASS 或thisclass。更糟糕的是,如果我输入了ThisC,然后自动完成它会给出Thisclass,这非常令人沮丧。
有没有办法修改这种行为?
【问题讨论】:
标签: emacs autocomplete
是的,使用hippie-expand:
(global-set-key (kbd "M-/") 'hippie-expand)
查看上面的wiki page,以及简洁的manual page for it。
hippie-expand 类似于dabbrev(M-/ 的默认绑定),但增加了更多功能,并在此过程中修复了您指出的驼峰式问题。
【讨论】:
虽然修改搜索行为是解决问题的一种方法,但另一种可能更好的方法是保持搜索行为不变,而是修改替换行为。
为此,请设置变量 dabbrev-case-replace 为零。
这种方式可能会更好,因为即使你输入的是不正确的大小写,它仍然会被正确匹配,然后完成到正确的大小写。
示例:假设您有变量“aVariable”。如果您更改搜索行为(将 dabbrev-case-fold-search 设置为 nil),则键入“av”将与您的变量不匹配。但是,如果您改为更改替换行为(将 dabbrev-case-replace 设置为 nil),则键入“av”将扩展为“aVariable”。
参考:http://www.gnu.org/software/emacs/manual/html_node/emacs/Dabbrev-Customization.html
【讨论】:
除了 hippie-expand,您还可以通过自定义以下变量来仅使用 dabbrev 实现您想要的行为:
dabbrev-case-fold-search is a variable defined in `dabbrev.el'.
Its value is nil
This variable is potentially risky when used as a file local variable.
Documentation:
Control whether dabbrev searches should ignore case.
A value of nil means case is significant.
A value of `case-fold-search' means case is significant
if `case-fold-search' is nil.
Any other non-nil version means case is not significant.
You can customize this variable.
【讨论】: