Skip to content

Commit af713e6

Browse files
committed
Merge pull request #325 from elixir-lang/handle-dots-in-indentations
Fix indentation of statement keywords on dot call
2 parents 5383308 + 4fe8314 commit af713e6

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

elixir-smie.el

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,15 @@
277277
((looking-at elixir-smie--operator-regexp)
278278
(goto-char (match-end 0))
279279
"OP")
280-
(t
281-
(let ((token (smie-default-forward-token)))
282-
(unless (elixir-smie-empty-string-p token)
283-
token)))))
280+
(t (let ((token (smie-default-forward-token)))
281+
(unless (or (elixir-smie-empty-string-p token)
282+
(elixir-smie--at-dot-call))
283+
token)))))
284+
285+
(defun elixir-smie--at-dot-call ()
286+
(and (eq ?w (char-syntax (following-char)))
287+
(eq (char-before) ?.)
288+
(not (eq (char-before (1- (point))) ?.))))
284289

285290
(defun elixir-smie-backward-token ()
286291
(let ((pos (point)))
@@ -303,7 +308,10 @@
303308
((looking-back elixir-smie--operator-regexp (- (point) 3) t)
304309
(goto-char (match-beginning 0))
305310
"OP")
306-
(t (smie-default-backward-token)))))
311+
(t (let ((token (smie-default-backward-token)))
312+
(unless (or (elixir-smie-empty-string-p token)
313+
(elixir-smie--at-dot-call))
314+
token))))))
307315

308316
(defun verbose-elixir-smie-rules (kind token)
309317
(let ((value (elixir-smie-rules kind token)))
@@ -574,7 +582,7 @@
574582
;; ...
575583
((and (not (smie-rule-hanging-p))
576584
(smie-rule-parent-p "do"))
577-
elixir-smie-indent-basic)
585+
elixir-smie-indent-basic)
578586
((and (not (smie-rule-hanging-p))
579587
(smie-rule-parent-p "MATCH-STATEMENT-DELIMITER"))
580588
(smie-rule-parent))
@@ -707,7 +715,7 @@
707715
(let ((pos (point)))
708716
(parse-partial-sexp 1 pos)))))
709717
(and (looking-at "\"\"\"")
710-
(match-beginning 0)))))
718+
(match-beginning 0)))))
711719

712720
(defun elixir-smie--previous-line-empty-p ()
713721
"Return non-nil if the previous line is blank."

test/elixir-mode-indentation-test.el

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ else: :bar"
377377
)
378378

379379
(elixir-def-indentation-test indent-if-when-condition-is-a-named-function-on-a-module
380-
(:expected-result :failed :tags '(indentation))
381-
;; https://github.com/elixir-lang/emacs-elixir/issues/323
380+
(:tags '(indentation))
382381
"defmodule Whois do
383382
def lookup2(domain) do
384383
if Server.for(domain) do
@@ -1575,8 +1574,7 @@ end"
15751574
end")
15761575

15771576
(elixir-def-indentation-test indent-case-when-condition-is-a-named-function-on-a-module
1578-
(:expected-result :failed :tags '(indentation))
1579-
;; https://github.com/elixir-lang/emacs-elixir/issues/323
1577+
(:tags '(indentation))
15801578
"defmodule Whois do
15811579
def lookup1(domain) do
15821580
case Server.for(domain) do

0 commit comments

Comments
 (0)