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

Fixes indent and adds g:vim_vue_indent_paths for runtime indent overrides #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions indent/vue.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ endif

function! s:get_indentexpr(language)
unlet! b:did_indent
execute 'runtime! indent/' . a:language . '.vim'
let path = ""
if exists('g:vim_vue_indent_paths') && has_key(g:vim_vue_indent_paths, a:language)
let path = g:vim_vue_indent_paths[a:language]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent files from plugins are already loaded by default. Isn't this working for you?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me there were cases where you can have multiple plugins with indent rules. For example, eclim and vim-javascript both contain javascript rules, however vim-javascript is far superior for me. The old method always resulted in eclim loading for vue files.

The other suggested fixes for using set ft= html.javascript or vice-versa worked, but also broke completion and other plugins.

else
let path = '/indent/' . a:language . '.vim'
endif
execute 'runtime! ' . path
return &indentexpr
endfunction

Expand All @@ -21,6 +27,7 @@ let s:languages = [
\ { 'name': 'css', 'pairs': ['<style', '</style>'] },
\ { 'name': 'coffee', 'pairs': ['<script lang="coffee"', '</script>'] },
\ { 'name': 'javascript', 'pairs': ['<script', '</script>'] },
\ { 'name': 'typescript', 'pairs': ['<script lang="typescript"', '</script>'] },
\ ]

for s:language in s:languages
Expand All @@ -34,31 +41,31 @@ let s:html_indent = s:get_indentexpr('html')

let b:did_indent = 1

setlocal indentexpr=GetVueIndent()
setlocal indentexpr=GetVueIndent(v:lnum)

if exists('*GetVueIndent')
finish
endif

function! GetVueIndent()
function! GetVueIndent(lnum)
for language in s:languages
let opening_tag_line = searchpair(language.pairs[0], '', language.pairs[1], 'bWr')

if opening_tag_line
execute 'let indent = ' . get(language, 'indentexpr', -1)
let indent = language.indentexpr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get() was being used here to return -1 (which means "do not change the indentation") when the indent file for that language is not present.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly I couldn't tell that this actually affected anything when I changed it-- tested it with missing indent files

break
endif
endfor

if exists('l:indent')
if (opening_tag_line == prevnonblank(v:lnum - 1) || opening_tag_line == v:lnum)
\ || getline(v:lnum) =~ '\v^\s*\</(script|style|template)'
if (opening_tag_line == prevnonblank(a:lnum - 1) || opening_tag_line == a:lnum)
\ || getline(a:lnum) =~ '\v^\s*\</(script|style|template)'
return 0
endif
else
" Couldn't find language, fall back to html
execute 'let indent = ' . s:html_indent
let indent = s:html_indent
endif

return indent
let g:vim_vue_last_indentexpr = indent
execute 'let g:vim_vue_result = ' . indent
return g:vim_vue_result
endfunction