[cvs] [Wiki] changed: Doc/Dev/Emacs

Gunnar Wrobel p at rdus.de
Tue Sep 22 11:18:45 UTC 2009


wrobel  Tue, 22 Sep 2009 07:18:45 -0400

Modified page: http://wiki.horde.org/Doc/Dev/Emacs
New Revision:  1.3
Change log:  Update for the CodeSniffer 1.2.0

@@ -67,8 +67,10 @@

  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.
+
++++ CodeSniffer < 1.2.0

  <code>
  ;; taken from  
http://atomized.org/2008/10/php-lint-and-style-checking-from-emacs/
  (defun phpcs ()
@@ -78,8 +80,41 @@
          (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.
+
++++ CodeSniffer >= 1.2.0
+
+The newer code sniffer version can directly output an emacs  
compatible format. You have two options of using the output for  
compilation within emacs.
+
+++++ Binding the compile command for you PHP mode
+
+<code>
+;;taken from  
http://pear.php.net/manual/en/package.php.php-codesniffer.reporting.php
+(defun my-php-hook-function ()
+  (set (make-local-variable 'compile-command)
+    (format "phpcs --report=emacs --standard=PEAR %s"
+            (buffer-file-name))))
+(add-hook 'php-mode-hook 'my-php-hook-function)
+</code>
+
+The style check will be run once you execute the "M-x compile" command.
+
+++++ Binding the style check to a command
+
+<code>
+(defun phpcs ()
+  "Performs a PHP code sniffer check on the current file."
+  (interactive)
+  (let ((compilation-error-regexp-alist '(gnu)))
+    (compile (format "phpcs --standard=PEAR --report=emacs \"%s\""
+                     (buffer-file-name)))))

  ;; Check code style
  (define-key php-mode-map (kbd "<f3> <f11>") 'phpcs)
  </code>



More information about the cvs mailing list