Skip to content

Add font-lock-function-call compatible faces #784

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 3 commits into from
Jun 21, 2024
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
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Names Sorted Alphabetically:

- Aaron S. Hawley
- Alan Pearce
- Alex Figl-Brick
- Andreas Röhler
- Andrei Chițu
- Antoine Brand
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
* Remove `$` from face names for interoperability with treesit ([#780], [emacs-php/php-ts-mode#68])
* `php-$this` → `php-this`
* `php-$this-sigil` → `php-this-sigil`
* Add `php-function-call-standard` face inherit `font-lock-function-call-face` on Emacs 29.1 and above ([#782], thanks [@bricka]!)
* Add `-tranditional` suffix to the `php-*-call` faces.
* `php-function-call` → `php-function-call-traditional`
* `php-method-call` → `php-method-call-traditional`
* `php-static-method-call` → `php-static-method-call-traditional`
* Add variables for the `php-function-call`, `php-method-call`, and `php-static-method-call` faces, defaulting to the `-traditional` face.

### Removed

Expand All @@ -32,6 +38,8 @@ All notable changes of the PHP Mode 1.19.1 release series are documented in this
[#776]: https://github.com/emacs-php/php-mode/discussions/776
[#777]: https://github.com/emacs-php/php-mode/pull/777
[#780]: https://github.com/emacs-php/php-mode/issues/780
[#782]: https://github.com/emacs-php/php-mode/issues/782
[@bricka]: https://github.com/bricka
[emacs-php/php-ts-mode#68]: https://github.com/emacs-php/php-ts-mode/pull/68
[PEAR Coding Standards]: https://pear.php.net/manual/en/standards.php

Expand Down
34 changes: 28 additions & 6 deletions lisp/php-face.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,42 @@
:group 'php-faces
:tag "PHP Function Name")

(defface php-function-call '((t ()))
(defface php-function-call-standard `((t ,(when (eval-when-compile (get 'font-lock-function-call-face 'face-defface-spec))
'(:inherit font-lock-function-call-face))))
"PHP Mode face used to highlight function names in calles."
:group 'php-faces
:tag "PHP Function Call")
:tag "PHP Function Call Standard")

(defface php-method-call '((t (:inherit php-function-call)))
(defface php-function-call-traditional '((t ()))
"PHP Mode face used to highlight function names in calles."
:group 'php-faces
:tag "PHP Function Call Traditional")

(define-obsolete-face-alias 'php-function-call 'php-function-call-traditional "1.26.0")

(defface php-method-call-standard '((t (:inherit php-function-call-standard)))
"PHP Mode face used to highlight method names in calles."
:group 'php-faces
:tag "PHP Method Call Standard")

(defface php-method-call-traditional '((t (:inherit php-function-call-traditional)))
"PHP Mode face used to highlight method names in calles."
:group 'php-faces
:tag "PHP Method Call")
:tag "PHP Method Call Traditional")

(define-obsolete-face-alias 'php-method-call 'php-method-call-traditional "1.26.0")

(defface php-static-method-call-standard '((t (:inherit php-method-call-standard)))
"PHP Mode face used to highlight static method names in calles."
:group 'php-faces
:tag "PHP Static Method Call Standard")

(defface php-static-method-call '((t (:inherit php-method-call)))
(defface php-static-method-call-traditional '((t (:inherit php-method-call-traditional)))
"PHP Mode face used to highlight static method names in calles."
:group 'php-faces
:tag "PHP Static Method Call")
:tag "PHP Static Method Call Traditional")

(define-obsolete-face-alias 'php-static-method-call 'php-static-method-call-traditional "1.26.0")

(defface php-variable-name '((t (:inherit font-lock-variable-name-face)))
"PHP Mode face used to highlight variable names."
Expand Down
6 changes: 3 additions & 3 deletions lisp/php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ for \\[find-tag] (which see)."

;; 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))
("\\(->\\)\\(\\sw+\\)\\s-*(" (1 'php-object-op) (2 php-method-call))
("\\<\\(const\\)\\s-+\\(\\_<.+?\\_>\\)" (1 'php-keyword) (2 'php-constant-assign))

;; Logical operator (!)
Expand Down Expand Up @@ -1413,7 +1413,7 @@ for \\[find-tag] (which see)."

;; Highlight static method calls as such. This is necessary for method
;; names which are identical to keywords to be highlighted correctly.
("\\sw+::\\(\\sw+\\)(" 1 'php-static-method-call)
("\\sw+::\\(\\sw+\\)(" 1 php-static-method-call)
;; Multiple catch (FooException | BarException $e)
(,(rx symbol-start "catch" symbol-end
(* (syntax whitespace)) "(" (* (syntax whitespace))
Expand Down Expand Up @@ -1457,7 +1457,7 @@ for \\[find-tag] (which see)."
(1 'php-import-declaration)
(,(rx (group (+ (or (syntax word) (syntax symbol) "\\" "{" "}")))) nil nil (1 'php-constant-assign t)))
;; Highlight function calls
("\\(\\_<\\(?:\\sw\\|\\s_\\)+?\\_>\\)\\s-*(" 1 'php-function-call)
("\\(\\_<\\(?:\\sw\\|\\s_\\)+?\\_>\\)\\s-*(" 1 php-function-call)
;; Highlight all upper-cased symbols as constant
("\\<\\([A-Z_][A-Z0-9_]+\\)\\>" 1 'php-constant)

Expand Down
18 changes: 18 additions & 0 deletions lisp/php.el
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,24 @@ a completion list."
:group 'php
:tag "PHP Topsy Separator"
:type 'string)

(defcustom php-function-call 'php-function-call-traditional
"Face name to use for method call."
:group 'php
:tag "PHP Function Call"
:type 'face)

(defcustom php-method-call 'php-method-call-traditional
"Face name to use for method call."
:group 'php
:tag "PHP Method Call"
:type 'face)

(defcustom php-static-method-call 'php-static-method-call-traditional
"Face name to use for method call."
:group 'php
:tag "PHP Static Method Call"
:type 'face)

;;; PHP Keywords
(defconst php-magical-constants
Expand Down
4 changes: 2 additions & 2 deletions tests/7.4/typed-property.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
(" ")
("print" . php-function-name)
("()\n {\n ")
("var_dump" . php-function-call)
("var_dump" . php-function-call-traditional)
("(")
("$" . php-this-sigil)
("this" . php-this)
Expand All @@ -60,5 +60,5 @@
("Typed" . font-lock-type-face)
(")")
("->" . php-object-op)
("print" . php-method-call)
("print" . php-method-call-traditional)
("();\n"))
12 changes: 6 additions & 6 deletions tests/8.0/attribute/class.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

#[WithoutArgument]
#[")
("SingleArgument" . php-function-call)
("SingleArgument" . php-function-call-traditional)
("(0)]
#[")
("FewArguments" . php-function-call)
("FewArguments" . php-function-call-traditional)
("(")
("'Hello'" . php-string)
(", ")
Expand All @@ -40,9 +40,9 @@
("() {}

#[WithoutArgument] #[")
("SingleArgument" . php-function-call)
("SingleArgument" . php-function-call-traditional)
("(0)] #[")
("FewArguments" . php-function-call)
("FewArguments" . php-function-call-traditional)
("(")
("'Hello'" . php-string)
(", ")
Expand All @@ -55,11 +55,11 @@
("() {}

#[")
("Attr2" . php-function-call)
("Attr2" . php-function-call-traditional)
("(")
("\"foo\"" . php-string)
("), ")
("Attr2" . php-function-call)
("Attr2" . php-function-call-traditional)
("(")
("\"bar\"" . php-string)
(")]
Expand Down
8 changes: 4 additions & 4 deletions tests/8.0/attribute/function.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

#[WithoutArgument]
#[")
("SingleArgument" . php-function-call)
("SingleArgument" . php-function-call-traditional)
("(0)]
#[")
("FewArguments" . php-function-call)
("FewArguments" . php-function-call-traditional)
("(")
("'Hello'" . php-string)
(", ")
Expand All @@ -27,9 +27,9 @@
("() {}

#[WithoutArgument]#[")
("SingleArgument" . php-function-call)
("SingleArgument" . php-function-call-traditional)
("(0)]#[")
("FewArguments" . php-function-call)
("FewArguments" . php-function-call-traditional)
("(")
("'Hello'" . php-string)
(", ")
Expand Down
2 changes: 1 addition & 1 deletion tests/constants.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
(";\n")
("SomeClass" . php-constant)
("::" . php-paamayim-nekudotayim)
("classIdentifier" . php-static-method-call)
("classIdentifier" . php-static-method-call-traditional)
("();\n\n")
("__halt_compiler" . php-keyword)
("();\n\n")
Expand Down
6 changes: 3 additions & 3 deletions tests/identifiers.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
("the constant face. Just like c++-mode \"NS::Class::method()\"\n" . font-lock-comment-face)
("ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("method" . php-static-method-call)
("method" . php-static-method-call-traditional)
("();\n")
("\\SpaceName\\ClassName" . php-constant)
("::" . php-paamayim-nekudotayim)
("method" . php-static-method-call)
("method" . php-static-method-call-traditional)
("();\n")
("\\My_Class" . php-constant)
("::" . php-paamayim-nekudotayim)
("method" . php-static-method-call)
("method" . php-static-method-call-traditional)
("();\n\n")
("__halt_compiler" . php-keyword)
("();\n\n")
Expand Down
4 changes: 2 additions & 2 deletions tests/issue-197.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
("$" . php-variable-sigil)
("test" . php-variable-name)
("->" . php-object-op)
("int" . php-method-call)
("int" . php-method-call-traditional)
("();\n")
("$" . php-variable-sigil)
("test" . php-variable-name)
("->" . php-object-op)
("string" . php-method-call)
("string" . php-method-call-traditional)
("();\n"))
6 changes: 3 additions & 3 deletions tests/issue-201.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
(";\n")
("self" . php-keyword)
("::" . php-paamayim-nekudotayim)
("test" . php-static-method-call)
("test" . php-static-method-call-traditional)
("();\n")
("static" . php-keyword)
("::" . php-paamayim-nekudotayim)
("test" . php-static-method-call)
("test" . php-static-method-call-traditional)
("();\n")
("parent" . php-keyword)
("::" . php-paamayim-nekudotayim)
("test" . php-static-method-call)
("test" . php-static-method-call-traditional)
("();\n"))
4 changes: 2 additions & 2 deletions tests/issue-439.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
(" ")
("<<<\"いろは\"\nLet'go Justin\nいろは" . php-string)
(";\n\n")
("var_dump" . php-function-call)
("var_dump" . php-function-call-traditional)
("(")
("<<<\"ABC\"\nLet'go Justin\nABC" . php-string)
(");\n\n")
("if" . php-keyword)
(" (1 ")
("===" . php-comparison-op)
(" 1) {\n ")
("var_dump" . php-function-call)
("var_dump" . php-function-call-traditional)
("(")
("<<<\"ABC\"\n Let'go Justin\n ABC" . php-string)
(");\n}\n"))
2 changes: 1 addition & 1 deletion tests/lang/class/anonymous-class.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
("// " . font-lock-comment-delimiter-face)
("###php-mode-test### ((indent 4))\n" . font-lock-comment-face)
("};\n\n")
("is_object" . php-function-call)
("is_object" . php-function-call-traditional)
("(1, ")
("new" . php-keyword)
(" ")
Expand Down
2 changes: 1 addition & 1 deletion tests/lang/doc-comment/comments.php.24.faces
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
(" ")
("=" . php-assignment-op)
(" ")
("hoge" . php-function-call)
("hoge" . php-function-call-traditional)
("();\n\n ")
("// " . font-lock-comment-delimiter-face)
("one-line comment\n" . font-lock-comment-face)
Expand Down
2 changes: 1 addition & 1 deletion tests/lang/doc-comment/comments.php.27.faces
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
(" ")
("=" . php-assignment-op)
(" ")
("hoge" . php-function-call)
("hoge" . php-function-call-traditional)
("();\n\n ")
("// " . font-lock-comment-delimiter-face)
("one-line comment\n" . font-lock-comment-face)
Expand Down
2 changes: 1 addition & 1 deletion tests/lang/doc-comment/comments.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
(" ")
("=" . php-assignment-op)
(" ")
("hoge" . php-function-call)
("hoge" . php-function-call-traditional)
("();\n\n ")
("// " . font-lock-comment-delimiter-face)
("one-line comment\n" . font-lock-comment-face)
Expand Down
Loading
Loading