Skip to content

Commit 71841da

Browse files
authored
Merge pull request #572 from sodapopcan/handle-quote-indent
Handle nested `quote` blocks
2 parents 6dd03f8 + a89e05f commit 71841da

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

autoload/elixir/indent.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ endfunction
379379
" function, etc... so we need to first figure out what the innermost structure
380380
" is then forward execution to the proper handler
381381
function! elixir#indent#handle_inside_block(context)
382-
let start_pattern = '\C\%(\<with\>\|\<if\>\|\<case\>\|\<cond\>\|\<try\>\|\<receive\>\|\<fn\>\|{\|\[\|(\)'
382+
let start_pattern = '\C\%(\<with\>\|\<if\>\|\<case\>\|\<cond\>\|\<try\>\|\<receive\>\|\<fn\>\|\<quote\>\|{\|\[\|(\)'
383383
let end_pattern = '\C\%(\<end\>\|\]\|}\|)\)'
384384
" hack - handle do: better
385385
let block_info = searchpairpos(start_pattern, '', end_pattern, 'bnW', "line('.') == " . line('.') . " || elixir#indent#searchpair_back_skip() || getline(line('.')) =~ 'do:'", max([0, a:context.lnum - g:elixir_indent_max_lookbehind]))
@@ -394,6 +394,7 @@ function! elixir#indent#handle_inside_block(context)
394394
let never_match = ''
395395
let config = {
396396
\'f': {'aligned_clauses': s:keyword('end'), 'pattern_match_clauses': never_match},
397+
\'q': {'aligned_clauses': s:keyword('end'), 'pattern_match_clauses': never_match},
397398
\'c': {'aligned_clauses': s:keyword('end'), 'pattern_match_clauses': never_match},
398399
\'t': {'aligned_clauses': s:keyword('end\|catch\|rescue\|after\|else'), 'pattern_match_clauses': s:keyword('catch\|rescue\|else')},
399400
\'r': {'aligned_clauses': s:keyword('end\|after'), 'pattern_match_clauses': s:keyword('after')},

spec/indent/quote_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'Indenting quote statements' do
6+
i <<~EOF
7+
defmacro foo do
8+
quote do
9+
unquote(foo)
10+
end
11+
end
12+
EOF
13+
14+
i <<~EOF
15+
defmacro foo do
16+
if 1 = 1 do
17+
quote do
18+
unquote(foo)
19+
end
20+
end
21+
end
22+
EOF
23+
end

0 commit comments

Comments
 (0)