Skip to content

Commit be716f0

Browse files
authored
Merge pull request #727 from emacs-php/feature/use-function
Add `use function` and `use const` to font-lock-keyword
2 parents cf9481c + d0949f1 commit be716f0

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed

lisp/php-mode.el

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,11 @@ for \\[find-tag] (which see)."
13961396
("\\_<\\(?:implements\\|extends\\)\\_>" . 'php-class-declaration-spec)
13971397
;; Namespace declaration
13981398
("\\_<namespace\\_>" . 'php-namespace-declaration)
1399+
;; import constant statement
1400+
(,(rx symbol-start (group "use" (+ (syntax whitespace)) "const")
1401+
(+ (syntax whitespace)))
1402+
(1 'php-import-declaration)
1403+
(,(rx (group (+ (or (syntax word) (syntax symbol) "\\" "{" "}")))) nil nil (1 'php-constant-assign)))
13991404
;; import statement
14001405
("\\_<use\\_>" . 'php-import-declaration)
14011406
;; Class modifiers (abstract, final)
@@ -1478,6 +1483,11 @@ for \\[find-tag] (which see)."
14781483
;; is usually overkill.
14791484
`(
14801485
("\\<\\(@\\)" 1 'php-errorcontrol-op)
1486+
;; import function statement
1487+
(,(rx symbol-start (group "use" (+ (syntax whitespace)) "function")
1488+
(+ (syntax whitespace)))
1489+
(1 'php-import-declaration)
1490+
(,(rx (group (+ (or (syntax word) (syntax symbol) "\\" "{" "}")))) nil nil (1 'php-function-name t)))
14811491
;; Highlight function calls
14821492
("\\(\\_<\\(?:\\sw\\|\\s_\\)+?\\_>\\)\\s-*(" 1 'php-function-call)
14831493
;; Highlight all upper-cased symbols as constant
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Foo;
3+
4+
use const Foo\BAR;
5+
use const Foo\{BUZ, BUZBUZ};
6+
use const PHP_VERSION;
7+
8+
const FOO = 'bar';
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n")
4+
("namespace" . php-namespace-declaration)
5+
(" ")
6+
("Foo" . font-lock-type-face)
7+
(";\n\n")
8+
("use const" . php-import-declaration)
9+
(" ")
10+
("Foo\\" . php-constant-assign)
11+
("BAR" . font-lock-type-face)
12+
(";\n")
13+
("use const" . php-import-declaration)
14+
(" ")
15+
("Foo" . font-lock-type-face)
16+
("\\{BUZ" . php-constant-assign)
17+
(", ")
18+
("BUZBUZ}" . php-constant-assign)
19+
(";\n")
20+
("use const" . php-import-declaration)
21+
(" ")
22+
("PHP_VERSION" . font-lock-type-face)
23+
(";\n\n")
24+
("const" . php-keyword)
25+
(" ")
26+
("FOO" . font-lock-type-face)
27+
(" ")
28+
("=" . php-assignment-op)
29+
(" ")
30+
("'bar'" . php-string)
31+
(";\n"))
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace Foo;
3+
4+
use function var_dump;
5+
use function is_array, is_string, is_dir;
6+
use function Safe\json_encode;
7+
use function Safe\{file_get_contents, json_decode};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n")
4+
("namespace" . php-namespace-declaration)
5+
(" ")
6+
("Foo" . font-lock-type-face)
7+
(";\n\n")
8+
("use" . php-import-declaration)
9+
(" ")
10+
("function" . php-keyword)
11+
(" ")
12+
("var_dump" . php-function-name)
13+
(";\n")
14+
("use" . php-import-declaration)
15+
(" ")
16+
("function" . php-keyword)
17+
(" ")
18+
("is_array" . php-function-name)
19+
(", ")
20+
("is_string" . php-function-name)
21+
(", ")
22+
("is_dir" . php-function-name)
23+
(";\n")
24+
("use" . php-import-declaration)
25+
(" ")
26+
("function" . php-keyword)
27+
(" ")
28+
("Safe\\json_encode" . php-function-name)
29+
(";\n")
30+
("use" . php-import-declaration)
31+
(" ")
32+
("function" . php-keyword)
33+
(" ")
34+
("Safe\\{file_get_contents" . php-function-name)
35+
(", ")
36+
("json_decode}" . php-function-name)
37+
(";\n"))

tests/php-mode-test.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ Meant for `php-mode-test-issue-503'."
683683
(with-php-mode-test ("lang/doc-comment/return-type.php" :faces t))
684684
(with-php-mode-test ("lang/function/calls.php" :faces t))
685685
(with-php-mode-test ("lang/function/closure.php" :indent t :magic t :faces t))
686+
(with-php-mode-test ("lang/import/import-constant.php" :faces t))
687+
(with-php-mode-test ("lang/import/import-function.php" :faces t))
686688
(with-php-mode-test ("lang/try-cactch/multiple.php" :faces t))
687689
(with-php-mode-test ("lang/types/cast.php" :faces t))
688690
(with-php-mode-test ("lang/types/function.php" :faces t))

0 commit comments

Comments
 (0)