Skip to content
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

Make languages & policies user-configurable #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

agriffis
Copy link

@agriffis agriffis commented Jun 24, 2018

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 messages 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.

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.
@agriffis
Copy link
Author

By the way, I think it would make a lot of sense for g:vue_indent_languages to eventually become g:vue_languages with a common structure for configuring indent/syntax simultaneously. I guess that raises the question of whether it's better to do that rather than merging this directly. Let me know what you think.

Copy link
Collaborator

@adriaanzon adriaanzon left a 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.
Copy link
Collaborator

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.

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

Successfully merging this pull request may close these issues.

2 participants