From f784bae336912dac6381ede089a0f524cfbbd2ac Mon Sep 17 00:00:00 2001 From: Andrew Haust Date: Sun, 23 Jun 2024 12:21:22 -0400 Subject: [PATCH 1/2] Handle nested `quote` blocks Fixes #502 --- autoload/elixir/indent.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/elixir/indent.vim b/autoload/elixir/indent.vim index 6611477..e9b05b2 100644 --- a/autoload/elixir/indent.vim +++ b/autoload/elixir/indent.vim @@ -379,7 +379,7 @@ endfunction " function, etc... so we need to first figure out what the innermost structure " is then forward execution to the proper handler function! elixir#indent#handle_inside_block(context) - let start_pattern = '\C\%(\\|\\|\\|\\|\\|\\|\\|{\|\[\|(\)' + let start_pattern = '\C\%(\\|\\|\\|\\|\\|\\|\\|\\|{\|\[\|(\)' let end_pattern = '\C\%(\\|\]\|}\|)\)' " hack - handle do: better 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) let never_match = '' let config = { \'f': {'aligned_clauses': s:keyword('end'), 'pattern_match_clauses': never_match}, + \'q': {'aligned_clauses': s:keyword('end'), 'pattern_match_clauses': never_match}, \'c': {'aligned_clauses': s:keyword('end'), 'pattern_match_clauses': never_match}, \'t': {'aligned_clauses': s:keyword('end\|catch\|rescue\|after\|else'), 'pattern_match_clauses': s:keyword('catch\|rescue\|else')}, \'r': {'aligned_clauses': s:keyword('end\|after'), 'pattern_match_clauses': s:keyword('after')}, From a89e05fea67439c694a9d32b882ac0c58ceffefa Mon Sep 17 00:00:00 2001 From: Andrew Haust Date: Sun, 23 Jun 2024 19:38:57 -0400 Subject: [PATCH 2/2] Add test --- spec/indent/quote_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 spec/indent/quote_spec.rb diff --git a/spec/indent/quote_spec.rb b/spec/indent/quote_spec.rb new file mode 100644 index 0000000..2801220 --- /dev/null +++ b/spec/indent/quote_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Indenting quote statements' do + i <<~EOF + defmacro foo do + quote do + unquote(foo) + end + end + EOF + + i <<~EOF + defmacro foo do + if 1 = 1 do + quote do + unquote(foo) + end + end + end + EOF +end