Skip to content

Commit 5a5b907

Browse files
authored
Merge pull request #567 from emacs-php/font-lock/support-multiple-catch
Add font-lock for multiple catch
2 parents e28eada + 294e66b commit 5a5b907

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

php-mode.el

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,14 @@ a completion list."
15131513
;; Highlight static method calls as such. This is necessary for method
15141514
;; names which are identical to keywords to be highlighted correctly.
15151515
("\\sw+::\\(\\sw+\\)(" 1 'php-static-method-call)
1516-
1516+
;; Multiple catch (FooException | BarException $e)
1517+
(,(rx symbol-start "catch" symbol-end
1518+
(* (syntax whitespace)) "(" (* (syntax whitespace))
1519+
(group (+ (or (syntax word) (syntax symbol)))))
1520+
(1 font-lock-type-face)
1521+
(,(rx (* (syntax whitespace)) "|" (* (syntax whitespace))
1522+
(group (+ (or (syntax word) (syntax symbol))) symbol-end))
1523+
nil nil (1 font-lock-type-face)))
15171524
;; While c-opt-cpp-* highlights the <?php opening tags, it is not
15181525
;; possible to make it highlight short open tags and closing tags
15191526
;; as well. So we force the correct face on all cases that

tests/lang/try-cactch/multiple.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
try {
4+
} catch (ErrorException | PDOException $e) {
5+
} catch (Foo | Bar | Buz | Fuga $e) {
6+
} catch (Throwable $e) {
7+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n\n")
4+
("try" . php-keyword)
5+
(" {\n} ")
6+
("catch" . php-keyword)
7+
(" (")
8+
("ErrorException" . font-lock-type-face)
9+
(" | ")
10+
("PDOException" . font-lock-type-face)
11+
(" ")
12+
("$" . php-variable-sigil)
13+
("e" . php-variable-name)
14+
(") {\n} ")
15+
("catch" . php-keyword)
16+
(" (")
17+
("Foo" . font-lock-type-face)
18+
(" | ")
19+
("Bar" . font-lock-type-face)
20+
(" | ")
21+
("Buz" . font-lock-type-face)
22+
(" | ")
23+
("Fuga" . font-lock-type-face)
24+
(" ")
25+
("$" . php-variable-sigil)
26+
("e" . php-variable-name)
27+
(") {\n} ")
28+
("catch" . php-keyword)
29+
(" (")
30+
("Throwable" . font-lock-type-face)
31+
(" ")
32+
("$" . php-variable-sigil)
33+
("e" . php-variable-name)
34+
(") {\n}\n"))

tests/php-mode-test.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ Meant for `php-mode-test-issue-503'."
674674
(t t))))
675675
(with-php-mode-test ("doc-comment/return-type.php" :faces t))
676676
(with-php-mode-test ("doc-comment/inheritdoc.php" :faces t))
677+
(with-php-mode-test ("lang/try-cactch/multiple.php" :faces t))
677678
(with-php-mode-test ("lang/types/cast.php" :faces t))
678679
(with-php-mode-test ("lang/types/function.php" :faces t))
679680
(with-php-mode-test ("lang/types/keywords.php" :faces t))

0 commit comments

Comments
 (0)