Skip to content
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

Improve class faces v2 #614

Merged
merged 7 commits into from
Mar 22, 2020
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
35 changes: 35 additions & 0 deletions php-face.el
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,41 @@
:group 'php-faces
:tag "PHP Class Declaration")

(defface php-class-declaration-spec '((t (:inherit php-keyword)))
"Face used to highlight class declaration specification keywords (implements, extends)"
:group 'php-faces
:tag "PHP Class Declaration Specification")

(defface php-namespace-declaration '((t (:inherit php-keyword)))
"Face used to highlight namespace declaration keyword."
:group 'php-faces
:tag "PHP Namespace Declaration")

(defface php-import-declaration '((t (:inherit php-keyword)))
"PHP Mode Face used to highlight import statements (use ... as ...)."
:group 'php-faces
:tag "PHP Import Statement")

(defface php-class-modifier '((t (:inherit php-keyword)))
"PHP Mode Face used to highlight class modifiers (final, abstract)."
:group 'php-faces
:tag "PHP Class Modifier")

(defface php-method-modifier '((t (:inherit php-keyword)))
"PHP Mode Face used to highlight method modifiers (final, abstract)."
:group 'php-faces
:tag "PHP Method Modifier")

(defface php-visibility-modifier '((t (:inherit php-keyword)))
"PHP Mode Face used to highlight access keywords (public, protected, private)."
:group 'php-faces
:tag "PHP Visibility Modifier")

(defface php-control-structure '((t (:inherit php-keyword)))
"PHP Mode Face used to highlight control structures (if, foreach, while, switch, catch...)."
:group 'php-faces
:tag "PHP Control Structure")

(define-obsolete-face-alias 'php-annotations-annotation-face 'php-doc-annotation-tag "1.19.0")

(provide 'php-face)
Expand Down
9 changes: 9 additions & 0 deletions php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,15 @@ a completion list."
;; only add patterns here if you want to prevent cc-mode from applying
;; a different face.
`(
;; Class declaration specification keywords (implements, extends)
("\\_<\\(?:implements\\|extends\\)\\_>" . 'php-class-declaration-spec)
;; Namespace declaration
("\\_<namespace\\_>" . 'php-namespace-declaration)
;; import statement
("\\_<use\\_>" . 'php-import-declaration)
;; Class modifiers (abstract, final)
("\\_<\\(abstract\\|final\\)\\_>\\s-+\\_<class\\>" 1 'php-class-modifier)

;; 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))
Expand Down
4 changes: 2 additions & 2 deletions tests/lang/class/anonymous-class.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
(" ")
("class" . php-class-declaration)
(" () ")
("extends" . php-keyword)
("extends" . php-class-declaration-spec)
(" ")
("IteratorAggregate" . font-lock-type-face)
(" {\n ")
Expand All @@ -23,7 +23,7 @@
(" ")
("class" . php-class-declaration)
(" () ")
("extends" . php-keyword)
("extends" . php-class-declaration-spec)
(" ")
("IteratorAggregate" . font-lock-type-face)
(" {\n ")
Expand Down
2 changes: 1 addition & 1 deletion tests/lang/doc-comment/annotation.php.faces
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
(" ")
("Child" . font-lock-type-face)
(" ")
("extends" . php-keyword)
("extends" . php-class-declaration-spec)
(" ")
("Parent_" . font-lock-type-face)
("\n{\n}\n"))
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 @@ -62,7 +62,7 @@
("@ORM\\Entity" php-doc-annotation-tag font-lock-doc-face)
("(repositoryClass=\"Emacs\\Repository\\MajorModeRepository\")\n */" . font-lock-doc-face)
("\n")
("final" . php-keyword)
("final" . php-class-modifier)
(" ")
("class" . php-class-declaration)
(" ")
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 @@ -63,7 +63,7 @@
("@ORM\\Entity" php-doc-annotation-tag font-lock-doc-face)
("(repositoryClass=\"Emacs\\Repository\\MajorModeRepository\")\n */" . font-lock-doc-face)
("\n")
("final" . php-keyword)
("final" . php-class-modifier)
(" ")
("class" . php-class-declaration)
(" ")
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 @@ -62,7 +62,7 @@
("@ORM\\Entity" php-doc-annotation-tag font-lock-doc-face)
("(repositoryClass=\"Emacs\\Repository\\MajorModeRepository\")\n */" . font-lock-doc-face)
("\n")
("final" . php-keyword)
("final" . php-class-modifier)
(" ")
("class" . php-class-declaration)
(" ")
Expand Down
4 changes: 0 additions & 4 deletions tests/language-constructs.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
endwhile;
eval();
exit();
extends ClassName;
final;
finally;
for;
Expand All @@ -47,14 +46,12 @@ function;
global;
goto;
if;
implements ClassName;
include;
include_once;
instanceof ClassName;
insteadof ClassName;
isset();
list();
namespace ClassName;
new ClassName;
print;
private;
Expand All @@ -68,7 +65,6 @@ function;
throw;
try;
unset();
use ClassName;
var;
while;
xor;
Expand Down
20 changes: 12 additions & 8 deletions tests/php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,12 @@ file name and check that the faces of the fonts in the buffer match."
(php-mode-test-process-magics))))
,(if faces
`(should (equal
(php-mode-test--parse-list-file
(concat (expand-file-name ,file php-mode-test-dir)
(if (eq t ,faces) ".faces" ,faces)))
(php-mode-test--buffer-face-list (current-buffer)))))
(cons ,file
(php-mode-test--parse-list-file
(concat (expand-file-name ,file php-mode-test-dir)
(if (eq t ,faces) ".faces" ,faces))))
(cons ,file
(php-mode-test--buffer-face-list (current-buffer))))))
(goto-char (point-min))
(let ((case-fold-search nil))
,@body)))
Expand Down Expand Up @@ -421,14 +423,16 @@ style from Drupal."
(with-php-mode-test ("language-constructs.php")
(while (search-forward "ClassName" nil t)
(backward-char)
(should (eq 'font-lock-type-face
(get-text-property (point) 'face)))))
(let ((token (symbol-at-point)))
(should (equal (list token 'font-lock-type-face)
(list token (get-text-property (point) 'face)))))))
(with-php-mode-test ("language-constructs.php")
(search-forward "Start:")
(while (not (= (line-number-at-pos) (count-lines (point-min) (point-max))))
(forward-line 1)
(should (eq 'php-keyword
(get-text-property (point) 'face))))))
(let ((token (symbol-at-point)))
(should (equal (list token 'php-keyword)
(list token (get-text-property (point) 'face))))))))

(ert-deftest php-mode-test-issue-178 ()
"Highligth as keyword and following symbol"
Expand Down