Skip to content

Commit 1fb2b33

Browse files
authored
Merge pull request #525 from emacs-php/recoloring-const-assign
Add php-constant-assign face to "const" statement
2 parents 242430b + 83eb4a8 commit 1fb2b33

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

php-face.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
"PHP Mode face used to highlight constants."
9393
:group 'php-faces)
9494

95+
(defface php-constant-assign '((t (:inherit font-lock-type-face)))
96+
"PHP Mode face used to highlight constant assigning (\"const\" statement)."
97+
:group 'php-faces)
98+
9599
(defface php-magical-constant '((t (:inherit font-lock-builtin-face)))
96100
"PHP Mode face used to highlight magical constants."
97101
:group 'php-faces)

php-mode.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,7 @@ a completion list."
13911391
;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but
13921392
;; not in $obj->var()
13931393
("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call))
1394+
("\\<\\(const\\)\\s-+\\(\\_<.+?\\_>\\)" (1 'php-keyword) (2 'php-constant-assign))
13941395

13951396
;; Highlight special variables
13961397
("\\(\\$\\)\\(this\\)\\>" (1 'php-$this-sigil) (2 'php-$this))

tests/lang/constants/const.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
const A = 'A';
4+
const a = 'a';
5+
const B='B';
6+
const b='b';
7+
const Aa = 'Aa';
8+
const AA = 'AA';
9+
const AB='AB';
10+
const Ab='AA';
11+
const α = '';
12+
const = '';
13+
const = '';
14+
const = '';
15+
const = '';
16+
const あα = 'あα';
17+
const 漢_ = '漢_';
18+
const あ_='あ_';
19+
const X='X';const y='y';
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n\n")
4+
("const" . php-keyword)
5+
(" ")
6+
("A" . php-constant-assign)
7+
(" = ")
8+
("'A'" . php-string)
9+
(";\n")
10+
("const" . php-keyword)
11+
(" ")
12+
("a" . php-constant-assign)
13+
(" = ")
14+
("'a'" . php-string)
15+
(";\n")
16+
("const" . php-keyword)
17+
(" ")
18+
("B" . php-constant-assign)
19+
("=")
20+
("'B'" . php-string)
21+
(";\n")
22+
("const" . php-keyword)
23+
(" ")
24+
("b" . php-constant-assign)
25+
("=")
26+
("'b'" . php-string)
27+
(";\n")
28+
("const" . php-keyword)
29+
(" ")
30+
("Aa" . php-constant-assign)
31+
(" = ")
32+
("'Aa'" . php-string)
33+
(";\n")
34+
("const" . php-keyword)
35+
(" ")
36+
("AA" . php-constant-assign)
37+
(" = ")
38+
("'AA'" . php-string)
39+
(";\n")
40+
("const" . php-keyword)
41+
(" ")
42+
("AB" . php-constant-assign)
43+
("=")
44+
("'AB'" . php-string)
45+
(";\n")
46+
("const" . php-keyword)
47+
(" ")
48+
("Ab" . php-constant-assign)
49+
("=")
50+
("'AA'" . php-string)
51+
(";\n")
52+
("const" . php-keyword)
53+
(" ")
54+
("α" . php-constant-assign)
55+
(" = ")
56+
("''" . php-string)
57+
(";\n")
58+
("const" . php-keyword)
59+
(" ")
60+
("" . php-constant-assign)
61+
(" = ")
62+
("''" . php-string)
63+
(";\n")
64+
("const" . php-keyword)
65+
(" ")
66+
("" . php-constant-assign)
67+
(" = ")
68+
("''" . php-string)
69+
(";\n")
70+
("const" . php-keyword)
71+
(" ")
72+
("" . php-constant-assign)
73+
(" = ")
74+
("'あ'" . php-string)
75+
(";\n")
76+
("const" . php-keyword)
77+
(" ")
78+
("" . php-constant-assign)
79+
(" = ")
80+
("'漢'" . php-string)
81+
(";\n")
82+
("const" . php-keyword)
83+
(" ")
84+
("あα" . php-constant-assign)
85+
(" = ")
86+
("'あα'" . php-string)
87+
(";\n")
88+
("const" . php-keyword)
89+
(" ")
90+
("漢_" . php-constant-assign)
91+
(" = ")
92+
("'漢_'" . php-string)
93+
(";\n")
94+
("const" . php-keyword)
95+
(" ")
96+
("あ_" . php-constant-assign)
97+
("=")
98+
("'あ_'" . php-string)
99+
(";\n")
100+
("const" . php-keyword)
101+
(" ")
102+
("X" . php-constant-assign)
103+
("=")
104+
("'X'" . php-string)
105+
(";")
106+
("const" . php-keyword)
107+
(" ")
108+
("y" . php-constant-assign)
109+
("=")
110+
("'y'" . php-string)
111+
(";\n"))

0 commit comments

Comments
 (0)