Skip to content

Commit f8e9bb9

Browse files
committed
update font rules, indention, faces and readme
1 parent 92c4d8a commit f8e9bb9

File tree

4 files changed

+82
-9
lines changed

4 files changed

+82
-9
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
*.elc
22
php-ts-mode-autoloads.el
3+
php-ts-mode-pkg.el
34
/.eask
45
/dist
6+
# emacs tmp files
7+
*~
8+
*#

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ If you haven't installed Tree-sitter yet, please read [How to Get Started with T
1616

1717
[How to Get Started with Tree-Sitter - Mastering Emacs]: https://www.masteringemacs.org/article/how-to-get-started-tree-sitter
1818

19+
Package can be installed by running the following command.
20+
21+
```
22+
M-x package-vc-install [RET] https://github.com/emacs-php/php-ts-mode
23+
```
24+
25+
### Configuration
26+
27+
Example configuration that you can put in your `.emacs` file
28+
29+
```
30+
;; Enable variables highlighting
31+
(customize-set-variable 'treesit-font-lock-level 4)
32+
33+
(add-hook 'php-ts-mode-hook (lambda ()
34+
;; Use spaces for indent
35+
(setq-local indent-tabs-mode nil)))
36+
```
37+
1938
### Grammer installation
2039

2140
If you don't already have `php-ts-mode` installed, please evaluate the Lisp code below.
@@ -36,7 +55,7 @@ In `php-ts-mode`, syntax elements are classified as follows.
3655
* **Level 1**: `comment` `definition` `preprocessor`
3756
* **Level 2**: `keyword` `string` `type`
3857
* **Level 3**: `function` `constant` `label`
39-
* **Level 4**: `bracket` `delimiter` `operator` `variables`
58+
* **Level 4**: `bracket` `delimiter` `operator` `variables` `this`
4059

4160
By default, up to **Level 3** will be highlighted.
4261

php-ts-face.el

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
;;; php-ts-face.el --- Face definitions for PHP script -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2023 Friends of Emacs-PHP development
4+
5+
;; Author: USAMI Kenta <[email protected]>
6+
;; Created: 5 May 2019
7+
;; Version: 1.25.0
8+
;; Keywords: faces, php
9+
;; Homepage: https://github.com/emacs-php/php-mode
10+
;; License: GPL-3.0-or-later
11+
12+
;; This program is free software; you can redistribute it and/or modify
13+
;; it under the terms of the GNU General Public License as published by
14+
;; the Free Software Foundation, either version 3 of the License, or
15+
;; (at your option) any later version.
16+
17+
;; This program is distributed in the hope that it will be useful,
18+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
;; GNU General Public License for more details.
21+
22+
;; You should have received a copy of the GNU General Public License
23+
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
24+
25+
;;; Commentary:
26+
27+
;; Face definitions for PHP script.
28+
29+
;;; Code:
30+
31+
;;;###autoload
32+
33+
(defface php-this '((t (:inherit php-constant)))
34+
"PHP Mode face used to highlight $this variables."
35+
:group 'php-faces
36+
:tag "PHP $this")
37+
38+
(defface php-this-sigil '((t (:inherit php-constant)))
39+
"PHP Mode face used to highlight sigils($) of $this variable."
40+
:group 'php-faces
41+
:tag "PHP $this Sigil")
42+
43+
(provide 'php-ts-face)
44+
;;; php-ts-face.el ends here

php-ts-mode.el

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
(require 'c-ts-common)
3737
(require 'php nil t)
3838
(require 'php-face nil t)
39+
(require 'php-ts-face nil t)
3940

4041
(declare-function php-base-mode "ext:php")
4142
(declare-function treesit-parser-create "treesit.c")
@@ -77,6 +78,7 @@
7778
;; "compound_statement" contains the body of many statements.
7879
;; For example function_definition, foreach_statement, etc.
7980
((parent-is "compound_statement") parent-bol ,offset)
81+
((parent-is "method_declaration") parent-bol 0)
8082
((parent-is "array_creation_expression") parent-bol ,offset)
8183
((parent-is "base_clause") parent-bol ,offset)
8284
((parent-is "class_interface_clause") parent-bol ,offset)
@@ -145,7 +147,8 @@ see https://www.php.net/manual/language.constants.predefined.php")
145147
(named_type (name) @php-type)
146148
(named_type (qualified_name) @php-type)
147149
(namespace_use_clause)
148-
(namespace_name (name))]
150+
(namespace_name (name))
151+
(optional_type "?" @php-type)]
149152
@php-type
150153
(class_interface_clause (name) @php-class)
151154
(class_constant_access_expression
@@ -176,7 +179,8 @@ see https://www.php.net/manual/language.constants.predefined.php")
176179
(trait_declaration
177180
name: (name) @php-class)
178181
(enum_case
179-
name: (name) @php-class))
182+
name: (name) @php-class)
183+
(base_clause (name) @php-class))
180184

181185
:language 'php
182186
:feature 'function
@@ -207,15 +211,17 @@ see https://www.php.net/manual/language.constants.predefined.php")
207211

208212
;; ((name) @constructor
209213
;; (:match ,(rx-to-string '(: bos (in "A-Z")))))
210-
211-
;; (variable_name (name) @php-$this
212-
;; (:match ,(rx bos "this" eos)
213-
;; @php-$this))
214214
(member_access_expression name: (name) @php-property-name)
215215
;;(variable_name (name) @font-lock-variable-name-face)
216216
(variable_name (name) @php-variable-name)
217217
(variable_name "$" @php-variable-sigil))
218218

219+
:language 'php
220+
:feature 'this
221+
:override t
222+
`((variable_name "$" @php-this-sigil (name) @php-this
223+
(:match ,(rx bos "this" eos) @php-this)))
224+
219225
:language 'php
220226
:feature 'comment
221227
`(((comment) @font-lock-doc-face
@@ -226,7 +232,7 @@ see https://www.php.net/manual/language.constants.predefined.php")
226232
:language 'php
227233
:feature 'string
228234
`([(string)
229-
(string_value)
235+
(string_content)
230236
(encapsed_string)
231237
(heredoc)
232238
(heredoc_body)
@@ -347,7 +353,7 @@ Currently there are `php-mode' and `php-ts-mode'."
347353
'((comment definition preprocessor)
348354
(keyword string type)
349355
(function constant label)
350-
(bracket delimiter operator variables)))
356+
(bracket delimiter operator variables this)))
351357

352358
;; Imenu.
353359
(setq-local treesit-simple-imenu-settings

0 commit comments

Comments
 (0)