I'm going to be doing some PHP editing for my job this summer, and am looking for an effective Emacs setup for editing it. I'm already heavily invested in Emacs, so switching to another editor is not worthwhile.
今年夏天我将为我的工作做一些PHP编辑,我正在寻找一个有效的Emacs设置来编辑它。我已经在Emacs上投入了大量资金,因此切换到另一个编辑器是不值得的。
Right now, I have nXhtml-mode, which provides a PHP mode with syntax highlighting (there are at least three different ones in the wild) as well as MuMaMo for editing PHP embedded in HTML. I just started using Auto-Complete and Anything for programming and general Emacs stuff, respectively.
现在,我有nXhtml模式,它提供了一个带有语法高亮的PHP模式(在野外至少有三个不同的模式)以及用于编辑嵌入在HTML中的PHP的MuMaMo。我刚刚开始分别使用Auto-Complete和Anything进行编程和一般的Emacs。
What I'm really looking for is an effective way to get Emacs to really understand the project, beyond just highlighting. Etags looks like a good option, but it looks like the process for generating new tags is kind of arduous and manual (or at least not invisible). The nice thing about Etags is that they integrate well with Anything and Auto-Complete. Other potential options are gtags (though I'm hesitant to install non-elisp files, just for the complexity), vtags, or Semantic, which I've messed with before and seems complicated to set up, plus it doesn't look like it has support for PHP.
我真正想要的是让Emacs真正理解项目的有效方法,而不仅仅是突出显示。 Etags看起来是一个不错的选择,但看起来生成新标签的过程有点艰巨和手动(或至少不可见)。 Etags的优点在于它们可以与Anything和Auto-Complete很好地集成。其他可能的选项是gtags(虽然我对安装非elisp文件犹豫不决,只是为了复杂性),vtags或Semantic,我之前搞过这些并且设置起来很复杂,而且它看起来不像它支持PHP。
Another option is Imenu, but it only works for the current buffer, and I would like to be able to jump to function definitions in other files (preferably using Anything for completion of the name).
另一个选项是Imenu,但它只适用于当前缓冲区,我希望能够跳转到其他文件中的函数定义(最好使用Anything来完成名称)。
The projects I will be working on are not that big (about 30,000 lines total), so the overhead of Etags probably won't be that big of an issue, but I'd rather not use it if there is a better solution.
我将要开展的项目并不是那么大(总共约30,000行),因此Etags的开销可能不会是一个大问题,但如果有更好的解决方案,我宁愿不使用它。
So what is your preferred PHP editing system?
那么您首选的PHP编辑系统是什么?
3 个解决方案
#1
22
In addition to features you are already familiar with, I suggest you the followings.
除了您已熟悉的功能外,我建议您使用以下功能。
ETags
I do not use ETags, but there is a question already on SO How to programmatically create/update a TAGS file with emacs. No good answer was posted, though, but it may be a good entry point to get an idea.
我不使用ETags,但是已经存在一个问题如何使用emacs以编程方式创建/更新TAGS文件。尽管如此,没有公布好的答案,但这可能是一个很好的切入点。
Debugging
Flymake is a mode to get on the fly syntax checking. It has support for PHP as well. It hints at syntax errors immediately as you type. The Flymake version shipped with Emacs 23 contains PHP support. If you have previous version, check Sacha Chua's post on Emacs and PHP: On-the-fly syntax checking with Flymake.
Flymake是一种快速进行语法检查的模式。它也支持PHP。它会在您键入时立即提示语法错误。 Emacs 23附带的Flymake版本包含PHP支持。如果您有以前的版本,请查看Sacha Chua关于Emacs和PHP的帖子:使用Flymake进行动态语法检查。
Another useful package is Geben that allows you to debug your scripts interactively. For PHP, you can use XDebug. There is a detailed tutorial on how to do that, see Debug php in emacs with geben.
另一个有用的包是Geben,它允许您以交互方式调试脚本。对于PHP,您可以使用XDebug。有关如何执行此操作的详细教程,请参阅使用geben的emacs中的Debug php。
Documentation lookup
PHP Mode has a nice feature to lookup the function's definition in PHP's manual in your web browser (M-x php-search-documentation
or C-c C-f
). You can combine it with Emacs-W3M to get the relevant manual page without leaving Emacs.
PHP模式有一个很好的功能,可以在Web浏览器的PHP手册中查找函数的定义(M-x php-search-documentation或C-c C-f)。您可以将它与Emacs-W3M结合使用,无需离开Emacs即可获得相关的手册页。
#2
5
web-model.el (available on web-mode.org) handles pretty well php blocks embedded in an html document. This major mode will also highlight js and css parts.
web-model.el(可在web-mode.org上获得)处理嵌入在html文档中的相当好的php块。此主要模式还将突出显示js和css部分。
#3
3
As an alternative to ETags, consider GNU Global, aka "GTags". Global is a lot smarter about finding tags tables, and is fairly fast to update. Emacs-fu has a nice post about doing this on-the-fly.
作为ETag的替代品,请考虑GNU Global,即“GTags”。 Global对于查找标签表非常聪明,并且更新速度相当快。 Emacs-fu有一篇很好的文章,关于在飞行中做这件事。
BTW, if you're using the Windows port of GNU Global with a Windows Emacs build, use the DJGPP ("DOS") version. The MinGW ("Win32") build seems to have a problem with path names.
顺便说一句,如果你使用Windows Emacs版本的GNU Global的Windows端口,请使用DJGPP(“DOS”)版本。 MinGW(“Win32”)版本似乎有路径名的问题。
#1
22
In addition to features you are already familiar with, I suggest you the followings.
除了您已熟悉的功能外,我建议您使用以下功能。
ETags
I do not use ETags, but there is a question already on SO How to programmatically create/update a TAGS file with emacs. No good answer was posted, though, but it may be a good entry point to get an idea.
我不使用ETags,但是已经存在一个问题如何使用emacs以编程方式创建/更新TAGS文件。尽管如此,没有公布好的答案,但这可能是一个很好的切入点。
Debugging
Flymake is a mode to get on the fly syntax checking. It has support for PHP as well. It hints at syntax errors immediately as you type. The Flymake version shipped with Emacs 23 contains PHP support. If you have previous version, check Sacha Chua's post on Emacs and PHP: On-the-fly syntax checking with Flymake.
Flymake是一种快速进行语法检查的模式。它也支持PHP。它会在您键入时立即提示语法错误。 Emacs 23附带的Flymake版本包含PHP支持。如果您有以前的版本,请查看Sacha Chua关于Emacs和PHP的帖子:使用Flymake进行动态语法检查。
Another useful package is Geben that allows you to debug your scripts interactively. For PHP, you can use XDebug. There is a detailed tutorial on how to do that, see Debug php in emacs with geben.
另一个有用的包是Geben,它允许您以交互方式调试脚本。对于PHP,您可以使用XDebug。有关如何执行此操作的详细教程,请参阅使用geben的emacs中的Debug php。
Documentation lookup
PHP Mode has a nice feature to lookup the function's definition in PHP's manual in your web browser (M-x php-search-documentation
or C-c C-f
). You can combine it with Emacs-W3M to get the relevant manual page without leaving Emacs.
PHP模式有一个很好的功能,可以在Web浏览器的PHP手册中查找函数的定义(M-x php-search-documentation或C-c C-f)。您可以将它与Emacs-W3M结合使用,无需离开Emacs即可获得相关的手册页。
#2
5
web-model.el (available on web-mode.org) handles pretty well php blocks embedded in an html document. This major mode will also highlight js and css parts.
web-model.el(可在web-mode.org上获得)处理嵌入在html文档中的相当好的php块。此主要模式还将突出显示js和css部分。
#3
3
As an alternative to ETags, consider GNU Global, aka "GTags". Global is a lot smarter about finding tags tables, and is fairly fast to update. Emacs-fu has a nice post about doing this on-the-fly.
作为ETag的替代品,请考虑GNU Global,即“GTags”。 Global对于查找标签表非常聪明,并且更新速度相当快。 Emacs-fu有一篇很好的文章,关于在飞行中做这件事。
BTW, if you're using the Windows port of GNU Global with a Windows Emacs build, use the DJGPP ("DOS") version. The MinGW ("Win32") build seems to have a problem with path names.
顺便说一句,如果你使用Windows Emacs版本的GNU Global的Windows端口,请使用DJGPP(“DOS”)版本。 MinGW(“Win32”)版本似乎有路径名的问题。