Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add individual faces #606

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8891afc
Add => to assignment operators
Dec 20, 2019
ab9a0f0
Add class declaration face
Dec 23, 2019
a1469dd
Fix php class declaration regex and inherit
Dec 23, 2019
00eeb2f
Add php class declaration specification face
Dec 23, 2019
26b9948
Add namespace declaration face
Dec 23, 2019
c68ab57
Add import statement face
Dec 23, 2019
2cb9b54
Improve import statement
Dec 23, 2019
aad24cf
Add class modifiers
Dec 23, 2019
451fb60
Add sanity check for class declaration (We don't want to match get_cl…
Dec 23, 2019
f79dfa9
Add method modifiers
Dec 23, 2019
f4cdd87
rename php modifiers faces; added php-property-acess face
Jan 2, 2020
49ee230
Simplify method-modifiers regex
Jan 2, 2020
79096c8
Add php method access and static modifier faces
Jan 2, 2020
3ddbffa
Make position of abstract/final keywords irrelevant in method declara…
Jan 2, 2020
cc050df
Change method faces to not collide with property faces; Add property …
Jan 2, 2020
908cfa7
Add property constant regex
Jan 2, 2020
249281d
Add block statement face
Jan 2, 2020
a702767
Simplify block statement regex
Jan 2, 2020
71f6998
Add flow-control, print and include statement faces
Jan 2, 2020
c7abe00
Add constant keyword face
Jan 2, 2020
9722ce8
Add number face
Jan 2, 2020
c8c76cf
Add php-string-quote face
Jan 2, 2020
91dbba5
Add block-delimiter face; fix wrong description
Jan 2, 2020
d52ff61
Add string and type operator faces
Jan 2, 2020
74533cb
Fix [, ] in php-block-delimiter
Jan 2, 2020
6589e7f
Adapt block statement regex to not catch occurences in strings
Jan 3, 2020
c0794e8
Normalize some of the face names
Jan 3, 2020
3b1e863
Add return type colon face
Jan 3, 2020
244267e
Add function-keyword face
Jan 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 111 additions & 1 deletion php-face.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 (.)."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

:group 'php-faces
:tag "PHP String Op")

Expand Down Expand Up @@ -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)
Expand Down
78 changes: 73 additions & 5 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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
("\\<function\\s-+&?\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*(" 1 'php-function-name)

Expand Down Expand Up @@ -1646,6 +1702,9 @@ a completion list."
;; Highlight the ? character for nullable type hints.
("\\(\\?\\)\\(:?\\sw\\|\\s_\\|\\\\\\)+\\s-+\\$" 1 font-lock-type-face)

;; Highlight the : character in front of return types.
("\\(?:function[[:space:]]+[[:word:]]+([[:word:][:space:],\$\\]*)\\)\\(:\\)" (1 'php-return-type-colon))

;; Class names without a namespace are not highlighted at all when they
;; are used as nullable type hints or return types (both nullable and
;; non-nullable). We have to use separate regular expressions, because
Expand All @@ -1656,7 +1715,7 @@ a completion list."
(")\\s-*:\\s-*\\??\\(\\(?:\\sw\\|\\s_\\)+\\)\\s-*\\(?:\{\\|;\\)" 1 font-lock-type-face)

;; Assignment operators (=, +=, ...)
("\\([^=<!>]+?\\([\-+./%]?=\\)[^=<!>]+?\\)" 2 'php-assignment-op)
("\\([^=<!>]+?\\([\-+./%]?=\\)[^=<!]+?\\)" 2 'php-assignment-op)

;; Comparison operators (==, ===, >=, ...)
("\\([!=]=\\{1,2\\}[>]?\\|[<>]=?\\)" 1 'php-comparison-op)
Expand All @@ -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
Expand Down Expand Up @@ -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)))


Expand Down