Skip to content

Add php-errorcontrol-op face #519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions php-face.el
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
"PHP Mode face used to highlight sigils($) of $this variable."
:group 'php-faces)

(defface php-errorcontrol-op '((t (:inherit font-lock-type-face)))
"PHP Mode face used to highlight errorcontrol operators (@).."
:group 'php-face)

(defface php-php-tag '((t (:inherit font-lock-preprocessor-face)))
"PHP Mode face used to highlight PHP tags."
:group 'php-faces)
Expand Down
4 changes: 4 additions & 0 deletions php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -984,4 +984,8 @@ Meant for `php-mode-test-issue-503'."
"Test highlighting arrow funcsion (short closure syntax) added in PHP 7.4."
(with-php-mode-test ("7.4/arrow-function.php" :faces t)))

(ert-deftest php-mode-test-lang ()
"Test highlighting for language constructs."
(with-php-mode-test ("lang/errorcontrol.php" :faces t)))

;;; php-mode-test.el ends here
39 changes: 27 additions & 12 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ In that case set to `NIL'."
(left-assoc "\\" "::" "->")
(prefix "\\" "::")))

(c-lang-defconst c-operators
php (delete '(postfix-if-paren "<" ">")
(c-lang-const c-operators)))

;; Allow '\' when scanning from open brace back to defining
;; construct like class
(c-lang-defconst c-block-prefix-disallowed-chars
Expand Down Expand Up @@ -469,35 +473,32 @@ PHP does not have an \"enum\"-like keyword."
php '("implements" "extends"))

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

(c-lang-defconst c-ref-list-kwds
php nil)

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

(c-lang-defconst c-simple-stmt-kwds
php (append '("include" "include_once" "require" "require_once"
"echo" "print" "die" "exit")
(c-lang-const c-simple-stmt-kwds)))
php '("break" "continue" "die" "echo" "exit" "goto" "return" "throw"
"include" "include_once" "print" "require" "require_once"))

(c-lang-defconst c-constant-kwds
php '("true"
"false"
"null"))
php '("true" "false" "null"))

(c-lang-defconst c-lambda-kwds
php '("function"
"use"))
php '("function" "use"))

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

(c-lang-defconst c-other-kwds
"Keywords not accounted for by any other `*-kwds' language constant."
php '(
php
'(
"__halt_compiler"
"and"
"array"
Expand Down Expand Up @@ -546,6 +547,12 @@ PHP does not have an \"enum\"-like keyword."
(c-lang-defconst c-recognize-<>-arglists
php nil)

(c-lang-defconst c-<>-type-kwds
php nil)

(c-lang-defconst c-inside-<>-type-kwds
php nil)

(c-lang-defconst c-enums-contain-decls
php nil)

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

(c-lang-defconst c-basic-matchers-after
php (cl-remove-if (lambda (elm) (and (listp elm) (memq 'c-annotation-face elm)))
(c-lang-const c-basic-matchers-after php)))

(c-lang-defconst c-opt-<>-sexp-key
php nil)

(defun php-lineup-cascaded-calls (langelem)
"Line up chained methods using `c-lineup-cascaded-calls',
but only if the setting is enabled"
Expand Down Expand Up @@ -1431,6 +1445,7 @@ a completion list."
;; already fontified by another pattern. Note that using OVERRIDE
;; is usually overkill.
`(
("\\<\\(@\\)" 1 'php-errorcontrol-op)
;; Highlight all upper-cased symbols as constant
("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant)

Expand Down
9 changes: 9 additions & 0 deletions tests/lang/errorcontrol.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

new stdClass;
@new stdClass;
echo @a.@b;
echo @a;
echo @$a;

@fopen('php://memory', 'rw');
33 changes: 33 additions & 0 deletions tests/lang/errorcontrol.php.faces
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;; -*- mode: emacs-lisp -*-
(("<?php" . php-php-tag)
("\n\n")
("new" . php-keyword)
(" ")
("stdClass" . font-lock-type-face)
(";\n")
("@new" . php-keyword)
(" ")
("stdClass" . font-lock-type-face)
(";\n")
("echo" . php-keyword)
(" ")
("@" . php-errorcontrol-op)
("a.")
("@" . php-errorcontrol-op)
("b;\n")
("echo" . php-keyword)
(" ")
("@" . php-errorcontrol-op)
("a;\n")
("echo" . php-keyword)
(" ")
("@" . php-errorcontrol-op)
("$" . php-variable-sigil)
("a" . php-variable-name)
(";\n\n")
("@" . php-errorcontrol-op)
("fopen(")
("'php://memory'" . php-string)
(", ")
("'rw'" . php-string)
(");\n"))