Skip to content

Commit 42669da

Browse files
committed
Fix indentation for keywords used as parameter names
``` foo( in: 1 ) foo( where: 1 ) ```
1 parent 6cd2948 commit 42669da

File tree

3 files changed

+308
-54
lines changed

3 files changed

+308
-54
lines changed

swift-mode-font-lock.el

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ Return nil otherwise."
126126
"\\<catch\\>"
127127
"\\<dynamicType\\>"
128128
"\\<is\\>"
129-
"\\<nil\\>"
130129
"\\<rethrows\\>"
131130
"\\<super\\>"
132131
"\\<self\\>"

swift-mode-indent.el

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -217,46 +217,6 @@ declaration and its offset is `swift-mode:basic-offset'."
217217
(goto-char (swift-mode:token:start previous-token))
218218
(swift-mode:calculate-indent-after-comma))
219219

220-
;; Before "in" on the same line
221-
((and next-is-on-same-line (equal next-text "in"))
222-
;; When it is for-in statement, align with the token after "for":
223-
;;
224-
;; for
225-
;; x
226-
;; in
227-
;; foo
228-
;;
229-
;; for x
230-
;; in
231-
;; foo
232-
;;
233-
;; When it is anonymous function, align with the token after {:
234-
;;
235-
;; foo {
236-
;; x
237-
;; in
238-
;; ...
239-
;; }
240-
;;
241-
;;
242-
;; foo { x
243-
;; in
244-
;; ...
245-
;; }
246-
;;
247-
;; foo { [
248-
;; weak self
249-
;; ]
250-
;; (
251-
;; x,
252-
;; y
253-
;; )
254-
;; -> Void
255-
;; in
256-
;; a
257-
;; }
258-
(swift-mode:find-and-align-with-parents '("for" {)))
259-
260220
;; Before "case" or "default" on the same line, for switch statement
261221
((and
262222
next-is-on-same-line
@@ -340,6 +300,59 @@ declaration and its offset is `swift-mode:basic-offset'."
340300
swift-mode:statement-parent-tokens
341301
swift-mode:multiline-statement-offset))
342302

303+
;; After {
304+
((eq previous-type '{)
305+
(goto-char (swift-mode:token:start previous-token))
306+
(swift-mode:calculate-indent-after-open-curly-brace
307+
swift-mode:basic-offset))
308+
309+
;; After ( or [
310+
((memq previous-type '(\( \[))
311+
(goto-char (swift-mode:token:start previous-token))
312+
(swift-mode:calculate-indent-of-expression
313+
swift-mode:parenthesized-expression-offset
314+
swift-mode:parenthesized-expression-offset))
315+
316+
;; Before "in" on the same line
317+
((and next-is-on-same-line (equal next-text "in"))
318+
;; When it is for-in statement, align with the token after "for":
319+
;;
320+
;; for
321+
;; x
322+
;; in
323+
;; foo
324+
;;
325+
;; for x
326+
;; in
327+
;; foo
328+
;;
329+
;; When it is anonymous function, align with the token after {:
330+
;;
331+
;; foo {
332+
;; x
333+
;; in
334+
;; ...
335+
;; }
336+
;;
337+
;;
338+
;; foo { x
339+
;; in
340+
;; ...
341+
;; }
342+
;;
343+
;; foo { [
344+
;; weak self
345+
;; ]
346+
;; (
347+
;; x,
348+
;; y
349+
;; )
350+
;; -> Void
351+
;; in
352+
;; a
353+
;; }
354+
(swift-mode:find-and-align-with-parents '("for" {)))
355+
343356
;; Before "where" on the same line
344357
((and next-is-on-same-line (equal next-text "where"))
345358
;; switch {
@@ -411,19 +424,6 @@ declaration and its offset is `swift-mode:basic-offset'."
411424
'(<))
412425
swift-mode:multiline-statement-offset)))))
413426

414-
;; After {
415-
((eq previous-type '{)
416-
(goto-char (swift-mode:token:start previous-token))
417-
(swift-mode:calculate-indent-after-open-curly-brace
418-
swift-mode:basic-offset))
419-
420-
;; After ( or [
421-
((memq previous-type '(\( \[))
422-
(goto-char (swift-mode:token:start previous-token))
423-
(swift-mode:calculate-indent-of-expression
424-
swift-mode:parenthesized-expression-offset
425-
swift-mode:parenthesized-expression-offset))
426-
427427
;; After "where"
428428
((equal previous-text "where")
429429
;; switch {

test/swift-files/identifiers.swift

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,261 @@ let foo = foo.var
3333
let x = foo.where +
3434
a
3535

36+
// keywords as parameter names
37+
38+
func foo() {
39+
// Keywords used in declarations
40+
foo(
41+
associatedtype: 1
42+
)
43+
foo(
44+
class: 1
45+
)
46+
foo(
47+
deinit: 1
48+
)
49+
foo(
50+
enum: 1
51+
)
52+
foo(
53+
extension: 1
54+
)
55+
foo(
56+
fileprivate: 1
57+
)
58+
foo(
59+
func: 1
60+
)
61+
foo(
62+
import: 1
63+
)
64+
foo(
65+
init: 1
66+
)
67+
foo(
68+
inout: 1
69+
)
70+
foo(
71+
internal: 1
72+
)
73+
foo(
74+
let: 1
75+
)
76+
foo(
77+
open: 1
78+
)
79+
foo(
80+
operator: 1
81+
)
82+
foo(
83+
private: 1
84+
)
85+
foo(
86+
protocol: 1
87+
)
88+
foo(
89+
public: 1
90+
)
91+
foo(
92+
static: 1
93+
)
94+
foo(
95+
struct: 1
96+
)
97+
foo(
98+
subscript: 1
99+
)
100+
foo(
101+
typealias: 1
102+
)
103+
foo(
104+
var: 1
105+
)
106+
107+
// Keywords used in statements
108+
foo(
109+
break: 1
110+
)
111+
foo(
112+
case: 1
113+
)
114+
foo(
115+
continue: 1
116+
)
117+
foo(
118+
default: 1
119+
)
120+
foo(
121+
defer: 1
122+
)
123+
foo(
124+
do: 1
125+
)
126+
foo(
127+
else: 1
128+
)
129+
foo(
130+
fallthrough: 1
131+
)
132+
foo(
133+
for: 1
134+
)
135+
foo(
136+
guard: 1
137+
)
138+
foo(
139+
if: 1
140+
)
141+
foo(
142+
in: 1
143+
)
144+
foo(
145+
repeat: 1
146+
)
147+
foo(
148+
return: 1
149+
)
150+
foo(
151+
switch: 1
152+
)
153+
foo(
154+
where: 1
155+
)
156+
foo(
157+
while: 1
158+
)
159+
160+
// Keywords used in expressions and types (without true, false, and keywords begin with a number sign)
161+
foo(
162+
as: 1
163+
)
164+
foo(
165+
catch: 1
166+
)
167+
foo(
168+
dynamicType: 1
169+
)
170+
foo(
171+
is: 1
172+
)
173+
foo(
174+
rethrows: 1
175+
)
176+
foo(
177+
super: 1
178+
)
179+
foo(
180+
self: 1
181+
)
182+
foo(
183+
Self: 1
184+
)
185+
foo(
186+
throws: 1
187+
)
188+
foo(
189+
throw: 1
190+
)
191+
foo(
192+
try: 1
193+
)
194+
195+
// Keywords reserved in particular contexts
196+
foo(
197+
Protocol: 1
198+
)
199+
foo(
200+
Type: 1
201+
)
202+
foo(
203+
and: 1
204+
)
205+
foo(
206+
assignment: 1
207+
)
208+
foo(
209+
associativity: 1
210+
)
211+
foo(
212+
convenience: 1
213+
)
214+
foo(
215+
didSet: 1
216+
)
217+
foo(
218+
dynamic: 1
219+
)
220+
foo(
221+
final: 1
222+
)
223+
foo(
224+
get: 1
225+
)
226+
foo(
227+
higherThan: 1
228+
)
229+
foo(
230+
indirect: 1
231+
)
232+
foo(
233+
infix: 1
234+
)
235+
foo(
236+
lazy: 1
237+
)
238+
foo(
239+
left: 1
240+
)
241+
foo(
242+
lowerThan: 1
243+
)
244+
foo(
245+
mutating: 1
246+
)
247+
foo(
248+
none: 1
249+
)
250+
foo(
251+
nonmutating: 1
252+
)
253+
foo(
254+
optional: 1
255+
)
256+
foo(
257+
override: 1
258+
)
259+
foo(
260+
postfix: 1
261+
)
262+
foo(
263+
precedence: 1
264+
)
265+
foo(
266+
precedencegroup: 1
267+
)
268+
foo(
269+
prefix: 1
270+
)
271+
foo(
272+
required: 1
273+
)
274+
foo(
275+
right: 1
276+
)
277+
foo(
278+
set: 1
279+
)
280+
foo(
281+
unowned: 1
282+
)
283+
foo(
284+
weak: 1
285+
)
286+
foo(
287+
willSet: 1
288+
)
289+
}
290+
36291
// Unicode identifiers
37292

38293
let こんにちは = 你好 +

0 commit comments

Comments
 (0)