Skip to content

Commit 390556f

Browse files
committed
Add highlight for function guards.
Highlight [the functions](http://elixir-lang.org/getting-started/case-cond-and-if.html#expressions-in-guard-clauses) that can be used in guards.
1 parent 7ba09a8 commit 390556f

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GEM
2-
remote: http://rubygems.org/
2+
remote: https://rubygems.org/
33
specs:
44
diff-lcs (1.2.4)
55
rspec (2.13.0)

spec/syntax/guard_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe "Guard syntax" do
4+
it "guard in function" do
5+
<<-EOF
6+
def fun(a) when is_atom(a) do
7+
end
8+
EOF
9+
.should include_elixir_syntax('elixirKeyword', 'is_atom')
10+
end
11+
12+
it "guard in case" do
13+
<<-EOF
14+
case
15+
a when is_atom(a) -> {:ok, a}
16+
end
17+
EOF
18+
.should include_elixir_syntax('elixirKeyword', 'is_atom')
19+
end
20+
21+
it "does not highlight outside guards" do
22+
<<-EOF
23+
if is_atom(a) do
24+
{:ok, a}
25+
end
26+
EOF
27+
.should_not include_elixir_syntax('elixirKeyword', 'is_atom')
28+
end
29+
end

syntax/elixir.vim

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ syn cluster elixirNotTop contains=@elixirRegexSpecial,@elixirStringContained,@el
1515
syn match elixirComment '#.*' contains=elixirTodo
1616
syn keyword elixirTodo FIXME NOTE TODO OPTIMIZE XXX HACK contained
1717

18-
syn keyword elixirKeyword is_atom is_binary is_bitstring is_boolean is_float is_function is_integer is_list is_map is_number is_pid is_port is_record is_reference is_tuple is_exception
1918
syn keyword elixirKeyword case when cond for if unless try receive send
2019
syn keyword elixirKeyword exit raise throw after rescue catch else do end
2120
syn keyword elixirKeyword quote unquote super
2221

22+
" Functions used on guards
23+
syn keyword elixirKeyword contained is_atom is_binary is_bitstring is_boolean
24+
syn keyword elixirKeyword contained is_float is_function is_integer is_list
25+
syn keyword elixirKeyword contained is_map is_number is_pid is_port is_record
26+
syn keyword elixirKeyword contained is_reference is_tuple is_exception abs
27+
syn keyword elixirKeyword contained bit_size byte_size div elem hd length
28+
syn keyword elixirKeyword contained map_size node rem round tl trunc tuple_size
29+
30+
syn match elixirGuard '.*when.*' contains=ALLBUT,@elixirNotTop
31+
2332
syn keyword elixirInclude import require alias use
2433

2534
syn keyword elixirSelf self

0 commit comments

Comments
 (0)