\documentclass{article}
\usepackage{ulem}
\pagestyle{headings}
\begin{document}
\part{ Emacs configurations for Horde}
\section{ Jan's configuration}
\begin{verbatim}

(autoload 'po-mode "po-mode" "Major mode for translators to edit PO files" t)
(setq auto-mode-alist (cons '("\\.po\\'\\|\\.po\\." . po-mode) auto-mode-alist))                                   

(require 'php-mode)
(add-to-list 'auto-mode-alist '("\\.dist\\'" . php-mode))
(add-to-list 'auto-mode-alist '("\\.phpt\\'" . php-mode))

(autoload 'javascript-mode "javascript" nil t)
(add-to-list 'auto-mode-alist (cons  "\\.js\\'" 'javascript-mode))

(global-set-key "\C-l" 'goto-line)

(c-add-style "horde"
  '((c-basic-offset . 4)
    (c-tab-always-indent . t)
    (indent-tabs-mode . nil)
    (fill-column . 79)
    (c-offsets-alist . ((inline-open . 0)
                        (defun-block-intro . +)
                        (block-open . -)
                        (statement-cont . +)
                        (statement-block-intro . +)
                        (arglist-close . 0)))
    (c-comment-only-line-offset (0 . 0))
    (c-hanging-braces-alist . ((defun-open after)
                               (substatement-open after)))
    (c-cleanup-list . (brace-else-brace brace-elseif-brace))))
(add-hook 'php-mode-common-hook
   '(lambda () (c-set-style "horde")))
\end{verbatim}

\section{ Gunnar's configuration}
Gunnar keeps his Emacs configuration\footnote{http://github.com/wrobel/pardalys/blob/b712dd2a68f2339c1c7ef0472d83dd47f90bfe62/pardalys/modules/tool\_emacs/files/ed\_01\_php\_mode.el} in a puppet\footnote{http://reductivelabs.com/trac/puppet} configuration repository\footnote{http://github.com/wrobel/pardalys/tree/master} on github.com\footnote{http://github.com}. It contains lisp functionality to run code checks, style checking, the GEBEN debugger\footnote{http://code.google.com/p/geben-on-emacs/} and PHPUnit tests\footnote{http://www.phpunit.de/} from within Emacs.

\part{ Emacs features}
\section{ 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.

\begin{verbatim}


(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)
\end{verbatim}

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.

\section{ Checking the code style for problems}
In order to adhere to the Horde coding standards\footnote{http://www.horde.org/horde/docs/?f=CODING\_STANDARDS.html} you can run PHP\_CodeSniffer\footnote{http://pear.php.net/package/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.

\subsection{ CodeSniffer\footnote{http://example.com/index.php?page=CodeSniffer} < 1.2.0}
\begin{verbatim}

;; 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)
\end{verbatim}

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.

\subsection{ CodeSniffer\footnote{http://example.com/index.php?page=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.

\subsubsection{ Binding the compile command for you PHP mode}
\begin{verbatim}

;;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)
\end{verbatim}

The style check will be run once you execute the "M-x compile" command.

\subsubsection{ Binding the style check to a command}
\begin{verbatim}

(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)
\end{verbatim}

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.

\end{document}
