-;; (require 'opac3)
-;; (setq 'opac3-phpunit-config "~/path/to/phpunit.xml")
+;;; opac3.el --- Minor PHP mode for programming AFI-OPAC2
 
+;; Copyright (C) 2012 Free Software Foundation, Inc.
+;;
+;; Author: Laurent Laffont <llaffont@afi-sa.fr>
+;; Maintainer: Laurent Laffont <llaffont@afi-sa.fr>
+;; Created: 6 Aug 2012
+;; Version: 0.01
+;; Keywords: languages, tools
 
-(require 'php+-mode)
-(php+-mode-setup)
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, write to the Free Software
+;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-(require 'phpunit)
-;;(require 'geben)
-
+;; Depends on: Geben, Php-mode, phpunit-mode
+;;
+;; Example of .emacs setup :
+;;
+;; (require 'php-mode)
+;; (add-to-list 'auto-mode-alist  '("\\.php[34]?\\'\\|\\.phtml\\'" . php-mode))
+;; (defun my-php-mode() 
+;; 	(autoload 'opac3-mode "opac3" "OPAC3 mode")
+;; 	(opac3-mode)
+;; )
+;; (add-hook 'php-mode-hook 'my-php-mode) 
 
 (defvar opac3-phpunit-config "~/dev/afi/afi-opac3/tests/phpunit.xml" "phpunit.xml path")
 
 
+(setq opac3-mode-hook '(opac3-php-mode))
 (defun opac3-php-mode()
-  (setq tab-width 2)
-  (setq indent-tabs-mode t)
-	(setq flymake-mode t)
-  (custom-set-variables
-   '(geben-pause-at-entry-line nil))
+	(require 'geben)
+	(require 'phpunit)
+  (setq 
+	 tab-width 2
+   indent-tabs-mode t
+	 flymake-mode t
+	 compilation-error-regexp-alist  '(	("^\\(/.*\\):\\([0-9]+\\)$" 1 2)
+																			("^.* \\(/.*\\):\\([0-9]+\\)" 1 2)
+																			("PHP\s+[0-9]+\. [^/]* \\([^:]+\\):\\([0-9]+\\)" 1 2)
+																			("in \\(/.*\\) on line \\([0-9]+\\)" 1 2) ) 
+	 geben-pause-at-entry-line nil)
 	)
 
-(autoload 'geben "geben" "PHP Debugger on Emacs" t)
-(add-hook 'php+-mode-hook 'opac3-php-mode)
 
 (defun opac3-stop-geben (buffer msg)
 	(geben-end 'geben-dbgp-default-port)
 	(jump-to-register 'g)
 	(setq compilation-finish-functions '())
-	(beginning-of-line)
-	(kill-line)
-	(kill-line)
+	;; (beginning-of-line)
+	;; (kill-line)
+	;; (kill-line)
 	(save-buffer)
 	)
 

		(if debug (progn (geben 1) 
										 (window-configuration-to-register 'g)
										 (add-to-list 'compilation-finish-functions 'opac3-stop-geben)
										 (beginning-of-line)
										 (insert "xdebug_break();")
										 (indent-according-to-mode)
										 (align-newline-and-indent)
										 (previous-line)
										 (beginning-of-line)
										 (save-buffer)
										 )
			)

	)


(defun opac3-run-phpunit-filtered-custom(custom-filter debug)
	"Prompt for a filter and run phpunit with it"
	(interactive (list (read-string "Enter PHPUnit fiter: ")
										 (y-or-n-p "Debug ?: ")))
	(opac3-compile-phpunit custom-filter debug)
	)



(defun opac3-debug-phpunit-function()
	"Run phpunit on this function with debugger activated"
	(interactive)
