Skip to content

Commit 8e20513

Browse files
committed
Some code cleanup.
1 parent a163037 commit 8e20513

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

elixir-smie.el

+17-9
Original file line numberDiff line numberDiff line change
@@ -200,30 +200,39 @@ Return non-nil if any line breaks were skipped."
200200
(block nil
201201
(while
202202
(and
203+
;; Cursor is not at the end of the buffer...
203204
(not (= (point) (point-max)))
205+
;; ...and the current token is not an empty string...
204206
(not (string= "" token))
207+
;; ...nor a newline nor a semicolon.
205208
(not (or (string= "\n" token) (string= ";" token))))
206209
(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
207212
(cond ((and (= level 0) (string= "->" token))
208213
(return t))
214+
;; If token is "do" or "fn", increment level
209215
((find token '("do" "fn") :test 'string=)
210216
(incf level))
217+
;; If token is "end", decrement level
211218
((string= token "end")
212219
(decf level)))))))
213220
;; Scan behind:
214221
(let (token)
215222
(save-excursion
216223
(block nil
217224
(while
218-
(and (not (= (point) (point-min)))
219-
(not (string= "" token))
220-
(not (string= "do" token))
221-
(not (string= "fn" token)))
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)))
222232
(setq token (elixir-smie-next-token-no-lookaround nil nil))
223233
(when (string= "->" token)
224234
(return t)))
225-
(when (or (string= token "do"))
226-
t)))))
235+
(when (string= token "do") t)))))
227236
"MATCH-STATEMENT-DELIMITER"
228237
current-token))))
229238

@@ -310,15 +319,14 @@ Return non-nil if any line breaks were skipped."
310319
(`(:after . "end") 0)
311320
(`(:after . ,(or `"do"))
312321
elixir-smie-indent-basic)
313-
(`(:list-intro . ,(or `"do"))
314-
t)))
322+
(`(:list-intro . ,(or `"do")) t)))
315323

316324
(define-minor-mode elixir-smie-mode
317325
"SMIE-based indentation and syntax for Elixir"
318326
nil nil nil nil
319327
(set (make-local-variable 'comment-start) "# ")
320328
(set (make-local-variable 'comment-end) "")
321-
(smie-setup elixir-smie-grammar 'elixir-smie-rules ; 'verbose-elixir-smie-rules
329+
(smie-setup elixir-smie-grammar 'elixir-smie-rules
322330
:forward-token 'elixir-smie-forward-token
323331
:backward-token 'elixir-smie-backward-token))
324332

test/elixir-mode-indentation-tests.el

+8-7
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
(insert indented)
1212
(should (equal indented ,expected-output)))))))
1313

14-
(elixir-def-indentation-test indents-use-dot-module-newline
15-
(:expected-result :failed) ; #41
16-
"
17-
defmodule Foo do
14+
;; Expected test failures indicates that the code tested by that test case is
15+
;; indeed broken. My intention is that while working on a specific problem,
16+
;; the failure expectation will be removed so that we know when the test case
17+
;; passes.
18+
(elixir-def-indentation-test indents-use-dot-module-newline ()
19+
"defmodule Foo do
1820
use GenServer.Behaviour
1921
2022
def foobar do
2123
if true, do: IO.puts \"yay\"
2224
end
2325
end"
24-
"
25-
defmodule Foo do
26+
"defmodule Foo do
2627
use GenServer.Behaviour
2728
2829
def foobar do
@@ -125,7 +126,7 @@ defmodule FooBar do
125126
end")
126127

127128
(elixir-def-indentation-test indents-after-empty-line
128-
(:expected-result :failed)
129+
(:expected-result :failed) ; #18
129130
"
130131
a = 2
131132

0 commit comments

Comments
 (0)