 Turning this on will force PEAR rules on all PHP files."
   :type 'boolean
   :group 'php)
-
-;; Note whether we're in XEmacs
-(defconst xemacsp (string-match "Lucid\\|XEmacs" emacs-version)
-  "Non nil if using XEmacs.")
++
+(eval-when-compile
+  (defconst php-mode-modified
+    (save-excursion
+      (and
+       (re-search-backward "^;; Modified: \\(.*\\)" nil 'noerror)
+       (match-string-no-properties 1)))
+    "PHP Mode version number."))
+
+(defun php-mode-version ()
+  "Display string describing the version of PHP mode"
+  (interactive)
+  (message "PHP mode %s of %s"
+	   php-mode-version-number php-mode-modified))
+
+(defconst php-beginning-of-defun-regexp
+  "^\\s *function\\s +&?\\(\\(\\sw\\|\\s_\\)+\\)\\s *("
+  "Regular expression for a PHP function.")
+
+(defun php-beginning-of-defun (&optional arg)
+  "Move to the beginning of the ARGth PHP function from point.
+Implements PHP version of `beginning-of-defun-function'."
+  (interactive "p")
+  (let ((arg (or arg 1)))
+    (while (> arg 0)
+      (re-search-backward php-beginning-of-defun-regexp
+			  nil 'noerror)
+      (setq arg (1- arg)))
+    (while (< arg 0)
+      (end-of-line 1)
+      (let ((opoint (point)))
+	(beginning-of-defun 1)
+	(forward-list 2)
+	(forward-line 1)
+	(if (eq opoint (point))
+	    (re-search-forward php-beginning-of-defun-regexp
+			       nil 'noerror))
+	(setq arg (1+ arg))))))
+
+(defun php-end-of-defun (&optional arg)
+  "Move the end of the ARGth PHP function from point.
+Implements PHP befsion of `end-of-defun-function'
+
+See `php-beginning-of-defun'."
+  (interactive "p")
+  (php-beginning-of-defun (- (or arg 1))))
+
++
+(defvar php-completion-table nil
+  "Obarray of tag names defined in current tags table and functions know to PHP.")
+
+(defvar php-warned-bad-indent nil)
+(make-variable-buffer-local 'php-warned-bad-indent)
+
+;; Do it but tell it is not good if html tags in buffer.
+(defun php-check-html-for-indentation ()
+  (let ((html-tag-re "</?\\sw+.*?>")
+        (here (point)))
+    (if (not (or (re-search-forward html-tag-re (line-end-position) t)
+                 (re-search-backward html-tag-re (line-beginning-position) t)))
+        t
+      (goto-char here)
+      (setq php-warned-bad-indent t)
+      (lwarn 'php-indent :warning
+	     "\n\t%s\n\t%s\n\t%s\n"
+	     "Indentation fails badly with mixed HTML and PHP."
+	     "Look for an Emacs Lisp library that supports \"multiple"
+	     "major modes\" like mumamo, mmm-mode or multi-mode.")
+      nil)))
+
+(defun php-cautious-indent-region (start end &optional quiet)
+  (if (or php-warned-bad-indent
+          (php-check-html-for-indentation))
+      (funcall 'c-indent-region start end quiet)))
+
+(defun php-cautious-indent-line ()
+  (if (or php-warned-bad-indent
+          (php-check-html-for-indentation))
+      (funcall 'c-indent-line)))
 
 ;;;###autoload
 (define-derived-mode php-mode c-mode "PHP"
   "Major mode for editing PHP code.\n\n\\{php-mode-map}"
-  
-  (setq comment-start "// "
-	comment-end   ""
-	comment-start-skip "// *")
-  
-  (setq c-class-key php-class-key)
-  (setq c-conditional-key php-conditional-key)
+;;   (c-add-language 'php-mode 'c-mode)
+
+;;   (c-lang-defconst c-block-stmt-1-kwds
+;;     php php-block-stmt-1-kwds)
+  (set (make-local-variable 'c-block-stmt-1-key) php-block-stmt-1-key)
+
+;;   (c-lang-defconst c-block-stmt-2-kwds
+;;     php php-block-stmt-2-kwds)
+  (set (make-local-variable 'c-block-stmt-2-key) php-block-stmt-2-key)
+  ;; Specify that cc-mode recognize Javadoc comment style
+  (set (make-local-variable 'c-doc-comment-style)
+    '((php-mode . javadoc)))
+
+;;   (c-lang-defconst c-class-decl-kwds
+;;     php php-class-decl-kwds)
+  (set (make-local-variable 'c-class-key) php-class-key)
 
   (defvar php-mode-syntax-table php-mode-syntax-table)
   ;; this line makes $ into punctuation instead of a word constituent

   (cons
    (concat "\\<\\(" php-constants "\\)\\>")
    'font-lock-constant-face)
   
   ;; Fontify keywords
   (cons
    (concat "\\<\\(" php-keywords "\\)\\>")
    'font-lock-keyword-face)
   
   ;; Fontify keywords and targets, and case default tags.
   (list "\\<\\(break\\|case\\|continue\\)\\>[ \t]*\\(-?\\(?:\\sw\\|\\s_\\)+\\)?"
	 '(1 font-lock-keyword-face) '(2 font-lock-constant-face t t))

;;; php-mode.el --- major mode for editing PHP code

;; Copyright (C) 1999, 2000, 2001, 2003, 2004 Turadg Aleahmad
;;               2008 Aaron S. Hawley

;; Maintainer: Aaron S. Hawley <ashawley at users.sourceforge.net>
;; Author: Turadg Aleahmad, 1999-2004
;; Keywords: php languages oop
;; Created: 1999-05-17
;; Modified: 2007-01-02
;; X-URL:   http://php-mode.sourceforge.net/

(defconst php-mode-version-number "1.4.0"
  "PHP Mode version number.")

;;; License

;; This file 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 3
;; of the License, or (at your option) any later version.

;; This file 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 file; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
;; 02110-1301, USA.

;;; Usage

;; Put this file in your Emacs lisp path (eg. site-lisp) and add to
;; your .emacs file:
;;
;;   (require 'php-mode)

;; To use abbrev-mode, add lines like this:
;;   (add-hook 'php-mode-hook
;;     '(lambda () (define-abbrev php-mode-abbrev-table "ex" "extends")))

;; To make php-mode compatible with html-mode, see http://php-mode.sf.net
