Skip to content

Tokenize trailing whitespace properly. Fixes #97 #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions elixir-smie.el
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
">=" "<" ">" "&&" "||" "<>" "++" "--" "//"
"/>" "=~" "|>" "->")))

(defvar elixir-smie--spaces-til-eol-regexp
(rx (and (1+ space) eol))
"Regex representing one or more whitespace characters concluding with eol.")

(defvar elixir-smie-indent-basic 2)

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

(defun elixir-smie-forward-token ()
(cond
;; If there is nothing but whitespace between the last token and eol, emit
;; a semicolon.
((looking-at elixir-smie--spaces-til-eol-regexp)
(goto-char (match-end 0))
";")
((and (looking-at "[\n#]") (elixir-smie--implicit-semi-p))
(if (eolp) (forward-char 1) (forward-comment 1))
";")
Expand Down
30 changes: 30 additions & 0 deletions test/elixir-mode-indentation-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,33 @@ end"
def foo do #comment
:bar
end")

(elixir-def-indentation-test indent-after-require-Record
()
;; Mind the significant whitespace after `Record' in each case. There should
;; be two spaces after `Record', otherwise this test is meaningless.
"
defmodule RSS do
require Record

def zip(list1, list2) when length(list1) == length(list2) do
x = 1
end
end"
"
defmodule RSS do
require Record

def zip(list1, list2) when length(list1) == length(list2) do
x = 1
end
end")

;; We don't want automatic whitespace cleanup here because of the significant
;; whitespace after `Record' above. By setting `whitespace-action' to nil,
;; `whitespace-mode' won't automatically clean up trailing whitespace (in my
;; config, anyway).

;;; Local Variables:
;;; whitespace-action: nil
;;; End: