[cvs] [Wiki] changed: Doc/Dev/Emacs
Gunnar Wrobel
p at rdus.de
Fri Apr 3 04:36:25 UTC 2009
wrobel Fri, 03 Apr 2009 00:36:25 -0400
Modified page: http://wiki.horde.org/Doc/Dev/Emacs
New Revision: 1.2
Change log: Added information on how to check your code with emacs
(syntax checks, code style)
@@ -36,4 +36,53 @@
++ Gunnar's configuration
Gunnar keeps
[http://github.com/wrobel/pardalys/blob/b712dd2a68f2339c1c7ef0472d83dd47f90bfe62/pardalys/modules/tool_emacs/files/ed_01_php_mode.el his Emacs configuration] in a [http://reductivelabs.com/trac/puppet puppet] [http://github.com/wrobel/pardalys/tree/master configuration repository] on [http://github.com github.com]. It contains lisp functionality to run code checks, style checking, the [http://code.google.com/p/geben-on-emacs/ GEBEN debugger] and [http://www.phpunit.de/ PHPUnit tests] from within
Emacs.
+
++ Emacs features
+
+++ Checking the code for syntax errors
+
+PHP allows you to check (lint) your code for syntax errors. It can be
helpful to bind that functionality to a key combination within emacs.
This way you can quickly check that your new code has no major flaws
in it.
+
+Emacs will present the result of the check in a compilation buffer
that allows you to directly jump to any problematic line.
+
+<code>
+
+(defun php-lint ()
+ "Performs a PHP lint check on the current file."
+ (interactive)
+ (let ((compilation-error-regexp-alist '(php))
+ (compilation-error-regexp-alist-alist ()))
+ (pushnew '(php "\\(syntax error.*\\) in \\(.*\\) on line
\\([0-9]+\\)$" 2 3 nil nil 1)
+ compilation-error-regexp-alist-alist)
+ (compile (concat "php -l -f \"" (buffer-file-name) "\""))))
+
+;; Check code
+(define-key php-mode-map (kbd "<f3> <f10>") 'php-lint)
+</code>
+
+The last line binds the function to the key combination <f3> <f10>
but it is of course completely up to you if you like that combination.
+
+++ Checking the code style for problems
+
+In order to adhere to the
[http://www.horde.org/horde/docs/?f=CODING_STANDARDS.html Horde coding
standards] you can run [http://pear.php.net/package/PHP_CodeSniffer
PHP_CodeSniffer] over your code to detect problems. It might not be
completely aware of the Horde code style but the PEAR code style is
close enough to it in order to be useful.
+
+Emacs will present the result of the check in a compilation buffer
that allows you to directly jump to any problematic line.
+
+<code>
+;; taken from
http://atomized.org/2008/10/php-lint-and-style-checking-from-emacs/
+(defun phpcs ()
+ "Performs a PHPCS lint-check on the current file."
+ (interactive)
+ (let ((compilation-error-regexp-alist '(php))
+ (compilation-error-regexp-alist-alist ()))
+ (pushnew '(php
"\"\\([^\"]+\\)\",\\([0-9]+\\),\\([0-9]+\\),\\(\\(warning\\)\\|\\(error\\)\\),\\(.*\\)" 1 2 3 (5 . 6)
4)
+ compilation-error-regexp-alist-alist)
+ (compile (concat "phpcs --standard=PEAR --report=csv \""
(buffer-file-name) "\""))))
+
+;; Check code style
+(define-key php-mode-map (kbd "<f3> <f11>") 'phpcs)
+</code>
+
+The last line binds the function to the key combination <f3> <f11>
but it is of course completely up to you if you like that combination.
+
More information about the cvs
mailing list