Source

prog-modes / php-mode.el

Diff from to

php-mode.el

 ;;; php-mode.el --- major mode for editing PHP code
 
-;; Copyright (C) 1999-2001 Turadg Aleahmad
+;; Copyright (C) 1999-2003 Turadg Aleahmad
 
 ;; Maintainer: Turadg Aleahmad <turadg at users.sourceforge.net>
 ;; Keywords: php languages oop
 ;; Created: 1999-05-17
-;; Modified: 2002-01-22
-;; X-URL:   http://php-mode.sf.net/
+;; Modified: 2003-02-26
+;; X-URL:   http://php-mode.sourceforge.net/
 
-(defconst php-version "1.0.2"
+(defconst php-version "1.0.4"
   "PHP Mode version number.")
 
 ;;; License
 
 ;;; Usage
 
-;; Place this file in your Emacs lisp path (eg. site-lisp)
-;; and add to your .emacs file:
-;;   (load-library "php-mode-102")
+;; Rename this file to php-mode.el if it isn't already then place it in
+;; your Emacs lisp path (eg. site-lisp) and add to your .emacs file:
+;;   (require 'php-mode)
 
 ;; If you want colorization, turn on global-font-lock or
 ;; add this to your .emacs:
 ;;   (add-hook 'php-mode-user-hook 'turn-on-font-lock)
 
+;; To use abbrev-mode, add lines like this:
+;;   (add-hook 'php-mode-user-hook
+;;     '(lambda () (define-abbrev php-mode-abbrev-table "ex" "extends")))
+
 ;; To make php-mode compatible with html-mode, see php-mode.sf.net
 
 ;; Many options available under Help:Customize
 
 ;;; Changelog:
 
+;; 1.04
+;;   Fixed unbalanced regexp for "->symbol" match
+;;   Removed abbreviation definitions since they cause abbrev-mode
+;;   to always be enabled.  If you want them, include them in your
+;;   php-mode-user-hook as described above.
+
+;; 1.03
+;;   Took '_' out of word syntax table (suggested by Gregory Stark)
+;;   Revised regexps to include '_' (Turadg)
+;;   Include ZE 2 keywords (Stig Bakken)
+;;   Highlight superglobals (Stig Bakken)
+;;   Addition of "boolean" to types (Valentin Funk)
+;;   Autoloading of php-file-patterns (ppercot)
+
 ;; 1.02
 ;;   Highlight HTML tags and entities (see site for more on HTML)
 ;;   Highlight more constants by default
 	comment-start-skip "// *")
   
   (defvar php-mode-syntax-table php-mode-syntax-table)
-  ;; underscore considered part of word
-  (modify-syntax-entry ?_ "w" php-mode-syntax-table)
-  ;; dollar-sign considered punctuation, not part of word
-  ;; 2002-01-22: I don't remember saying the above so I'm commenting
-  ;; this out because it kills indenting of case lines that begin with $
-  ;; Let me know if you have a case for keeping it in, preferably
-  ;; along with a solution to the switch indenting problem
+  ;; this line makes $ into punctuation instead of a word constituent
+  ;; it used to be active, but it killed indenting of case lines that
+  ;; begin with '$' (many do).  If anyone has a solution to this
+  ;; problem, please let me know.  Of course, you're welcome to
+  ;; uncomment this line in your installation.
 ;  (modify-syntax-entry ?$ "." php-mode-syntax-table)
   
   ;; The above causes XEmacs to handle shell-style comments correctly,
   "\C-c\C-m"
   'php-browse-manual)
 
-;; Define abbreviations and their expansions
-(define-abbrev php-mode-abbrev-table "ex" "extends")
-(define-abbrev php-mode-abbrev-table "fu" "function")
-(define-abbrev php-mode-abbrev-table "GL" "GLOBAL")
-(define-abbrev php-mode-abbrev-table "req" "require(")
-(define-abbrev php-mode-abbrev-table "ret" "return")
-
 (defconst php-constants
   (eval-when-compile
     (regexp-opt
        "endfor" "endforeach" "endif" "endswitch" "endwhile" "exit"
        "extends" "for" "foreach" "global" "if" "include" "include_once"
        "next" "or" "require" "require_once" "return" "static" "switch"
-       "then" "var" "while" "xor") t))
+       "then" "var" "while" "xor" "private" "throw" "catch" "try") t))
   "PHP keywords.")
 
 (defconst php-identifier
 
 (defconst php-types
   (eval-when-compile
-    (regexp-opt '("array" "bool" "char" "const" "double" "float" "int"
-		  "integer" "long" "mixed" "object" "real" 
+    (regexp-opt '("array" "bool" "boolean" "char" "const" "double" "float"
+		  "int" "integer" "long" "mixed" "object" "real" 
 		  "string") t))
   "PHP types.")
 
+(defconst php-superglobals
+  (eval-when-compile
+    (regexp-opt '("_GET" "_POST" "_COOKIE" "_SESSION" "_ENV"
+		  "_SERVER" "_FILES") t))
+  "PHP superglobal variables.")
+
 ;; Set up font locking
 (defconst php-font-lock-keywords-1
   (list
     'font-lock-keyword-face)
    
    ;; Fontify keywords and targets, and case default tags.
-   (list "\\<\\(break\\|case\\|continue\\)\\>[ \t]*\\(-?\\sw+\\)?"
+   (list "\\<\\(break\\|case\\|continue\\)\\>[ \t]*\\(-?\\(?:\\sw\\|\\s_\\)+\\)?"
 	 '(1 font-lock-keyword-face) '(2 font-lock-constant-face t t))
    ;; This must come after the one for keywords and targets.
-   '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
+   '(":" ("^[ \t]*\\(\\(?:\\sw\\|\\s_\\)+\\)[ \t]*:[ \t]*$"
 	  (beginning-of-line) (end-of-line)
 	  (1 font-lock-constant-face)))
    
    (list
     
     ;; Fontify class declaration
-    '("^[ \t]*\\(class\\)[ \t]*\\(\\sw+\\)?"
+    '("^[ \t]*\\(class\\)[ \t]*\\(\\(?:\\sw\\|\\s_\\)+\\)?"
       (1 font-lock-keyword-face) (2 font-lock-type-face nil t))
     
     ;; Fontify function declaration
-    '("^[ \t]*\\(function\\)\\s-+&?\\(\\sw+\\)\\s-*("
+    '("^[ \t]*\\(function\\)\\s-+&?\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*("
       (1 font-lock-keyword-face)
       (2 font-lock-function-name-face nil t))
     
     ;; handle several words specially, to include following word,
     ;; thereby excluding it from unknown-symbol checks later
-    '("\\<\\(new\\|extends\\)\\s-+\\$?\\(\\sw+\\)"
+    '("\\<\\(new\\|extends\\)\\s-+\\$?\\(\\(?:\\sw\\|\\s_\\)+\\)"
       (1 font-lock-keyword-face) (2 font-lock-type-face))
     ))
   "Medium level highlighting for PHP mode.")
     '("&\\w+;" . font-lock-variable-name-face)
 
     ;; warn about '$' immediately after ->
-    '("\\$\\sw+->\\s-*\\(\\$\\)\\(\\sw+\\)"
+    '("\\$\\(?:\\sw\\|\\s_\\)+->\\s-*\\(\\$\\)\\(\\(?:\\sw\\|\\s_\\)+\\)"
       (1 font-lock-warning-face) (2 default))
     
     ;; warn about $word.word -- it could be a valid concatenation,
     ;; but without any spaces we'll assume $word->word was meant.
-    '("\\$\\sw+\\(\\.\\)\\sw"
+    '("\\$\\(?:\\sw\\|\\s_\\)+\\(\\.\\)\\sw"
       1 font-lock-warning-face)
     
     ;; Warn about ==> instead of =>
     
     ;; Fontify variables and function calls
     '("\\$\\(this\\)\\W" (1 font-lock-constant-face nil nil)) ; "this" as constant
-    '("\\$\\(\\sw+\\)" (1 font-lock-variable-name-face)) ; $variable
-    '("->\\(\\sw+\\)" (1 font-lock-variable-name-face t t)) ; ->variable
-    '("->\\(\\sw+\\)\\s-*(" . (1 default t t)) ; ->function_call
-    '("\\sw+::\\sw+\\s-*(" . default) ; class::method call
-    '("\\<\\sw+\\s-*[[(]" . default)	; word( or word[
+    `(,(concat "\\$" php-superglobals "\\W")
+      (1 font-lock-constant-face nil nil)) ; $_GET & co
+    '("\\$\\(\\(?:\\sw\\|\\s_\\)+\\)" (1 font-lock-variable-name-face)) ; $variable
+    '("->\\(\\(?:\\sw\\|\\s_\\)+\\)" (1 font-lock-variable-name-face t t)) ; ->variable
+    '("->\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" . (1 default t t)) ; ->function_call
+    '("\\(?:\\sw\\|\\s_\\)+::\\(?:\\sw\\|\\s_\\)+\\s-*(" . default) ; class::method call
+    '("\\<\\(?:\\sw\\|\\s_\\)+\\s-*[[(]" . default)	; word( or word[
     '("\\<[0-9]+" . default)		; number (also matches word)
     
     ;; Warn on any words not already fontified
-    '("\\<\\sw+\\>" . font-lock-warning-face)
+    '("\\<\\(?:\\sw\\|\\s_\\)+\\>" . font-lock-warning-face)
     ))
   "Gauchy level highlighting for PHP mode.")