我该如何让Emacs自动补全C语言头文件中的单词?
#include <stdio.h>
int main(){
print//<-- this is where I want it to complete printf
有没有比Cedet更简单的方法?
#include <stdio.h>
int main(){
print//<-- this is where I want it to complete printf
有没有比Cedet更简单的方法?
首先为您想要自动完成的源文件和包含文件生成标签。如果之前没有使用过标签表,请参考我的博客文章获取有关使用标签的提示。
现在,如果您有一个包含stdio.h的TAGS表,那么可以使用命令 `complete-tag' 来自动补全“printf”。
也许将 `complete-tag' 绑定到一个快捷键上:
(global-set-key [f3] 'complete-tag)
你也可以尝试hippie-expand
,它有关于搜索补全信息的其他选项。我将M-/绑定到hippie-expand
,然后修改了hippie-expand-try-functions-list
中元素的顺序如下:
(global-set-key (kbd "M-/") 'hippie-expand)
(setq hippie-expand-try-functions-list '(try-expand-dabbrev try-expand-dabbrev-all-buffers try-expand-dabbrev-from-kill try-complete-file-name-partially try-complete-file-name try-expand-all-abbrevs try-expand-list try-expand-line try-complete-lisp-symbol-partially try-complete-lisp-symbol))
这使得hippie-expand
一开始的表现就像普通的M- /,但是重复按下会产生更多可能的扩展。
你可能想尝试使用M-/(dabbrev-expand)。该命令尝试使用当前缓冲区以及相同模式下其他缓冲区的内容来自动完成光标前即将输入的标识符。如果第一个提供的完成选项不是你想要的,只需继续键入 M-/ 即可。如果你习惯于保持一个单一的emacs会话连续打开(如果你还没有这样做,真的应该学会),并且有当前项目中的几个文件处于打开状态,那么你很可能能够为任何特定前缀找到你想要的扩展。
所以,回答你最初的问题,如果你在正在编辑的缓冲区中的任何地方使用了printf,或者它出现在你在emacs中打开的任何其他 .c 或 .h 文件中,M-/将会找到你在寻找的printf完成选项。