diff --git a/php-face.el b/php-face.el index 5bd821e5..f875d61d 100644 --- a/php-face.el +++ b/php-face.el @@ -117,7 +117,7 @@ :tag "PHP Increment/Decrement Op") (defface php-string-op '((t (:inherit php-operator))) - "PHP Mode face used to logical operators (.)." + "PHP Mode face used to string operator (.)." :group 'php-faces :tag "PHP String Op") @@ -201,6 +201,116 @@ :group 'php-faces :tag "PHPDoc Class Name") +(defface php-class-declaration '((t (:inherit php-keyword))) + "Face used to highlight class declaration keywords." + :group 'php-faces + :tag "PHP Class Declaration") + +(defface php-class-declaration-spec '((t (:inherit php-keyword))) + "Face used to highlight class declaration specification keywords (implements, extends)." + :group 'php-faces + :tag "PHP Class Declaration Specification") + +(defface php-namespace-declaration '((t (:inherit php-keyword))) + "Face used to highlight namespace declaration keyword." + :group 'php-faces + :tag "PHP Namespace Declaration") + +(defface php-import-declaration '((t (:inherit php-keyword))) + "Face used to highlight import statements (use ... as ...)." + :group 'php-faces + :tag "PHP Import Declaration") + +(defface php-class-modifier '((t (:inherit php-keyword))) + "Face used to highlight class modifiers (final, abstract)." + :group 'php-faces + :tag "PHP Class Modifier") + +(defface php-method-modifier '((t (:inherit php-keyword))) + "Face used to highlight method modifiers (final, abstract)." + :group 'php-faces + :tag "PHP Method Modifier") + +(defface php-method-access '((t (:inherit php-keyword))) + "Face used to highlight method access keywords (public, protected, private)." + :group 'php-faces + :tag "PHP Method Access") + +(defface php-method-static '((t (:inherit php-keyword))) + "Face used to highlight static keyword in method declaration." + :group 'php-faces + :tag "PHP Method Static") + +(defface php-property-access '((t (:inherit php-keyword))) + "Face used to highlight property access keywords (public, protected, private)." + :group 'php-faces + :tag "PHP Property Access") + +(defface php-property-const '((t (:inherit php-keyword))) + "Face used to highlight const keyword in property declaration." + :group 'php-faces + :tag "PHP Property Const") + +(defface php-property-static '((t (:inherit php-keyword))) + "Face used to highlight static keyword in property declaration." + :group 'php-faces + :tag "PHP Property Static") + +(defface php-block-statement '((t (:inherit php-keyword))) + "Face used to highlight block statements (if, elseif, for, foreach, while, declare, switch, catch)." + :group 'php-faces + :tag "PHP Block Statement") + +(defface php-flow-control-statement '((t (:inherit php-keyword))) + "Face used to highlight flow control statements (break, continue, die, exit, goto, return, throw)." + :group 'php-faces + :tag "PHP Flow Control Statement") + +(defface php-print-statement '((t (:inherit php-keyword))) + "Face used to highlight print statements (echo, print, var_dump)." + :group 'php-faces + :tag "PHP Print Statement") + +(defface php-include-statement '((t (:inherit php-keyword))) + "Face used to highlight include statements (include, include_once, require, require_once)." + :group 'php-faces + :tag "PHP Include Statement") + +(defface php-constant-keyword '((t (:inherit php-keyword))) + "Face used to highlight constant keywords (true, false, null)." + :group 'php-faces + :tag "PHP Constant Keyword") + +(defface php-number '((t (:inherit default))) + "Face used to highlight numbers." + :group 'php-faces + :tag "PHP Number") + +(defface php-string-quote '((t (:inherit php-string))) + "Face used to highlight quotes surrounding a string." + :group 'php-faces + :tag "PHP String Quote") + +(defface php-block-delimiter '((t (:inherit default))) + "Face used to highlight block delimiters ((, ), [, ], {, })" + :group 'php-faces + :tag "PHP Block Delimiter") + +(defface php-type-operator '((t (:inherit default))) + "Face used to highlight type operators (insteadof, instanceof)" + :group 'php-faces + :tag "PHP Type Op") + +(defface php-return-type-colon '((t (:inherit default))) + "Face used to highlight : character in front of return type." + :group 'php-faces + :tag "PHP Return Type Colon") + +(defface php-function-keyword '((t (:inherit php-keyword))) + "Face used to highlight the 'function' keyword in declaration." + :group 'php-faces + :tag "PHP Function Keyword") + (define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0") (provide 'php-face) diff --git a/php-mode.el b/php-mode.el index 93e95410..afd8cc8b 100644 --- a/php-mode.el +++ b/php-mode.el @@ -688,6 +688,7 @@ but only if the setting is enabled" (case-label . +) (class-open . 0) (comment-intro . 0) + (inexpr-class . 0) (inlambda . 0) (inline-open . 0) (namespace-open . 0) @@ -1538,6 +1539,61 @@ a completion list." ;; only add patterns here if you want to prevent cc-mode from applying ;; a different face. `( + ;; Class declaration keywords (class, trait, interface) + ("\\(class\\|trait\\|interface\\)[^(]" (1 'php-class-declaration)) + + ;; Class declaration specification keywords (implements, extends) + ("implements\\|extends" . 'php-class-declaration-spec) + + ;; Namespace declaration + ("namespace" . 'php-namespace-declaration) + + ;; import statement (use ... as ...) + ("\\(use[[:space:]]\\)\\(?:[[:word:]\\]\\)" (1 'php-import-declaration)) + ("\\(?:[[:word:]\\]\\)\\([[:space:]]as\\)" (1 'php-import-declaration)) + + ;; Class modifiers (abstract, final) + ("\\(abstract\\|final\\)[[:space:]]\\(?:class\\)" (1 'php-class-modifier)) + + ;; Method modifiers (abstract, final) + ("\\(abstract\\|final\\)\\(?:[[:space:]]static\\|[[:space:]]public\\|[[:space:]]private\\|[[:space:]]protected\\)*\\(?:[[:space:]]function\\)" (1 'php-method-modifier)) + + ;; Method access protection (public, protected, private) + ("\\(private\\|protected\\|public\\)\\(?:[[:space:]]static\\|[[:space:]]final\\|[[:space:]]abstract\\)*\\(?:[[:space:]]function\\)" (1 'php-method-access)) + + ;; Method static modifier + ("\\(static\\)\\(?:[[:space:]]private\\|[[:space:]]protected\\|[[:space:]]public\\|[[:space:]]final\\|[[:space:]]abstract\\)*\\(?:[[:space:]]function\\)" (1 'php-method-static)) + + ;; function keyword + ("\\(function\\)\\(?:[[:space:]]+[_[:word:]\\]+[[:space:]]*(\\)" (1 'php-function-keyword)) + + ;; Property constants + ("\\(const\\)[[:space:]]\\(?:[^\$][[:word:]]\\)" (1 'php-property-const)) + + ;; Property access protection + ("\\(private\\|protected\\|public\\)\\(?:[[:space:]]static\\|[[:space:]]const\\)?\\(?:[[:space:]]\$?[[:word:]]+\\)\\(?:[[:space:]]*=[[:space:]]*[^;]+\\)?\\(?:;\\)" (1 'php-property-access)) + + ;; Property static modifier + ("\\(static\\)\\(?:[[:space:]]private\\|[[:space:]]protected\\|[[:space:]]public\\)?\\(?:[[:space:]]\$?[[:word:]]+\\)\\(?:[[:space:]]*=[[:space:]]*[^;]+\\)?\\(?:;\\)" (1 'php-property-static)) + + ;; Block statements (if, elseif, for, foreach, catch, switch, while, declare) + ("\\(if\\|elseif\\|for\\|foreach\\|catch\\|switch\\|while\\|declare\\)\\(?:[[:space:]]*(\\)" (1 'php-block-statement)) + + ;; Flow control statements (break, continue, die, exit, goto, return, throw) + ("break\\|continue\\|die\\|exit\\|goto\\|return\\|throw" . 'php-flow-control-statement) + + ;; Print statements (echo, print, var_dump) + ("echo\\|print\\|var_dump" . 'php-print-statement) + + ;; Type operators (insteadof, instanceof) + ("insteadof\\|instanceof" . 'php-type-operator) + + ;; Include statements (include, include_once, require, require_once) + ("include[^_]\\|include_once\\|require[^_]\\|require_once" . 'php-include-statement) + + ;; Constant keywords + ("true\\|false\\|null" . 'php-constant-keyword) + ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but ;; not in $obj->var() ("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call)) @@ -1550,7 +1606,7 @@ a completion list." ("\\(\\$\\)\\(this\\)\\>" (1 'php-$this-sigil) (2 'php-$this)) ("\\(\\$+\\)\\(\\sw+\\)" (1 'php-variable-sigil) (2 'php-variable-name)) ("\\(->\\)\\([a-zA-Z0-9_]+\\)" (1 'php-object-op) (2 'php-property-name)) - + ;; Highlight function/method names ("\\]+?\\([\-+./%]?=\\)[^=]+?\\)" 2 'php-assignment-op) + ("\\([^=]+?\\([\-+./%]?=\\)[^==, ...) ("\\([!=]=\\{1,2\\}[>]?\\|[<>]=?\\)" 1 'php-comparison-op) @@ -1670,8 +1729,16 @@ a completion list." ;; Logical operators (and, or, &&, ...) ;; Not operator (!) is defined in "before cc-mode" section above. - ("\\(&&\\|\|\|\\)" 1 'php-logical-op) - )) + ("\\(&&\\|||\\)" 1 'php-logical-op) + + ;; String operator (.) + ("\\(?:[^0-9[:space:]]\\)\\([[:space:]]*\\.[[:space:]]*\\)\\(?:[^0-9[:space:]]\\)" . (1 'php-string-op)) + + ;; Block delimiters ((, ), [, ], {, }) + ("\(\\|\)\\|\\[\\|\\]\\|\{\\|\}" . 'php-block-delimiter) + + ;; Numbers + ("[0-9]+\\.?" . 'php-number))) "Detailed highlighting for PHP Mode.") (defvar php-font-lock-keywords php-font-lock-keywords-3 @@ -1715,7 +1782,8 @@ The output will appear in the buffer *PHP*." '(progn (font-lock-add-keywords 'php-mode - `((php-string-intepolated-variable-font-lock-find)) + `((php-string-intepolated-variable-font-lock-find) + ("\\s\"\\|\\s|" 0 'php-string-quote t)) 'append)))