Skip to content

Commit c4e30e7

Browse files
committed
Add highlighting for magical constants
1 parent fcd376e commit c4e30e7

File tree

5 files changed

+78
-7
lines changed

5 files changed

+78
-7
lines changed

php-mode-test.el

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,12 @@ style from Drupal."
701701
"__IS_CONSTANT__"
702702
"IS_CONSTANT99"
703703
"extraconstant"
704-
"ClassName"
705-
"class;")))
704+
"ClassName")))
706705
(dolist (variable variables)
707706
(search-forward variable)
708707
(goto-char (match-beginning 0))
709-
(should (eq 'php-constant
710-
(get-text-property (point) 'face))))))
708+
(should (equal (cons variable 'php-constant)
709+
(cons variable (get-text-property (point) 'face)))))))
711710

712711
;; Set default
713712
(custom-set-variables '(php-extra-constants (quote ())))
@@ -989,6 +988,7 @@ Meant for `php-mode-test-issue-503'."
989988
(with-php-mode-test ("lang/types/cast.php" :faces t))
990989
(with-php-mode-test ("lang/types/function.php" :faces t))
991990
(with-php-mode-test ("lang/types/keywords.php" :faces t))
992-
(with-php-mode-test ("lang/errorcontrol.php" :faces t)))
991+
(with-php-mode-test ("lang/errorcontrol.php" :faces t))
992+
(with-php-mode-test ("lang/magical-constants/echo.php" :faces t)))
993993

994994
;;; php-mode-test.el ends here

php-mode.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,12 +1409,13 @@ a completion list."
14091409
;; - when used as cast, so that (int) and (array) look the same
14101410
("(\\(array\\))" 1 font-lock-type-face)
14111411

1412+
(,(regexp-opt php-magical-constants 'symbols) (1 'php-magical-constant))
14121413
;; namespaces
14131414
("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)[^:a-zA-Z0-9_\\\\]" 1 'font-lock-type-face)
14141415
("\\(\\([a-zA-Z0-9_]+\\\\\\)+[a-zA-Z0-9_]+\\|\\(\\\\[a-zA-Z0-9_]+\\)+\\)::" 1 'php-constant)
14151416

14161417
;; Support the ::class constant in PHP5.6
1417-
("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-constant))
1418+
("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-magical-constant))
14181419

14191420
;; Highlight static method calls as such. This is necessary for method
14201421
;; names which are identical to keywords to be highlighted correctly.

tests/constants.php.faces

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
("Class name resolution is a special case\n" . font-lock-comment-face)
4040
("stdClass" . php-constant)
4141
("::" . php-paamayim-nekudotayim)
42-
("class" . php-constant)
42+
("class" . php-magical-constant)
4343
(";\n")
4444
("SomeClass" . php-constant)
4545
("::" . php-paamayim-nekudotayim)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
echo __LINE__, PHP_EOL;
4+
echo __FILE__, PHP_EOL;
5+
echo __FILE__, PHP_EOL;
6+
echo __FUNCTION__, PHP_EOL;
7+
echo __CLASS__, PHP_EOL;
8+
echo __TRAIT__, PHP_EOL;
9+
echo __METHOD__, PHP_EOL;
10+
echo __NAMESPACE__, PHP_EOL;
11+
echo \Directory::class, PHP_EOL;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n\n")
4+
("echo" . php-keyword)
5+
(" ")
6+
("__LINE__" . php-magical-constant)
7+
(", ")
8+
("PHP_EOL" . php-constant)
9+
(";\n")
10+
("echo" . php-keyword)
11+
(" ")
12+
("__FILE__" . php-magical-constant)
13+
(", ")
14+
("PHP_EOL" . php-constant)
15+
(";\n")
16+
("echo" . php-keyword)
17+
(" ")
18+
("__FILE__" . php-magical-constant)
19+
(", ")
20+
("PHP_EOL" . php-constant)
21+
(";\n")
22+
("echo" . php-keyword)
23+
(" ")
24+
("__FUNCTION__" . php-magical-constant)
25+
(", ")
26+
("PHP_EOL" . php-constant)
27+
(";\n")
28+
("echo" . php-keyword)
29+
(" ")
30+
("__CLASS__" . php-magical-constant)
31+
(", ")
32+
("PHP_EOL" . php-constant)
33+
(";\n")
34+
("echo" . php-keyword)
35+
(" ")
36+
("__TRAIT__" . php-magical-constant)
37+
(", ")
38+
("PHP_EOL" . php-constant)
39+
(";\n")
40+
("echo" . php-keyword)
41+
(" ")
42+
("__METHOD__" . php-magical-constant)
43+
(", ")
44+
("PHP_EOL" . php-constant)
45+
(";\n")
46+
("echo" . php-keyword)
47+
(" ")
48+
("__NAMESPACE__" . php-magical-constant)
49+
(", ")
50+
("PHP_EOL" . php-constant)
51+
(";\n")
52+
("echo" . php-keyword)
53+
(" ")
54+
("\\Directory" . php-constant)
55+
("::" . php-paamayim-nekudotayim)
56+
("class" . php-magical-constant)
57+
(", ")
58+
("PHP_EOL" . php-constant)
59+
(";\n"))

0 commit comments

Comments
 (0)