@@ -198,24 +198,41 @@ Return non-nil if any line breaks were skipped."
198
198
token)
199
199
(save-excursion
200
200
(block nil
201
- (while (and (not (= (point ) (point-max ))) (not (string= " " token)) (not (or (string= " \n " token) (string= " ;" token))))
201
+ (while
202
+ (and
203
+ ; ; Cursor is not at the end of the buffer...
204
+ (not (= (point ) (point-max )))
205
+ ; ; ...and the current token is not an empty string...
206
+ (not (string= " " token))
207
+ ; ; ...nor a newline nor a semicolon.
208
+ (not (or (string= " \n " token) (string= " ;" token))))
202
209
(setq token (elixir-smie-next-token-no-lookaround t nil ))
210
+ ; ; If we're at the top level and the token is "->",
211
+ ; ; return t
203
212
(cond ((and (= level 0 ) (string= " ->" token))
204
213
(return t ))
214
+ ; ; If token is "do" or "fn", increment level
205
215
((find token '(" do" " fn" ) :test 'string= )
206
216
(incf level))
217
+ ; ; If token is "end", decrement level
207
218
((string= token " end" )
208
219
(decf level)))))))
209
220
; ; Scan behind:
210
221
(let (token)
211
222
(save-excursion
212
223
(block nil
213
- (while (and (not (= (point ) (point-min ))) (not (string= " " token)) (not (string= " do" token)) (not (string= " fn" token)))
224
+ (while
225
+ (and
226
+ ; ; Cursor is not at the beginning of buffer...
227
+ (not (= (point ) (point-min )))
228
+ ; ; ...and token is neither empty string, nor "do"/"fn"
229
+ (not (string= " " token))
230
+ (not (string= " do" token))
231
+ (not (string= " fn" token)))
214
232
(setq token (elixir-smie-next-token-no-lookaround nil nil ))
215
233
(when (string= " ->" token)
216
234
(return t )))
217
- (when (or (string= token " do" ))
218
- t )))))
235
+ (when (string= token " do" ) t )))))
219
236
" MATCH-STATEMENT-DELIMITER"
220
237
current-token))))
221
238
@@ -241,7 +258,7 @@ Return non-nil if any line breaks were skipped."
241
258
(" try" " do" statements " catch" match-statements " end" )
242
259
(" try" " do" statements " end" )
243
260
(" case" non-block-expr " do" match-statements " end" )
244
- (" function " " do" match- statements " end" )
261
+ (" def " non-block-expr " do" statements " end" )
245
262
(non-block-expr " do" statements " end" )
246
263
(expr)
247
264
)
@@ -258,7 +275,13 @@ Return non-nil if any line breaks were skipped."
258
275
(match-statement))
259
276
(match-statement
260
277
(non-block-expr " ->" statements)))
261
- '((assoc " DOT" ) (assoc " if" ) (assoc " do:" ) (assoc " else:" ) (assoc " COMMA" ) (assoc " OP" ) (assoc " ->" " ;" )))))
278
+ '((assoc " DOT" )
279
+ (assoc " if" )
280
+ (assoc " do:" )
281
+ (assoc " else:" )
282
+ (assoc " COMMA" )
283
+ (assoc " OP" )
284
+ (assoc " ->" " ;" )))))
262
285
263
286
(defvar elixir-smie-indent-basic 2 )
264
287
@@ -281,7 +304,8 @@ Return non-nil if any line breaks were skipped."
281
304
(`(:after . " OP" )
282
305
(unless (smie-rule-sibling-p )
283
306
elixir-smie-indent-basic))
284
- (`(:before . " OP" )
307
+ (`(:before . " def" ) elixir-smie-indent-basic)
308
+ (`(:before . " OP" )
285
309
; ; FIXME: Issue #5: This should prevent comments on lines before
286
310
; ; continuation lines from causing indentation messed-upness, but
287
311
; ; for some reason SMIE doesn't look this far when there's a
@@ -292,17 +316,17 @@ Return non-nil if any line breaks were skipped."
292
316
elixir-smie-indent-basic))
293
317
(`(, _ . ,(or `" COMMA" )) (smie-rule-separator kind))
294
318
(`(:after . " =" ) elixir-smie-indent-basic)
319
+ (`(:after . " end" ) 0 )
295
320
(`(:after . ,(or `" do" ))
296
321
elixir-smie-indent-basic)
297
- (`(:list-intro . ,(or `" do" ))
298
- t )))
322
+ (`(:list-intro . ,(or `" do" )) t )))
299
323
300
324
(define-minor-mode elixir-smie-mode
301
325
" SMIE-based indentation and syntax for Elixir"
302
326
nil nil nil nil
303
327
(set (make-local-variable 'comment-start ) " # " )
304
328
(set (make-local-variable 'comment-end ) " " )
305
- (smie-setup elixir-smie-grammar 'elixir-smie-rules ; 'verbose-elixir-smie-rules
329
+ (smie-setup elixir-smie-grammar 'elixir-smie-rules
306
330
:forward-token 'elixir-smie-forward-token
307
331
:backward-token 'elixir-smie-backward-token ))
308
332
0 commit comments