Skip to content

Commit 1b4aba1

Browse files
authored
Merge pull request #64 from Gleek/master
Set treesit-defun-type-regexp to help with defun navigation
2 parents 3a8ab04 + 4db7c31 commit 1b4aba1

File tree

3 files changed

+87
-112
lines changed

3 files changed

+87
-112
lines changed

php-ts-mode.el

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ Currently there are `php-mode' and `php-ts-mode'."
331331

332332
(setq-local treesit-defun-name-function #'php-ts-mode--defun-name)
333333

334+
;; Navigation
335+
(setq-local treesit-defun-type-regexp
336+
(regexp-opt '("class_declaration"
337+
"enum_declaration"
338+
"function_definition"
339+
"interface_declaration"
340+
"method_declaration"
341+
"namespace_definition"
342+
"trait_declaration")))
343+
334344
;; Font-lock.
335345
(setq-local treesit-font-lock-settings php-ts-mode--font-lock-settings)
336346
(setq-local treesit-font-lock-feature-list
Lines changed: 74 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,63 @@
11
Code:
22
(lambda ()
33
(php-ts-mode)
4-
(forward-sentence 1))
4+
(beginning-of-defun))
55

6-
Point-Char: |
6+
Name: beginning-of-defun moves to method start
77

8-
Name: forward-sentence moves over method invocation
8+
Point-Char: |
99

1010
=-=
11-
class Basic
12-
{
13-
public function basic(): void
14-
{
15-
|echo "some text: {$text}";
16-
}
17-
}
18-
=-=
19-
class Basic
20-
{
21-
public function basic(): void
22-
{
23-
echo "some text: {$text}";|
24-
}
25-
}
26-
=-=-=
27-
28-
Name: forward-sentence moves over if
11+
<?php
2912

30-
=-=
3113
class Basic
3214
{
33-
public function basic(): void
34-
{
35-
|if ($x) {
36-
15+
public function basic(): void
16+
{
17+
return;|
3718
}
38-
echo "some text: {$text}";
39-
return;
40-
}
4119
}
4220
=-=
21+
<?php
22+
4323
class Basic
4424
{
45-
public function basic(): void
46-
{
47-
if ($x) {
48-
49-
}|
50-
echo "some text: {$text}";
51-
return;
52-
}
25+
| public function basic(): void
26+
{
27+
return;
28+
}
5329
}
5430
=-=-=
5531

5632
Code:
5733
(lambda ()
5834
(php-ts-mode)
59-
(forward-sentence 2))
60-
61-
Name: forward-sentence moves over multiple statements
62-
63-
=-=
64-
class Basic {
65-
public function basic(): void {
66-
|return;
67-
return;
68-
}
69-
}
70-
=-=
71-
class Basic {
72-
public function basic(): void {
73-
return;
74-
return;|
75-
}
76-
}
77-
=-=-=
35+
(end-of-defun))
7836

79-
Code:
80-
(lambda ()
81-
(php-ts-mode)
82-
(backward-sentence 1))
37+
Name: end-of-defun moves to method end
8338

84-
Name: backward-sentence moves over one statement
39+
Point-Char: |
8540

8641
=-=
87-
class Basic {
88-
public function basic(): void {
89-
return;|
90-
}
91-
}
92-
=-=
93-
class Basic {
94-
public function basic(): void {
95-
|return;
96-
}
97-
}
98-
=-=-=
99-
100-
Code:
101-
(lambda ()
102-
(php-ts-mode)
103-
(beginning-of-defun))
104-
105-
Name: beginning-of-defun moves to defun start
42+
<?php
10643

107-
=-=
108-
class Basic {
109-
public function basic(): void {
110-
return;|
111-
}
44+
class Basic
45+
{
46+
public function basic(): void
47+
{
48+
return;|
49+
}
11250
}
11351
=-=
114-
class Basic {
115-
| public function basic(): void {
116-
return;
117-
}
118-
}
52+
<?php
53+
54+
class Basic
55+
{
56+
public function basic(): void
57+
{
58+
return;
59+
}
60+
|}
11961
=-=-=
12062

12163
Code:
@@ -124,39 +66,62 @@ Code:
12466
(beginning-of-defun)
12567
(beginning-of-defun))
12668

127-
Name: beginning-of-defun moves to class
69+
Name: beginning-of-defun twice moves to class start
70+
71+
Point-Char: |
12872

12973
=-=
130-
class Basic {
131-
public function basic(): void {
132-
return;|
133-
}
74+
<?php
75+
76+
class Basic
77+
{
78+
public function basic(): void
79+
{
80+
return;|
81+
}
13482
}
13583
=-=
136-
|class Basic {
137-
public function basic(): void {
138-
return;
139-
}
84+
<?php
85+
86+
|class Basic
87+
{
88+
public function basic(): void
89+
{
90+
return;
91+
}
14092
}
14193
=-=-=
14294

14395
Code:
14496
(lambda ()
14597
(php-ts-mode)
98+
(end-of-defun)
14699
(end-of-defun))
147100

148-
Name: end-of-defun moves to defun end
101+
Name: end-of-defun twice moves to class block end
102+
103+
Point-Char: |
149104

150105
=-=
151-
class Basic {
152-
public funtion basic(): void {
153-
return;|
154-
}
106+
<?php
107+
108+
class Basic
109+
{
110+
public function basic(): void
111+
{
112+
return;|
113+
}
155114
}
115+
156116
=-=
157-
class Basic {
158-
public function basic(): void {
159-
return;
160-
}
161-
|}
117+
<?php
118+
119+
class Basic
120+
{
121+
public function basic(): void
122+
{
123+
return;
124+
}
125+
}
126+
|
162127
=-=-=

tests/php-ts-mode-tests.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
(ert-test-erts-file (ert-resource-file "indent.erts")))
3434

3535
; FIXME: implement basic movements
36-
;(ert-deftest php-ts-mode-test-movement ()
37-
; (skip-unless (treesit-ready-p 'php))
38-
; (ert-test-erts-file (ert-resource-file "movement.erts")))
36+
(ert-deftest php-ts-mode-test-movement ()
37+
(skip-unless (treesit-ready-p 'php))
38+
(ert-test-erts-file (ert-resource-file "movement.erts")))
3939

4040
(provide 'php-ts-mode-tests)
4141
;;; php-ts-mode-tests.el ends here

0 commit comments

Comments
 (0)