-
-
Notifications
You must be signed in to change notification settings - Fork 101
Make languages & policies user-configurable #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Add three configurables: - g:vue_indent_languages replaces s:languages. It can be configured before or after loading indent/vue.vim, and can be modified on the fly. - g:vue_indent_open_close_tags configures the policy for indenting open/close tags. It defaults to 0 which forces open/close tags for sections in a vue single-file component to the first column. - g:vue_indent_first_line configures the policy for indenting the first line after an open tag. It defaults to -1 which uses the autoindent default, i.e. the same column as the open tag. It will also preserve existing indentation when reindenting, which means that authors can use their preferred first line indentation without needing any special configuration. Additionally g:vue_indent_first_line can be overridden per-language by specifying a value for language.first_line. We use this for the 'html' language configuration to defer to html.vim for indenting the first line of an html template. Minor changes: - Since s:get_indentexpr is called lazily, it resets indentexpr before returning. - Use searchpair() to find the closing tag instead of a hard-coded list. - For development and debugging, it's possible to :echo GetVueIndent() which also enables error reporting and echom that are normally squelched when called as indentexpr. Note that although GetVueIndent() uses getpos('.') properly if line number isn't supplied, language indenters vary between getpos('.') and v:lnum, so this is mostly useful for debugging vue.vim's internal operation.
By the way, I think it would make a lot of sense for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the effort you have put into this!
I took a quick look at the changes, and left a comment at a line that caught my eye. I will have a further look at the changes in this PR sometime later.
function! GetVueIndent(...) | ||
let lnum = a:0 ? a:1 : getpos('.')[1] | ||
let indent = s:get_vue_indent(lnum) | ||
" NB: Strings compare as equal to 0, so 'html' == 0 is true, whoops. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use is#
here, which also checks if they are the same instance/type.
I think I will eventually s/==/is/g
the entire codebase.
Add three configurables:
g:vue_indent_languages
replacess:languages
. It can be configuredbefore or after loading
indent/vue.vim
, and can be modified on thefly.
g:vue_indent_open_close_tags
configures the policy for indentingopen/close tags. It defaults to 0 which forces open/close tags for
sections in a vue single-file component to the first column.
g:vue_indent_first_line
configures the policy for indenting thefirst line after an open tag. It defaults to -1 which uses the
autoindent default, i.e. the same column as the open tag. It will
also preserve existing indentation when reindenting, which means
that authors can use their preferred first line indentation without
needing any special configuration.
Additionally
g:vue_indent_first_line
can be overridden per-language byspecifying a value for
language.first_line
. We use this for the htmllanguage configuration to defer to
html.vim
for indenting the first lineof an html template.
Minor changes:
Since
s:get_indentexpr
is called lazily, it resetsindentexpr
beforereturning.
Use
searchpair()
to find the closing tag instead of a hard-coded list.For development and debugging, it's possible to
:echo GetVueIndent()
which also enables error reporting and messages that are normally
squelched when called as indentexpr. Note that although
GetVueIndent()
uses
getpos('.')
properly if line number isn't supplied, languageindenters vary between
getpos('.')
andv:lnum
, so this is mostlyuseful for debugging vue.vim's internal operation.