From b98b0c45c2d044a0f5779d9205dd1ec3a447091e Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Tue, 14 May 2019 14:04:42 +0900 Subject: [PATCH 1/5] Add php-errorcontrol-op face --- php-face.el | 4 ++++ php-mode.el | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/php-face.el b/php-face.el index 648c741c..72a85038 100644 --- a/php-face.el +++ b/php-face.el @@ -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) diff --git a/php-mode.el b/php-mode.el index 9a1b5747..72857260 100644 --- a/php-mode.el +++ b/php-mode.el @@ -569,6 +569,10 @@ 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))) + (defun php-lineup-cascaded-calls (langelem) "Line up chained methods using `c-lineup-cascaded-calls', but only if the setting is enabled" @@ -1376,6 +1380,7 @@ a completion list." ;; only add patterns here if you want to prevent cc-mode from applying ;; a different face. `( + ("\\<\\(@\\)" 1 'php-errorcontrol-op) ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but ;; not in $obj->var() ("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call)) From 2c2d510a337ba16a68d70cc3e2e7c9b0f0a424de Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Wed, 15 May 2019 22:15:28 +0900 Subject: [PATCH 2/5] Add @new to c-type-list-kwds for class highlighting workaround --- php-mode.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/php-mode.el b/php-mode.el index 72857260..a59815b0 100644 --- a/php-mode.el +++ b/php-mode.el @@ -469,7 +469,8 @@ 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) @@ -1380,7 +1381,6 @@ a completion list." ;; only add patterns here if you want to prevent cc-mode from applying ;; a different face. `( - ("\\<\\(@\\)" 1 'php-errorcontrol-op) ;; Highlight variables, e.g. 'var' in '$var' and '$obj->var', but ;; not in $obj->var() ("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 'php-method-call)) @@ -1436,6 +1436,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) From 57194a53b7f69757c5f9f3d79629743798915052 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Wed, 15 May 2019 22:16:53 +0900 Subject: [PATCH 3/5] Expand kwds instead of using c-lang-const from 'java --- php-mode.el | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/php-mode.el b/php-mode.el index a59815b0..4741f91c 100644 --- a/php-mode.el +++ b/php-mode.el @@ -476,29 +476,25 @@ PHP does not have an \"enum\"-like keyword." 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" From 8a437100f6b2bbb84bc8aee8577ba302922d2af1 Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Wed, 15 May 2019 22:19:33 +0900 Subject: [PATCH 4/5] Disable <> operator and keywords --- php-mode.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/php-mode.el b/php-mode.el index 4741f91c..2f456e48 100644 --- a/php-mode.el +++ b/php-mode.el @@ -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 @@ -543,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) @@ -570,6 +580,9 @@ might be to handle switch and goto labels differently." 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" From c861fcad3ec5d344e13c326efe1b0339e6a218ee Mon Sep 17 00:00:00 2001 From: USAMI Kenta Date: Thu, 16 May 2019 00:39:25 +0900 Subject: [PATCH 5/5] Add test for lang/errorcontrol.php --- php-mode-test.el | 4 ++++ tests/lang/errorcontrol.php | 9 +++++++++ tests/lang/errorcontrol.php.faces | 33 +++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/lang/errorcontrol.php create mode 100644 tests/lang/errorcontrol.php.faces diff --git a/php-mode-test.el b/php-mode-test.el index 695b5ed0..1bf09c63 100644 --- a/php-mode-test.el +++ b/php-mode-test.el @@ -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 diff --git a/tests/lang/errorcontrol.php b/tests/lang/errorcontrol.php new file mode 100644 index 00000000..ff0af97b --- /dev/null +++ b/tests/lang/errorcontrol.php @@ -0,0 +1,9 @@ +