Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Autocommand bodies with continued lines of lists/dicts end up with pipes and multiple backslashes #1

Open
deathlyfrantic opened this issue Jun 14, 2019 · 1 comment

Comments

@deathlyfrantic
Copy link
Owner

Example (from vim-endwise):

autocmd FileType lua let b:endwise = {
      \ 'addition': 'end',
      \ 'words': 'function,do,then',
      \ 'pattern': '^\s*\zs\%(\%(local\s\+\)\=function\)\>\%(.*\<end\>\)\@!\|\<\%(then\|do\)\ze\s*$',
      \ 'syngroups': 'luaFunction,luaStatement,luaCond'}

This gets formatted as:

autocmd FileType lua
      \ let b:endwise = { |
      \       \ 'addition': 'end', |
      \       \ 'words': 'function,do,then', |
      \       \ 'pattern': |
      \       \ '^\s*\zs\%(\%(local\s\+\)\=function\)\>\%(.*\<end\>\)\@!\|\<\%(then\|do\)\ze\s*$', |
      \       \ 'syngroups': 'luaFunction,luaStatement,luaCond', |
      \       \ }

Haven't narrowed this down yet but probably it's because formatting an autocommand in f_node() is pretty janky and assumes all the lines of the body are individual expressions. Likely need to add a f_autocmd() method to handle this.

@deathlyfrantic
Copy link
Owner Author

This looks like two different problems. The first, here:

vimlfmt/src/formatter.rs

Lines 321 to 327 in cc80dea

trimmed.push(
self.output
.iter()
.map(|line| line.trim())
.collect::<Vec<&str>>()
.join(" | "),
);
where all output lines are joined with a pipe.

The second, more generally, is continue_line() always adds a backslash, even though no more than one is necessary. So there needs to be some logic to handle that case - maybe a line_continued flag or something.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant