Skip to content

Commit 25944c2

Browse files
committed
Add test for beginning/end-of-defun
1 parent ed03fde commit 25944c2

File tree

7 files changed

+579
-11
lines changed

7 files changed

+579
-11
lines changed

swift-mode-beginning-of-defun.el

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,23 +332,23 @@ Intended for internal use."
332332
'(\; implicit-\; } anonymous-function-parameter-in
333333
outside-of-buffer)))
334334
(swift-mode:pseudo-implicit-semicolon-p token))))
335-
(while (eq (swift-mode:token:type
336-
(save-excursion (swift-mode:forward-token)))
337-
'\;)
338-
(setq token (swift-mode:forward-token)))
339335
(if (memq (swift-mode:token:type token)
340336
'(\; anonymous-function-parameter-in))
341337
(goto-char (swift-mode:token:end token))
342338
(goto-char (swift-mode:token:start token)))
339+
(while (eq (swift-mode:token:type
340+
(save-excursion (swift-mode:forward-token)))
341+
'\;)
342+
(setq token (swift-mode:forward-token)))
343343
(cond
344344
((eq (swift-mode:token:type token) 'outside-of-buffer)
345345
(forward-comment (- (point)))
346-
(when (< (point) pos)
346+
(when (<= (point) pos)
347347
(goto-char (swift-mode:token:end token)))
348348
token)
349349
((eq (swift-mode:token:type token) '})
350350
(forward-comment (- (point)))
351-
(if (< (point) pos)
351+
(if (<= (point) pos)
352352
(progn
353353
(goto-char (swift-mode:token:end token))
354354
(swift-mode:end-of-statement))

swift-mode-lexer.el

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,9 @@ If this line ends with a single-line comment, goto just before the comment."
12521252
;; Proceed to the end of the comment.
12531253
(goto-char (swift-mode:chunk:start chunk))
12541254
(forward-comment 1)
1255-
(end-of-line)))))
1255+
(end-of-line)
1256+
(when (and (eobp) (swift-mode:chunk-after))
1257+
(goto-char (swift-mode:chunk:start (swift-mode:chunk-after))))))))
12561258

12571259
;;; Comment or string chunks
12581260

@@ -1301,8 +1303,8 @@ If this line ends with a single-line comment, goto just before the comment."
13011303
If the cursor is outside of strings and comments, return nil.
13021304
13031305
If PARSER-STATE is given, it is used instead of (syntax-ppss)."
1304-
(unless parser-state
1305-
(setq parser-state (syntax-ppss)))
1306+
(when (or (null parser-state) (number-or-marker-p parser-state))
1307+
(setq parser-state (save-excursion (syntax-ppss parser-state))))
13061308
(cond
13071309
((eq (nth 3 parser-state) t)
13081310
(swift-mode:chunk 'multiline-string (nth 8 parser-state)))

swift-mode.el

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
9898
See `forward-sexp for ARG."
9999
(setq arg (or arg 1))
100+
(when (swift-mode:chunk-after)
101+
(goto-char (swift-mode:chunk:start (swift-mode:chunk-after))))
100102
(if (< 0 arg)
101103
(while (< 0 arg)
102104
(while (eq (swift-mode:token:type (swift-mode:forward-sexp-1))
Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
// Foo bar baz.
2+
3+
// Import declarations
4+
5+
/*{*//* aaa */ /* bbb */@Foo import Foundation/*}*/
6+
/*{*/@Foo
7+
import Foundation/*}*/
8+
9+
/*{*/class Foo {
10+
/*{*/@Foo import Foundation/*}*/
11+
/*{*/@Foo
12+
import Foundation/*}*/
13+
}/*}*/
14+
15+
// Constant/variable declarations
16+
17+
/*{*/let x = foo()/*}*/
18+
/*{*/@Foo
19+
let
20+
y
21+
=
22+
bar()/*}*/
23+
24+
/*{*/class Foo {
25+
/*{*/let x = foo()/*}*/
26+
/*{*/@Foo
27+
public
28+
let
29+
y
30+
=
31+
bar()/*}*/
32+
33+
/*{*/var a: Int {
34+
return 0
35+
}/*}*/
36+
37+
/*{*/var a: Int {
38+
/*{*/@Foo
39+
get {
40+
return 0
41+
}/*}*/
42+
43+
/*{*/@Foo
44+
set {
45+
foo()
46+
}/*}*/
47+
}/*}*/
48+
49+
/*{*/var a = 0 {
50+
/*{*/@Foo
51+
willSet {
52+
foo()
53+
}/*}*/
54+
55+
/*{*/@Foo
56+
didSet {
57+
foo()
58+
}/*}*/
59+
}/*}*/
60+
61+
/*{*/func foo() {
62+
let x = foo()
63+
let
64+
y
65+
=
66+
bar()
67+
while
68+
let
69+
x
70+
=
71+
xx,
72+
var
73+
y
74+
=
75+
yy,
76+
case
77+
(
78+
a,
79+
b
80+
)
81+
=
82+
ab {
83+
foo()
84+
foo()
85+
}
86+
}/*}*/
87+
}/*}*/
88+
89+
// Type alias declarationss
90+
91+
/*{*/@Foo typealias A = B/*}*/
92+
93+
/*{*/@Foo
94+
typealias
95+
A
96+
=
97+
B/*}*/
98+
99+
/*{*/class Foo {
100+
/*{*/@Foo typealias A = B/*}*/
101+
102+
/*{*/@Foo
103+
public
104+
typealias
105+
A
106+
=
107+
B/*}*/
108+
}/*}*/
109+
110+
// Function declarations
111+
112+
/*{*/func foo() {
113+
}/*}*/
114+
115+
/*{*/@Foo
116+
func
117+
foo() {
118+
}/*}*/
119+
120+
/*{*/class Foo {
121+
/*{*/func foo() {
122+
}/*}*/
123+
124+
/*{*/@Foo
125+
public
126+
func
127+
foo<A
128+
:
129+
X,
130+
B,
131+
C>(
132+
a a
133+
:
134+
(Int -> [Int])
135+
=
136+
{
137+
x
138+
in
139+
[
140+
x
141+
]
142+
}
143+
)
144+
throws
145+
->
146+
@Foo
147+
[
148+
A
149+
]
150+
where
151+
A
152+
:
153+
X
154+
,
155+
B
156+
==
157+
Int
158+
{
159+
}/*}*/
160+
}/*}*/
161+
162+
// Enum declarations
163+
164+
/*{*/enum Foo<A> where A: B {
165+
/*{*/case Foo(a: Int)/*}*/
166+
/*{*/case Bar(b: Int), Baz/*}*/
167+
/*{*/case
168+
A(
169+
b
170+
:
171+
Int)
172+
,
173+
@Foo
174+
indirect
175+
B
176+
=
177+
0/*}*/
178+
179+
/*{*/func foo() -> a {
180+
switch this {
181+
case .Foo:
182+
return a
183+
case
184+
let .Bar(a):
185+
return a
186+
case
187+
.Baz(var a):
188+
return a
189+
}
190+
}/*}*/
191+
}/*}*/
192+
193+
194+
// Struct declarations
195+
196+
/*{*/struct Foo {
197+
}/*}*/
198+
199+
// Class declarations
200+
201+
/*{*/class Foo {
202+
}/*}*/
203+
204+
/*{*/@Foo
205+
public
206+
final
207+
class
208+
Foo<A
209+
:
210+
X
211+
,
212+
B
213+
,
214+
C>
215+
:
216+
X
217+
where
218+
A
219+
:
220+
X
221+
,
222+
B
223+
==
224+
Int
225+
{
226+
/*{*/class Foo {
227+
}/*}*/
228+
}/*}*/
229+
230+
// Protocol declarations
231+
232+
/*{*/protocol Foo {
233+
/*{*/var x: Int {
234+
/*{*/get/*}*/
235+
/*{*/set/*}*/
236+
}/*}*/
237+
/*{*/func foo()/*}*/
238+
239+
/*{*/associatedtype
240+
A
241+
:
242+
B
243+
=
244+
C
245+
where
246+
A
247+
:
248+
D,
249+
A
250+
==
251+
E/*}*/
252+
}/*}*/
253+
254+
// Extension declarations
255+
/*{*/extension Foo: AAA {
256+
}/*}*/
257+
258+
// Operator declarations
259+
/*{*/prefix
260+
operator
261+
+++/*}*/
262+
/*{*/postfix
263+
operator
264+
+++/*}*/
265+
/*{*/infix
266+
operator
267+
+++
268+
:
269+
AAA/*}*/
270+
271+
// Precedence group declarations
272+
/*{*/precedencegroup Foo {
273+
higherThan: AAA, BBB, CCC
274+
lowerThan: DDD, EEE, FFF
275+
assignment: false
276+
associativity: left
277+
}/*}*/
278+
279+
/*{*/class Foo {
280+
// Initializer declarations
281+
/*{*/init() {
282+
`init`() {
283+
}
284+
}/*}*/
285+
286+
// Deinitializer declarations
287+
/*{*/deinit() {
288+
}/*}*/
289+
290+
// Subscript declarations
291+
/*{*/subscript(x: Int) {
292+
}/*}*/
293+
}/*}*/
294+
295+
// Multiple declaratoins in single line
296+
297+
/*{*/func foo(){};/*}*/ /*{*/func foo(){/*{*/func foo(){}/*}*/};/*}*//*{*/func foo(){} ;/*}*/ /*{*/func foo() {} /* */ ;/*}*/ /*{*//* */ func foo() {}/*}*/
298+
299+
// Strings and comments
300+
301+
/*{*/let x = """
302+
class Foo {}
303+
\(
304+
{ () in
305+
/*{*/class Foo {
306+
}/*}*/
307+
return 0
308+
}()
309+
)
310+
"""/*}*/
311+
312+
// class Foo {}
313+
314+
/*
315+
class Foo {
316+
}
317+
*/
318+
319+
// Foo bar baz.

0 commit comments

Comments
 (0)