Skip to content

Commit 7adebea

Browse files
committed
fixes Wrong colour for keyword "length" in keyword list #206
Note that this also removes highlighting in some places that I found it to be useful (e.g. using `is_pid` in a function body) but that can be discussed in a different PR
1 parent 9afaff4 commit 7adebea

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

spec/indent/blocks_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def name(param) do
4747
end
4848

4949
it 'guard in function' do
50-
expect(<<~EOF).to include_elixir_syntax('elixirKeyword', 'is_atom')
50+
expect(<<~EOF).to include_elixir_syntax('elixirKernelFunction', 'is_atom')
5151
defmodule M do
5252
def fun(a) when is_atom(a) do
5353
1

spec/syntax/guard_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
describe 'Guard syntax' do
66
it 'guard in function' do
7-
expect(<<~EOF).to include_elixir_syntax('elixirKeyword', 'is_atom')
7+
expect(<<~EOF).to include_elixir_syntax('elixirKernelFunction', 'is_atom')
88
def fun(a) when is_atom(a) do
99
end
1010
EOF
1111
end
1212

1313
it 'guard in case' do
14-
expect(<<~EOF).to include_elixir_syntax('elixirKeyword', 'is_atom')
14+
expect(<<~EOF).to include_elixir_syntax('elixirKernelFunction', 'is_atom')
1515
case
1616
a when is_atom(a) -> {:ok, a}
1717
end
1818
EOF
1919
end
2020

2121
it 'does not highlight outside guards' do
22-
expect(<<~EOF).not_to include_elixir_syntax('elixirKeyword', 'is_atom')
22+
expect(<<~EOF).not_to include_elixir_syntax('elixirKernelFunction', 'is_atom')
2323
if is_atom(a) do
2424
{:ok, a}
2525
end

spec/syntax/kernel_function_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'Kernel function syntax' do
6+
it 'kernel function used as an atom key in a keyword list contained in a block' do
7+
expect(<<~EOF).not_to include_elixir_syntax('elixirKernelFunction', 'length')
8+
do
9+
plug Plug.Parsers,
10+
parsers: [:urlencoded, :multipart, :json],
11+
pass: ["*/*"],
12+
json_decoder: Poison,
13+
length: 400_000_000
14+
EOF
15+
end
16+
17+
it 'kernel function used as a guard' do
18+
expect(<<~'EOF').to include_elixir_syntax('elixirKernelFunction', 'length')
19+
def hello(name) when length(name) > 20 do
20+
IO.puts "hello #{name}, you big boy"
21+
end
22+
EOF
23+
end
24+
25+
it 'kernel function used in a function body' do
26+
expect(<<~'EOF').not_to include_elixir_syntax('elixirKernelFunction', 'length')
27+
def say_size(chars) do
28+
size = length(chars)
29+
IO.puts "you gave me #{size} chars"
30+
end
31+
EOF
32+
end
33+
34+
it 'kernel function used as top-level' do
35+
expect(<<~'EOF').not_to include_elixir_syntax('elixirKernelFunction', 'length')
36+
length(chars)
37+
EOF
38+
end
39+
end

syntax/elixir.vim

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ syn match elixirKeyword '\(\.\)\@<!\<\(for\|case\|when\|with\|cond\|if\|unless\|
2222
syn match elixirKeyword '\(\.\)\@<!\<\(exit\|raise\|throw\|after\|rescue\|catch\|else\)\>'
2323
syn match elixirKeyword '\(\.\)\@<!\<\(quote\|unquote\|super\|spawn\|spawn_link\|spawn_monitor\)\>'
2424

25-
" Functions used on guards
26-
syn keyword elixirKeyword contained is_atom is_binary is_bitstring is_boolean
27-
syn keyword elixirKeyword contained is_float is_function is_integer is_list
28-
syn keyword elixirKeyword contained is_map is_nil is_number is_pid is_port
29-
syn keyword elixirKeyword contained is_record is_reference is_tuple is_exception
30-
syn keyword elixirKeyword contained abs bit_size byte_size div elem hd length
31-
syn keyword elixirKeyword contained map_size node rem round tl trunc tuple_size
25+
" Kernel functions
26+
syn match elixirKernelFunction contained containedin=elixirGuard '\<\(is_atom\|is_binary\|is_bitstring\|is_boolean\|is_float\|is_function\|is_integer\|is_list\|is_map\|is_nil\|is_number\|is_pid\|is_port\)\>\([ (]\)\@='
27+
syn match elixirKernelFunction contained containedin=elixirGuard '\<\(is_record\|is_reference\|is_tuple\|is_exception\|abs\|bit_size\|byte_size\|div\|elem\|hd\|length\|map_size\|node\|rem\|round\|tl\|trunc\|tuple_size\)\>\([ (]\)\@='
3228

3329
syn match elixirGuard '.*when.*' contains=ALLBUT,@elixirNotTop
3430

@@ -83,14 +79,14 @@ syn region elixirString matchgroup=elixirStringDelimiter start=+\z('\)+ end=+
8379
syn region elixirString matchgroup=elixirStringDelimiter start=+\z("\)+ end=+\z1+ skip=+\\\\\|\\\z1+ contains=@elixirStringContained
8480
syn region elixirString matchgroup=elixirStringDelimiter start=+\z('''\)+ end=+^\s*\z1+ skip=+'\|\\\\+ contains=@elixirStringContained
8581
syn region elixirString matchgroup=elixirStringDelimiter start=+\z("""\)+ end=+^\s*\z1+ skip=+"\|\\\\+ contains=@elixirStringContained
86-
syn region elixirInterpolation matchgroup=elixirInterpolationDelimiter start="#{" end="}" contained contains=ALLBUT,elixirComment,@elixirNotTop
82+
syn region elixirInterpolation matchgroup=elixirInterpolationDelimiter start="#{" end="}" contained contains=ALLBUT,elixirKernelFunction,elixirComment,@elixirNotTop
8783

8884
syn match elixirAtomInterpolated ':\("\)\@=' contains=elixirString
8985
syn match elixirString "\(\w\)\@<!?\%(\\\(x\d{1,2}\|\h{1,2}\h\@!\>\|0[0-7]{0,2}[0-7]\@!\>\|[^x0MC]\)\|(\\[MC]-)+\w\|[^\s\\]\)"
9086

91-
syn region elixirBlock matchgroup=elixirBlockDefinition start="\<do\>:\@!" end="\<end\>" contains=ALLBUT,@elixirNotTop fold
92-
syn region elixirElseBlock matchgroup=elixirBlockDefinition start="\<else\>:\@!" end="\<end\>" contains=ALLBUT,@elixirNotTop fold
93-
syn region elixirAnonymousFunction matchgroup=elixirBlockDefinition start="\<fn\>" end="\<end\>" contains=ALLBUT,@elixirNotTop fold
87+
syn region elixirBlock matchgroup=elixirBlockDefinition start="\<do\>:\@!" end="\<end\>" contains=ALLBUT,elixirKernelFunction,@elixirNotTop fold
88+
syn region elixirElseBlock matchgroup=elixirBlockDefinition start="\<else\>:\@!" end="\<end\>" contains=ALLBUT,elixirKernelFunction,@elixirNotTop fold
89+
syn region elixirAnonymousFunction matchgroup=elixirBlockDefinition start="\<fn\>" end="\<end\>" contains=ALLBUT,elixirKernelFunction,@elixirNotTop fold
9490

9591
syn region elixirArguments start="(" end=")" contained contains=elixirOperator,elixirAtom,elixirPseudoVariable,elixirAlias,elixirBoolean,elixirVariable,elixirUnusedVariable,elixirNumber,elixirDocString,elixirAtomInterpolated,elixirRegex,elixirString,elixirStringDelimiter,elixirRegexDelimiter,elixirInterpolationDelimiter,elixirSigilDelimiter
9692

@@ -172,6 +168,7 @@ hi def link elixirInclude Include
172168
hi def link elixirComment Comment
173169
hi def link elixirTodo Todo
174170
hi def link elixirKeyword Keyword
171+
hi def link elixirKernelFunction Keyword
175172
hi def link elixirOperator Operator
176173
hi def link elixirAtom Constant
177174
hi def link elixirPseudoVariable Constant

0 commit comments

Comments
 (0)