Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06edbd3

Browse files
authored
Merge pull request #519 from emacs-php/feature/php-errorcontrol-face
Add php-errorcontrol-op face
2 parents a1642c7 + c861fca commit 06edbd3

File tree

5 files changed

+77
-12
lines changed

5 files changed

+77
-12
lines changed

php-face.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@
100100
"PHP Mode face used to highlight sigils($) of $this variable."
101101
:group 'php-faces)
102102

103+
(defface php-errorcontrol-op '((t (:inherit font-lock-type-face)))
104+
"PHP Mode face used to highlight errorcontrol operators (@).."
105+
:group 'php-face)
106+
103107
(defface php-php-tag '((t (:inherit font-lock-preprocessor-face)))
104108
"PHP Mode face used to highlight PHP tags."
105109
:group 'php-faces)

php-mode-test.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,4 +984,8 @@ Meant for `php-mode-test-issue-503'."
984984
"Test highlighting arrow funcsion (short closure syntax) added in PHP 7.4."
985985
(with-php-mode-test ("7.4/arrow-function.php" :faces t)))
986986

987+
(ert-deftest php-mode-test-lang ()
988+
"Test highlighting for language constructs."
989+
(with-php-mode-test ("lang/errorcontrol.php" :faces t)))
990+
987991
;;; php-mode-test.el ends here

php-mode.el

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ In that case set to `NIL'."
413413
(left-assoc "\\" "::" "->")
414414
(prefix "\\" "::")))
415415

416+
(c-lang-defconst c-operators
417+
php (delete '(postfix-if-paren "<" ">")
418+
(c-lang-const c-operators)))
419+
416420
;; Allow '\' when scanning from open brace back to defining
417421
;; construct like class
418422
(c-lang-defconst c-block-prefix-disallowed-chars
@@ -469,35 +473,32 @@ PHP does not have an \"enum\"-like keyword."
469473
php '("implements" "extends"))
470474

471475
(c-lang-defconst c-type-list-kwds
472-
php '("new" "use" "implements" "extends" "namespace" "instanceof" "insteadof"))
476+
php '("@new" ;; @new is *NOT* language construct, it's workaround for coloring.
477+
"new" "use" "implements" "extends" "namespace" "instanceof" "insteadof"))
473478

474479
(c-lang-defconst c-ref-list-kwds
475480
php nil)
476481

477482
(c-lang-defconst c-block-stmt-2-kwds
478-
php (append '("elseif" "foreach" "declare")
479-
(remove "synchronized" (c-lang-const c-block-stmt-2-kwds))))
483+
php '("catch" "declare" "elseif" "for" "foreach" "if" "switch" "while"))
480484

481485
(c-lang-defconst c-simple-stmt-kwds
482-
php (append '("include" "include_once" "require" "require_once"
483-
"echo" "print" "die" "exit")
484-
(c-lang-const c-simple-stmt-kwds)))
486+
php '("break" "continue" "die" "echo" "exit" "goto" "return" "throw"
487+
"include" "include_once" "print" "require" "require_once"))
485488

486489
(c-lang-defconst c-constant-kwds
487-
php '("true"
488-
"false"
489-
"null"))
490+
php '("true" "false" "null"))
490491

491492
(c-lang-defconst c-lambda-kwds
492-
php '("function"
493-
"use"))
493+
php '("function" "use"))
494494

495495
(c-lang-defconst c-other-block-decl-kwds
496496
php '("namespace"))
497497

498498
(c-lang-defconst c-other-kwds
499499
"Keywords not accounted for by any other `*-kwds' language constant."
500-
php '(
500+
php
501+
'(
501502
"__halt_compiler"
502503
"and"
503504
"array"
@@ -546,6 +547,12 @@ PHP does not have an \"enum\"-like keyword."
546547
(c-lang-defconst c-recognize-<>-arglists
547548
php nil)
548549

550+
(c-lang-defconst c-<>-type-kwds
551+
php nil)
552+
553+
(c-lang-defconst c-inside-<>-type-kwds
554+
php nil)
555+
549556
(c-lang-defconst c-enums-contain-decls
550557
php nil)
551558

@@ -569,6 +576,13 @@ might be to handle switch and goto labels differently."
569576
php (cl-remove-if (lambda (elm) (and (listp elm) (equal (car elm) "\\s|")))
570577
(c-lang-const c-basic-matchers-before php)))
571578

579+
(c-lang-defconst c-basic-matchers-after
580+
php (cl-remove-if (lambda (elm) (and (listp elm) (memq 'c-annotation-face elm)))
581+
(c-lang-const c-basic-matchers-after php)))
582+
583+
(c-lang-defconst c-opt-<>-sexp-key
584+
php nil)
585+
572586
(defun php-lineup-cascaded-calls (langelem)
573587
"Line up chained methods using `c-lineup-cascaded-calls',
574588
but only if the setting is enabled"
@@ -1431,6 +1445,7 @@ a completion list."
14311445
;; already fontified by another pattern. Note that using OVERRIDE
14321446
;; is usually overkill.
14331447
`(
1448+
("\\<\\(@\\)" 1 'php-errorcontrol-op)
14341449
;; Highlight all upper-cased symbols as constant
14351450
("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant)
14361451

tests/lang/errorcontrol.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
new stdClass;
4+
@new stdClass;
5+
echo @a.@b;
6+
echo @a;
7+
echo @$a;
8+
9+
@fopen('php://memory', 'rw');

tests/lang/errorcontrol.php.faces

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;; -*- mode: emacs-lisp -*-
2+
(("<?php" . php-php-tag)
3+
("\n\n")
4+
("new" . php-keyword)
5+
(" ")
6+
("stdClass" . font-lock-type-face)
7+
(";\n")
8+
("@new" . php-keyword)
9+
(" ")
10+
("stdClass" . font-lock-type-face)
11+
(";\n")
12+
("echo" . php-keyword)
13+
(" ")
14+
("@" . php-errorcontrol-op)
15+
("a.")
16+
("@" . php-errorcontrol-op)
17+
("b;\n")
18+
("echo" . php-keyword)
19+
(" ")
20+
("@" . php-errorcontrol-op)
21+
("a;\n")
22+
("echo" . php-keyword)
23+
(" ")
24+
("@" . php-errorcontrol-op)
25+
("$" . php-variable-sigil)
26+
("a" . php-variable-name)
27+
(";\n\n")
28+
("@" . php-errorcontrol-op)
29+
("fopen(")
30+
("'php://memory'" . php-string)
31+
(", ")
32+
("'rw'" . php-string)
33+
(");\n"))

0 commit comments

Comments
 (0)