Skip to content

Commit ce7af6f

Browse files
committed
Merge pull request #156 from elixir-lang/indent-after-binary-sequence
Indent correct after binary sequence
2 parents 480d5a3 + 41d2412 commit ce7af6f

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
### Enhancements
66

7-
* [Indentation] indent correct after oneline `def ... do:` function
7+
* [Indentation] Ident correct after a binary sequence `<<1,2,3,4>>`.
8+
* [Indentation] Indent correct after oneline `def ... do:` function
89
* [Indentation] Correct behavior after last line in buffer. (#145)
910

1011
## v2.1.1 - 2014/12/24

elixir-smie.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@
144144
(rx (or "<<<" ">>>" "^^^" "~~~" "&&&" "|||" "===" "!==" "==" "!=" "<="
145145
"=" ">=" "<" ">" "&&" "||" "<>" "++" "--" "//" "/>" "=~" "|>")))
146146

147+
(defvar elixir-smie--binary-sequence-regexp
148+
(rx (or "<<" ">>")))
149+
147150
(defvar elixir-smie--block-operator-regexp
148151
(rx "->" (0+ nonl)))
149152

@@ -241,6 +244,9 @@
241244
((looking-back elixir-smie--block-operator-regexp (- (point) 3) t)
242245
(goto-char (match-beginning 0))
243246
"->")
247+
((looking-back elixir-smie--binary-sequence-regexp (- (point) 3) t)
248+
(goto-char (match-beginning 0))
249+
"OP")
244250
((looking-back elixir-smie--operator-regexp (- (point) 3) t)
245251
(goto-char (match-beginning 0))
246252
"OP")

test/elixir-mode-indentation-test.el

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,71 @@ defmodule Greeter do
850850
end
851851
end")
852852

853+
(elixir-def-indentation-test indent-binary-sequence
854+
(:tags '(indentation))
855+
"
856+
defmodule ExampleTest do
857+
test \"the truth\" do
858+
assert <<1,2>> == <<1,2>>
859+
assert 1 + 1 == 2
860+
end
861+
end"
862+
863+
"
864+
defmodule ExampleTest do
865+
test \"the truth\" do
866+
assert <<1,2>> == <<1,2>>
867+
assert 1 + 1 == 2
868+
end
869+
end")
870+
871+
(elixir-def-indentation-test indent-binary-sequence-inside-match-block/2
872+
(:expected-result :failed :tags '(indentation))
873+
"
874+
case asd do
875+
<<c1::5, c2::5, c3::5, c4::5, c5::5, c6::5, c7::2>> ->
876+
<<main::binary,
877+
enc.(c1)::8, enc.(c2)::8, enc.(c3)::8, enc.(c4)::8,
878+
enc.(c5)::8, enc.(c6)::8, enc.(bsl(c7, 3))::8, ?=>>
879+
<<c1::5, c2::5, c3::5, c4::5, c5::4>> ->
880+
<<main::binary,
881+
enc.(c1)::8, enc.(c2)::8, enc.(c3)::8, enc.(c4)::8,
882+
enc.(bsl(c5, 1))::8, ?=, ?=, ?=>>
883+
<<c1::5, c2::5, c3::5, c4::1>> ->
884+
<<main::binary,
885+
enc.(c1)::8, enc.(c2)::8, enc.(c3)::8, enc.(bsl(c4, 4))::8,
886+
?=, ?=, ?=, ?=>>
887+
<<c1::5, c2::3>> ->
888+
<<main::binary,
889+
enc.(c1)::8, enc.(bsl(c2, 2))::8, ?=, ?=,
890+
?=, ?=, ?=, ?=>>
891+
<<>> ->
892+
main
893+
end"
894+
895+
"
896+
case asd do
897+
<<c1::5, c2::5, c3::5, c4::5, c5::5, c6::5, c7::2>> ->
898+
<<main::binary,
899+
enc.(c1)::8, enc.(c2)::8, enc.(c3)::8, enc.(c4)::8,
900+
enc.(c5)::8, enc.(c6)::8, enc.(bsl(c7, 3))::8, ?=>>
901+
<<c1::5, c2::5, c3::5, c4::5, c5::4>> ->
902+
<<main::binary,
903+
enc.(c1)::8, enc.(c2)::8, enc.(c3)::8, enc.(c4)::8,
904+
enc.(bsl(c5, 1))::8, ?=, ?=, ?=>>
905+
<<c1::5, c2::5, c3::5, c4::1>> ->
906+
<<main::binary,
907+
enc.(c1)::8, enc.(c2)::8, enc.(c3)::8, enc.(bsl(c4, 4))::8,
908+
?=, ?=, ?=, ?=>>
909+
<<c1::5, c2::3>> ->
910+
<<main::binary,
911+
enc.(c1)::8, enc.(bsl(c2, 2))::8, ?=, ?=,
912+
?=, ?=, ?=, ?=>>
913+
<<>> ->
914+
main
915+
end")
916+
917+
853918
;; We don't want automatic whitespace cleanup here because of the significant
854919
;; whitespace after `Record' above. By setting `whitespace-action' to nil,
855920
;; `whitespace-mode' won't automatically clean up trailing whitespace (in my

0 commit comments

Comments
 (0)