疑问:怎么让emacs更好处理多文件协作的代码补全?

今天准备学习wordpress的源代码(我从安装程序学习起),使用emacs去解析代码时,发现emacs似乎并不能找到相关代码的定义:


如图,当我查找wp_install的函数定义时,emacs并没能给出相关的提示.
而在VSCODE之中
所以,我的疑问是,Emacs有没有对应的插件,可以直接解析已存在项目的代码,并且很方便的跳转到对应的部分?

难道已经可以解析不存在的php项目代码了?

在项目的主要目录下运行:

find . -name “*.php” -print | etags -

然后在 Emacs 中按下 M-. 即可。

1 个赞

推荐使用

1 个赞

楼主是想兼容所有语言,而不仅仅只是wordpress的php吗?这样的话似乎只有ctags或lsp了,如果只是一种语言,去package-list搜索一下也有不少解决办法

1 个赞

补充一个比现存解决方案更加简洁的方式:

使用 c-c p R 生成TAGS
方便的地方在于:Emacs可以根据内置的模式自动检测使用的语言,不再需要依靠后缀名进行判断.
这对于阅读PostgreSQL这类多语言协作项目,具有很大的优势.

不得不说,PostgreSQL是一个非常严谨的项目.

/*
 * Create a PostgreSQL data sub-directory
 *
 * The data directory itself, and most of its sub-directories, are created at
 * initdb time, but we do have some occasions when we create directories in
 * the backend (CREATE TABLESPACE, for example).  In those cases, we want to
 * make sure that those directories are created consistently.  Today, that means
 * making sure that the created directory has the correct permissions, which is
 * what pg_dir_create_mode tracks for us.
 *
 * Note that we also set the umask() based on what we understand the correct
 * permissions to be (see file_perm.c).
 *
 * For permissions other than the default, mkdir() can be used directly, but
 * be sure to consider carefully such cases -- a sub-directory with incorrect
 * permissions in a PostgreSQL data directory could cause backups and other
 * processes to fail.
 */
int
MakePGDirectory(const char *directoryName)
{
	return mkdir(directoryName, pg_dir_create_mode);
}

但是,Emacs也真是一个非常强大的Editor,在解析源代码的速度上,远远快于VSCODE(一个快捷键直接跳转到对应的定义)