Emacs configurations for Horde Jan's configuration
(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")))
Gunnar's configuration
Gunnar keeps his Emacs configuration in a puppet configuration repository on github.com. It contains lisp functionality to run code checks, style checking, the GEBEN debugger and 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.
(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 " ") 'php-lint)
The last line binds the function to the key combination
;; 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 " ") 'phpcs)
The last line binds the function to the key combination
;;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)
The style check will be run once you execute the "M-x compile" command.
Binding the style check to a command
(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 " ") 'phpcs)
The last line binds the function to the key combination