Skip to content

Commit 1178d72

Browse files
committed
1 parent 1339e24 commit 1178d72

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

swift-mode-beginning-of-defun.el

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
;; `beginning-of-defun' and `end-of-defun'
2525
;;
2626
;; A defun is a declaration except local variable, "get", "set", "willSet",
27-
;; "didSet", or "case" within enum.
27+
;; "didSet", "case" within enum, or "init" within var.
2828
;;
2929
;; A defun include modifiers, attributes, and comments on the same line.
3030
;;
@@ -1417,7 +1417,8 @@ of ancestors."
14171417
(when (eq (swift-mode:token:type next-token) 'identifier)
14181418
next-token))))
14191419
name-tokens)
1420-
'()))))
1420+
(swift-mode:backward-sexps-until-open-curly-bracket)
1421+
(swift-mode:current-defun-name-token-list)))))
14211422

14221423
(defun swift-mode:current-defun-name-token ()
14231424
"Return the name token of the defun under the point."

test/swift-files/beginning-of-defun/beginning-of-defun.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,17 @@ foo() {
166166
/*{*/enum Foo<A> where A: B {
167167
/*{*/case Foo(a: Int)/*}*/
168168
/*{*/case Bar(b: Int), Baz/*}*/
169-
/*{*/case
170-
A(
171-
b
172-
:
173-
Int)
174-
,
175-
@Foo
169+
/*{*/@Foo
176170
indirect
171+
case
172+
A(
173+
b
174+
:
175+
Int)
176+
,
177177
B
178-
=
179-
0/*}*/
178+
=
179+
0/*}*/
180180

181181
/*{*/func foo() -> a {
182182
/*[*/switch this {

test/swift-files/indent/declarations.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ class Foo {
220220
}
221221

222222
var x {
223+
init {
224+
x = 1
225+
}
226+
223227
get {
224228
1
225229
}
@@ -230,6 +234,11 @@ class Foo {
230234
}
231235

232236
var x {
237+
init
238+
{
239+
x = 1
240+
}
241+
233242
get
234243
{
235244
1
@@ -241,6 +250,37 @@ class Foo {
241250
}
242251
}
243252

253+
var x {
254+
init(newValue) {
255+
x = 1
256+
}
257+
258+
get {
259+
1
260+
}
261+
262+
set(newValue) {
263+
foo()
264+
}
265+
}
266+
267+
var x {
268+
init(newValue)
269+
{
270+
x = 1
271+
}
272+
273+
get
274+
{
275+
1
276+
}
277+
278+
set(newValue)
279+
{
280+
foo()
281+
}
282+
}
283+
244284
var x {
245285
get
246286
async

0 commit comments

Comments
 (0)