2017-02-02 15:49:51 -05:00
|
|
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vue') == -1
|
|
|
|
|
|
|
|
" Vim indent file
|
|
|
|
" Language: Vue.js
|
|
|
|
" Maintainer: Eduardo San Martin Morote
|
|
|
|
" Author: Adriaan Zonnenberg
|
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
if exists('b:did_indent')
|
2017-02-02 15:49:51 -05:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
function! s:get_indentexpr(language)
|
2017-02-02 15:49:51 -05:00
|
|
|
unlet! b:did_indent
|
2017-05-17 05:07:28 -04:00
|
|
|
execute 'runtime! indent/' . a:language . '.vim'
|
|
|
|
return &indentexpr
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" The order is important here, tags without attributes go last.
|
|
|
|
" HTML is left out, it will be used when there is no match.
|
|
|
|
let s:languages = [
|
|
|
|
\ { 'name': 'pug', 'pairs': ['<template lang="pug"', '</template>'] },
|
|
|
|
\ { 'name': 'stylus', 'pairs': ['<style lang="stylus"', '</style>'] },
|
|
|
|
\ { 'name': 'css', 'pairs': ['<style', '</style>'] },
|
|
|
|
\ { 'name': 'coffee', 'pairs': ['<script lang="coffee"', '</script>'] },
|
|
|
|
\ { 'name': 'javascript', 'pairs': ['<script', '</script>'] },
|
|
|
|
\ ]
|
|
|
|
|
2017-09-27 13:57:29 -04:00
|
|
|
for s:language in s:languages
|
2017-05-17 05:07:28 -04:00
|
|
|
" Set 'indentexpr' if the user has an indent file installed for the language
|
2017-09-27 13:57:29 -04:00
|
|
|
if strlen(globpath(&rtp, 'indent/'. s:language.name .'.vim'))
|
|
|
|
let s:language.indentexpr = s:get_indentexpr(s:language.name)
|
2017-05-17 05:07:28 -04:00
|
|
|
endif
|
2017-02-02 15:49:51 -05:00
|
|
|
endfor
|
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
let s:html_indent = s:get_indentexpr('html')
|
|
|
|
|
2017-02-02 15:49:51 -05:00
|
|
|
let b:did_indent = 1
|
|
|
|
|
|
|
|
setlocal indentexpr=GetVueIndent()
|
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
if exists('*GetVueIndent')
|
2017-02-02 15:49:51 -05:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
function! GetVueIndent()
|
2017-05-17 05:07:28 -04:00
|
|
|
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)
|
|
|
|
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)'
|
|
|
|
return 0
|
|
|
|
endif
|
2017-02-02 15:49:51 -05:00
|
|
|
else
|
2017-05-17 05:07:28 -04:00
|
|
|
" Couldn't find language, fall back to html
|
|
|
|
execute 'let indent = ' . s:html_indent
|
2017-02-02 15:49:51 -05:00
|
|
|
endif
|
|
|
|
|
2017-05-17 05:07:28 -04:00
|
|
|
return indent
|
2017-02-02 15:49:51 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
endif
|