My current setup in emacs for PHP development has a variety of shortcomings. I often use a mixed mode of html and php. I want the mode to be able to recognize what context I'm in and format appropriately. I am especially interested in appropriate tabbing. This is the most important feature for me. Correct coloring would be nice, but if it messes up once in a while that's ok.
我目前用於PHP開發的emacs設置有各種缺點。我經常使用混合模式的HTML和PHP。我希望模式能夠識別我所處的上下文並進行適當的格式化。我對適當的標簽特別感興趣。這對我來說是最重要的功能。正確的着色會很好,但如果它偶爾弄亂一次就可以了。
I am currently using multi-web-mode and the default php-mode in Emacs 24.3 on MacOS X.
我目前在MacOS X上使用Emacs 24.3中的多網頁模式和默認的php模式。
One of the most frustrating problems is incorporating the heredoc syntax: echo <<< My current system doesn't recognize that this syntax needs to be NOT tabbed. I typically get warnings like this:
最令人沮喪的問題之一是結合了heredoc語法:echo <<
Indentation fails badly with mixed HTML/PHP in the HTML part in
plaín `php-mode'. To get indentation to work you must use an
Emacs library that supports 'multiple major modes' in a buffer.
Parts of the buffer will then be in `php-mode' and parts in for
example `html-mode'. Known such libraries are:
mumamo, mmm-mode, multi-mode
You have these available in your `load-path':
mumamo
I've already tried using mumao/nxhtml but that didn't give me the results I wanted. In some ways it was worse. I'd really appreciate any tips people have for getting a working php development environment setup for emacs.
我已經嘗試過使用mumao / nxhtml,但這並沒有給我我想要的結果。在某些方面,情況更糟。我非常感謝人們為emacs獲得有用的php開發環境設置的任何提示。
1 个解决方案
#1
12
I use web-mode (http://web-mode.org/) for mixed HTML/PHP files and php-mode for pure PHP files. The latest version of php-mode also recommended web-mode for mixed HTML/PHP files: https://github.com/ejmr/php-mode#avoid-html-template-compatibility.
我使用web模式(http://web-mode.org/)用於混合HTML / PHP文件和php模式用於純PHP文件。最新版本的php-mode還推薦了混合HTML / PHP文件的web模式:https://github.com/ejmr/php-mode#avoid-html-template-compatibility。
Unlike other modes like mmm-mode, mumamo or multi-web-mode that try to apply different behaviors to different parts of a buffer, web-mode is aware of all the available syntax/template that can be mixed with HTML. You can also use web-mode for mixed HTML files/templates such as Twig, Django, ERB... In fact I use web-mode for anything involve HTML.
與其他模式(如mmm-mode,mumamo或multi-web-mode)嘗試將不同的行為應用於緩沖區的不同部分不同,web-mode知道可以與HTML混合的所有可用語法/模板。您還可以將Web模式用於混合HTML文件/模板,例如Twig,Django,ERB ......實際上,我使用web模式處理涉及HTML的任何內容。
There is a catch for PHP template though: Other template systems has different file extension so it is easy to switch the mode automatically, but PHP templates usually use the same .php extension; so I have to make it switch by folders or sometimes manually invoke M-x web-mode. Here's my current configuration:
雖然有一個PHP模板的問題:其他模板系統有不同的文件擴展名,所以很容易自動切換模式,但PHP模板通常使用相同的.php擴展名;所以我必須按文件夾切換,或者有時手動調用M-x網絡模式。這是我目前的配置:
(defun add-auto-mode (mode &rest patterns)
(mapc (lambda (pattern)
(add-to-list 'auto-mode-alist (cons pattern mode)))
patterns))
(add-auto-mode 'web-mode
"*html*" "*twig*" "*tmpl*" "\\.erb" "\\.rhtml$" "\\.ejs$" "\\.hbs$"
"\\.ctp$" "\\.tpl$" "/\\(views\\|html\\|templates\\)/.*\\.php$")
BTW, try to separate your PHP files and templates and keep the mixed HTML/PHP file as simple as possible (refactor long PHP blocks into functions in a pure file). The code will be easier to read/follow.
順便說一下,嘗試將PHP文件和模板分開,並使混合的HTML / PHP文件盡可能簡單(將長PHP塊重構為純文件中的函數)。代碼將更易於閱讀/遵循。