Skip to content

Highlight function calls as php-function-call #583

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 2 commits into from
Nov 27, 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
29 changes: 27 additions & 2 deletions php-face.el
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,32 @@
:group 'php-faces
:tag "PHP Variable Sigil")

(defface php-object-op '((t (:inherit default)))
(defface php-operator '((t (:inherit default)))
"PHP Mode face used to operators."
:group 'php-faces
:tag "PHP Operator")

(defface php-assignment-op '((t (:inherit php-operator)))
"PHP Mode face used to assignment operators (=, +=, ...)."
:group 'php-faces
:tag "PHP Object Op")

(defface php-comparison-op '((t (:inherit php-operator)))
"PHP Mode face used to comparison operators (==, !=, ===, ...)."
:group 'php-faces
:tag "PHP Comparison Op")

(defface php-logical-op '((t (:inherit php-operator)))
"PHP Mode face used to logical operators (&&, ||, ?:)."
:group 'php-faces
:tag "PHP Logical Op")

(defface php-string-op '((t (:inherit php-operator)))
"PHP Mode face used to logical operators (.)."
:group 'php-faces
:tag "PHP String Op")

(defface php-object-op '((t (:inherit php-operator)))
"PHP Mode face used to object operators (->)."
:group 'php-faces
:tag "PHP Object Op")
Expand Down Expand Up @@ -131,7 +156,7 @@
:group 'php-faces
:tag "PHP $this Sigil")

(defface php-errorcontrol-op '((t (:inherit font-lock-type-face)))
(defface php-errorcontrol-op '((t (:inherit font-lock-type-face)))
"PHP Mode face used to highlight errorcontrol operators (@).."
:group 'php-faces
:tag "PHP ErrorControl Op")
Expand Down
2 changes: 2 additions & 0 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,8 @@ a completion list."
;; is usually overkill.
`(
("\\<\\(@\\)" 1 'php-errorcontrol-op)
;; Highlight function calls
("\\(\\_<\\(?:\\sw\\|\\s_\\)+?\\_>\\)\\s-*(" 1 'php-function-call)
;; Highlight all upper-cased symbols as constant
("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant)

Expand Down
4 changes: 3 additions & 1 deletion tests/7.4/typed-property.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
("print" . php-function-name)
("()
{
var_dump(")
")
("var_dump" . php-function-call)
("(")
("$" . php-$this-sigil)
("this" . php-$this)
("->" . php-object-op)
Expand Down
4 changes: 3 additions & 1 deletion tests/comments.php.24.faces
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@
("\n ")
("$" . php-variable-sigil)
("foo" . php-variable-name)
(" = hoge();\n\n ")
(" = ")
("hoge" . php-function-call)
("();\n\n ")
("// " . font-lock-comment-delimiter-face)
("one-line comment\n" . font-lock-comment-face)
(" ")
Expand Down
4 changes: 3 additions & 1 deletion tests/comments.php.27.faces
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@
("\n ")
("$" . php-variable-sigil)
("foo" . php-variable-name)
(" = hoge();\n\n ")
(" = ")
("hoge" . php-function-call)
("();\n\n ")
("// " . font-lock-comment-delimiter-face)
("one-line comment\n" . font-lock-comment-face)
(" ")
Expand Down
4 changes: 3 additions & 1 deletion tests/comments.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@
("\n ")
("$" . php-variable-sigil)
("foo" . php-variable-name)
(" = hoge();\n\n ")
(" = ")
("hoge" . php-function-call)
("();\n\n ")
("// " . font-lock-comment-delimiter-face)
("one-line comment\n" . font-lock-comment-face)
(" ")
Expand Down
8 changes: 6 additions & 2 deletions tests/issue-439.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@
("g" . php-variable-name)
(" = ")
("<<<\"いろは\"\nLet'go Justin\nいろは" . php-string)
(";\n\nvar_dump(")
(";\n\n")
("var_dump" . php-function-call)
("(")
("<<<\"ABC\"\nLet'go Justin\nABC" . php-string)
(");\n\n")
("if" . php-keyword)
(" (1 === 1) {\n var_dump(")
(" (1 === 1) {\n ")
("var_dump" . php-function-call)
("(")
("<<<\"ABC\"\n Let'go Justin\n ABC" . php-string)
(");\n}\n")
)
19 changes: 19 additions & 0 deletions tests/lang/function/calls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

if (isset($foo)) {
1+bar()+foo();
}

$foo->string();
$foo->isset();


$a->b();
$a = a();
$aaa = aaa();
$_aa = _aa();
$a_a = a_a();
$aa_ = aa_();
$a1c = a1c();
$あ = あ();
$_a = $a();
70 changes: 70 additions & 0 deletions tests/lang/function/calls.php.faces
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
;; -*- mode: emacs-lisp -*-
(("<?php" . php-php-tag)
("\n\n")
("if" . php-keyword)
(" (")
("isset" . php-keyword)
("(")
("$" . php-variable-sigil)
("foo" . php-variable-name)
(")) {\n 1+")
("bar" . php-function-call)
("()+")
("foo" . php-function-call)
("();\n}\n\n")
("$" . php-variable-sigil)
("foo" . php-variable-name)
("->" . php-object-op)
("string" . php-method-call)
("();\n")
("$" . php-variable-sigil)
("foo" . php-variable-name)
("->" . php-object-op)
("isset" . php-method-call)
("();\n\n\n")
("$" . php-variable-sigil)
("a" . php-variable-name)
("->" . php-object-op)
("b" . php-method-call)
("();\n")
("$" . php-variable-sigil)
("a" . php-variable-name)
(" = ")
("a" . php-function-call)
("();\n")
("$" . php-variable-sigil)
("aaa" . php-variable-name)
(" = ")
("aaa" . php-function-call)
("();\n")
("$" . php-variable-sigil)
("_aa" . php-variable-name)
(" = ")
("_aa" . php-function-call)
("();\n")
("$" . php-variable-sigil)
("a_a" . php-variable-name)
(" = ")
("a_a" . php-function-call)
("();\n")
("$" . php-variable-sigil)
("aa_" . php-variable-name)
(" = ")
("aa_" . php-function-call)
("();\n")
("$" . php-variable-sigil)
("a1c" . php-variable-name)
(" = ")
("a1c" . php-function-call)
("();\n")
("$" . php-variable-sigil)
("あ" . php-variable-name)
(" = ")
("あ" . php-function-call)
("();\n")
("$" . php-variable-sigil)
("_a" . php-variable-name)
(" = ")
("$" . php-variable-sigil)
("a" . php-variable-name)
("();\n"))
1 change: 1 addition & 0 deletions tests/php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ Meant for `php-mode-test-issue-503'."
(t t))))
(with-php-mode-test ("doc-comment/return-type.php" :faces t))
(with-php-mode-test ("doc-comment/inheritdoc.php" :faces t))
(with-php-mode-test ("lang/function/calls.php" :faces t))
(with-php-mode-test ("lang/try-cactch/multiple.php" :faces t))
(with-php-mode-test ("lang/types/cast.php" :faces t))
(with-php-mode-test ("lang/types/function.php" :faces t))
Expand Down