Skip to content

Commit 23a75c4

Browse files
committed
Merge pull request #99 from elixir-lang/tokenize-whitespace-eol
Tokenize trailing whitespace properly. Fixes #97
2 parents 0ed9cf1 + 193d916 commit 23a75c4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

elixir-smie.el

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
">=" "<" ">" "&&" "||" "<>" "++" "--" "//"
8181
"/>" "=~" "|>" "->")))
8282

83+
(defvar elixir-smie--spaces-til-eol-regexp
84+
(rx (and (1+ space) eol))
85+
"Regex representing one or more whitespace characters concluding with eol.")
86+
8387
(defvar elixir-smie-indent-basic 2)
8488

8589
(defmacro elixir-smie-debug (message &rest format-args)
@@ -94,6 +98,11 @@
9498

9599
(defun elixir-smie-forward-token ()
96100
(cond
101+
;; If there is nothing but whitespace between the last token and eol, emit
102+
;; a semicolon.
103+
((looking-at elixir-smie--spaces-til-eol-regexp)
104+
(goto-char (match-end 0))
105+
";")
97106
((and (looking-at "[\n#]") (elixir-smie--implicit-semi-p))
98107
(if (eolp) (forward-char 1) (forward-comment 1))
99108
";")

test/elixir-mode-indentation-tests.el

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,3 +514,33 @@ end"
514514
def foo do #comment
515515
:bar
516516
end")
517+
518+
(elixir-def-indentation-test indent-after-require-Record
519+
()
520+
;; Mind the significant whitespace after `Record' in each case. There should
521+
;; be two spaces after `Record', otherwise this test is meaningless.
522+
"
523+
defmodule RSS do
524+
require Record
525+
526+
def zip(list1, list2) when length(list1) == length(list2) do
527+
x = 1
528+
end
529+
end"
530+
"
531+
defmodule RSS do
532+
require Record
533+
534+
def zip(list1, list2) when length(list1) == length(list2) do
535+
x = 1
536+
end
537+
end")
538+
539+
;; We don't want automatic whitespace cleanup here because of the significant
540+
;; whitespace after `Record' above. By setting `whitespace-action' to nil,
541+
;; `whitespace-mode' won't automatically clean up trailing whitespace (in my
542+
;; config, anyway).
543+
544+
;;; Local Variables:
545+
;;; whitespace-action: nil
546+
;;; End:

0 commit comments

Comments
 (0)