Skip to content

Commit b0c1bf3

Browse files
authored
Merge pull request #614 from emacs-php/miniknN-php-faces-2
Improve class faces v2
2 parents b73e7fc + 1e41ed3 commit b0c1bf3

9 files changed

+62
-18
lines changed

php-face.el

+35
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,41 @@
206206
:group 'php-faces
207207
:tag "PHP Class Declaration")
208208

209+
(defface php-class-declaration-spec '((t (:inherit php-keyword)))
210+
"Face used to highlight class declaration specification keywords (implements, extends)"
211+
:group 'php-faces
212+
:tag "PHP Class Declaration Specification")
213+
214+
(defface php-namespace-declaration '((t (:inherit php-keyword)))
215+
"Face used to highlight namespace declaration keyword."
216+
:group 'php-faces
217+
:tag "PHP Namespace Declaration")
218+
219+
(defface php-import-declaration '((t (:inherit php-keyword)))
220+
"PHP Mode Face used to highlight import statements (use ... as ...)."
221+
:group 'php-faces
222+
:tag "PHP Import Statement")
223+
224+
(defface php-class-modifier '((t (:inherit php-keyword)))
225+
"PHP Mode Face used to highlight class modifiers (final, abstract)."
226+
:group 'php-faces
227+
:tag "PHP Class Modifier")
228+
229+
(defface php-method-modifier '((t (:inherit php-keyword)))
230+
"PHP Mode Face used to highlight method modifiers (final, abstract)."
231+
:group 'php-faces
232+
:tag "PHP Method Modifier")
233+
234+
(defface php-visibility-modifier '((t (:inherit php-keyword)))
235+
"PHP Mode Face used to highlight access keywords (public, protected, private)."
236+
:group 'php-faces
237+
:tag "PHP Visibility Modifier")
238+
239+
(defface php-control-structure '((t (:inherit php-keyword)))
240+
"PHP Mode Face used to highlight control structures (if, foreach, while, switch, catch...)."
241+
:group 'php-faces
242+
:tag "PHP Control Structure")
243+
209244
(define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0")
210245

211246
(provide 'php-face)

php-mode.el

+9
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,15 @@ a completion list."
14941494
;; only add patterns here if you want to prevent cc-mode from applying
14951495
;; a different face.
14961496
`(
1497+
;; Class declaration specification keywords (implements, extends)
1498+
("\\_<\\(?:implements\\|extends\\)\\_>" . 'php-class-declaration-spec)
1499+
;; Namespace declaration
1500+
("\\_<namespace\\_>" . 'php-namespace-declaration)
1501+
;; import statement
1502+
("\\_<use\\_>" . 'php-import-declaration)
1503+
;; Class modifiers (abstract, final)
1504+
("\\_<\\(abstract\\|final\\)\\_>\\s-+\\_<class\\>" 1 'php-class-modifier)
1505+
14971506
;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but
14981507
;; not in $obj->var()
14991508
("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call))

tests/lang/class/anonymous-class.php.faces

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(" ")
1111
("class" . php-class-declaration)
1212
(" () ")
13-
("extends" . php-keyword)
13+
("extends" . php-class-declaration-spec)
1414
(" ")
1515
("IteratorAggregate" . font-lock-type-face)
1616
(" {\n ")
@@ -23,7 +23,7 @@
2323
(" ")
2424
("class" . php-class-declaration)
2525
(" () ")
26-
("extends" . php-keyword)
26+
("extends" . php-class-declaration-spec)
2727
(" ")
2828
("IteratorAggregate" . font-lock-type-face)
2929
(" {\n ")

tests/lang/doc-comment/annotation.php.faces

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
(" ")
2525
("Child" . font-lock-type-face)
2626
(" ")
27-
("extends" . php-keyword)
27+
("extends" . php-class-declaration-spec)
2828
(" ")
2929
("Parent_" . font-lock-type-face)
3030
("\n{\n}\n"))

tests/lang/doc-comment/comments.php.24.faces

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
("@ORM\\Entity" php-doc-annotation-tag font-lock-doc-face)
6363
("(repositoryClass=\"Emacs\\Repository\\MajorModeRepository\")\n */" . font-lock-doc-face)
6464
("\n")
65-
("final" . php-keyword)
65+
("final" . php-class-modifier)
6666
(" ")
6767
("class" . php-class-declaration)
6868
(" ")

tests/lang/doc-comment/comments.php.27.faces

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
("@ORM\\Entity" php-doc-annotation-tag font-lock-doc-face)
6464
("(repositoryClass=\"Emacs\\Repository\\MajorModeRepository\")\n */" . font-lock-doc-face)
6565
("\n")
66-
("final" . php-keyword)
66+
("final" . php-class-modifier)
6767
(" ")
6868
("class" . php-class-declaration)
6969
(" ")

tests/lang/doc-comment/comments.php.faces

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
("@ORM\\Entity" php-doc-annotation-tag font-lock-doc-face)
6363
("(repositoryClass=\"Emacs\\Repository\\MajorModeRepository\")\n */" . font-lock-doc-face)
6464
("\n")
65-
("final" . php-keyword)
65+
("final" . php-class-modifier)
6666
(" ")
6767
("class" . php-class-declaration)
6868
(" ")

tests/language-constructs.php

-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
endwhile;
3939
eval();
4040
exit();
41-
extends ClassName;
4241
final;
4342
finally;
4443
for;
@@ -47,14 +46,12 @@ function;
4746
global;
4847
goto;
4948
if;
50-
implements ClassName;
5149
include;
5250
include_once;
5351
instanceof ClassName;
5452
insteadof ClassName;
5553
isset();
5654
list();
57-
namespace ClassName;
5855
new ClassName;
5956
print;
6057
private;
@@ -68,7 +65,6 @@ function;
6865
throw;
6966
try;
7067
unset();
71-
use ClassName;
7268
var;
7369
while;
7470
xor;

tests/php-mode-test.el

+12-8
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,12 @@ file name and check that the faces of the fonts in the buffer match."
158158
(php-mode-test-process-magics))))
159159
,(if faces
160160
`(should (equal
161-
(php-mode-test--parse-list-file
162-
(concat (expand-file-name ,file php-mode-test-dir)
163-
(if (eq t ,faces) ".faces" ,faces)))
164-
(php-mode-test--buffer-face-list (current-buffer)))))
161+
(cons ,file
162+
(php-mode-test--parse-list-file
163+
(concat (expand-file-name ,file php-mode-test-dir)
164+
(if (eq t ,faces) ".faces" ,faces))))
165+
(cons ,file
166+
(php-mode-test--buffer-face-list (current-buffer))))))
165167
(goto-char (point-min))
166168
(let ((case-fold-search nil))
167169
,@body)))
@@ -421,14 +423,16 @@ style from Drupal."
421423
(with-php-mode-test ("language-constructs.php")
422424
(while (search-forward "ClassName" nil t)
423425
(backward-char)
424-
(should (eq 'font-lock-type-face
425-
(get-text-property (point) 'face)))))
426+
(let ((token (symbol-at-point)))
427+
(should (equal (list token 'font-lock-type-face)
428+
(list token (get-text-property (point) 'face)))))))
426429
(with-php-mode-test ("language-constructs.php")
427430
(search-forward "Start:")
428431
(while (not (= (line-number-at-pos) (count-lines (point-min) (point-max))))
429432
(forward-line 1)
430-
(should (eq 'php-keyword
431-
(get-text-property (point) 'face))))))
433+
(let ((token (symbol-at-point)))
434+
(should (equal (list token 'php-keyword)
435+
(list token (get-text-property (point) 'face))))))))
432436

433437
(ert-deftest php-mode-test-issue-178 ()
434438
"Highligth as keyword and following symbol"

0 commit comments

Comments
 (0)