diff options
Diffstat (limited to '')
| -rw-r--r-- | ftdetect/polyglot.vim | 244 | 
1 files changed, 121 insertions, 123 deletions
| diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 9408c288..aed797ab 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -1777,160 +1777,158 @@ au BufNewFile,BufRead,StdinReadPost *    \ | call polyglot#Heuristics() | endif -if v:version < 700 || &cp -  finish -endif - +if !has_key(s:disabled_packages, 'helm') -" Code below re-implements sleuth for vim-polyglot -let g:loaded_sleuth = 1 +  " Code below re-implements sleuth for vim-polyglot +  let g:loaded_sleuth = 1 -" Makes shiftwidth to be synchronized with tabstop by default -if &shiftwidth == &tabstop -  let &shiftwidth = 0 -endif - -function! s:guess(lines) abort -  let options = {} -  let ccomment = 0 -  let podcomment = 0 -  let triplequote = 0 -  let backtick = 0 -  let xmlcomment = 0 -  let heredoc = '' -  let minindent = 10 -  let spaces_minus_tabs = 0 +  " Makes shiftwidth to be synchronized with tabstop by default +  if &shiftwidth == &tabstop +    let &shiftwidth = 0 +  endif -  for line in a:lines -    if !len(line) || line =~# '^\W*$' -      continue -    endif +  function! s:guess(lines) abort +    let options = {} +    let ccomment = 0 +    let podcomment = 0 +    let triplequote = 0 +    let backtick = 0 +    let xmlcomment = 0 +    let heredoc = '' +    let minindent = 10 +    let spaces_minus_tabs = 0 + +    for line in a:lines +      if !len(line) || line =~# '^\W*$' +        continue +      endif -    if line =~# '^\s*/\*' -      let ccomment = 1 -    endif -    if ccomment -      if line =~# '\*/' -        let ccomment = 0 +      if line =~# '^\s*/\*' +        let ccomment = 1 +      endif +      if ccomment +        if line =~# '\*/' +          let ccomment = 0 +        endif +        continue        endif -      continue -    endif -    if line =~# '^=\w' -      let podcomment = 1 -    endif -    if podcomment -      if line =~# '^=\%(end\|cut\)\>' -        let podcomment = 0 +      if line =~# '^=\w' +        let podcomment = 1 +      endif +      if podcomment +        if line =~# '^=\%(end\|cut\)\>' +          let podcomment = 0 +        endif +        continue        endif -      continue -    endif -    if triplequote -      if line =~# '^[^"]*"""[^"]*$' -        let triplequote = 0 +      if triplequote +        if line =~# '^[^"]*"""[^"]*$' +          let triplequote = 0 +        endif +        continue +      elseif line =~# '^[^"]*"""[^"]*$' +        let triplequote = 1        endif -      continue -    elseif line =~# '^[^"]*"""[^"]*$' -      let triplequote = 1 -    endif -    if backtick -      if line =~# '^[^`]*`[^`]*$' -        let backtick = 0 +      if backtick +        if line =~# '^[^`]*`[^`]*$' +          let backtick = 0 +        endif +        continue +      elseif &filetype ==# 'go' && line =~# '^[^`]*`[^`]*$' +        let backtick = 1        endif -      continue -    elseif &filetype ==# 'go' && line =~# '^[^`]*`[^`]*$' -      let backtick = 1 -    endif -    if line =~# '^\s*<\!--' -      let xmlcomment = 1 -    endif -    if xmlcomment -      if line =~# '-->' -        let xmlcomment = 0 +      if line =~# '^\s*<\!--' +        let xmlcomment = 1 +      endif +      if xmlcomment +        if line =~# '-->' +          let xmlcomment = 0 +        endif +        continue        endif -      continue -    endif -    " This is correct order because both "<<EOF" and "EOF" matches end -    if heredoc != '' -      if line =~# heredoc -        let heredoc = '' +      " This is correct order because both "<<EOF" and "EOF" matches end +      if heredoc != '' +        if line =~# heredoc +          let heredoc = '' +        endif +        continue +      endif +      let herematch = matchlist(line, '\C<<\W*\([A-Z]\+\)\s*$') +      if len(herematch) > 0 +        let heredoc = herematch[1] . '$'        endif -      continue -    endif -    let herematch = matchlist(line, '\C<<\W*\([A-Z]\+\)\s*$') -    if len(herematch) > 0 -      let heredoc = herematch[1] . '$' -    endif -    let spaces_minus_tabs += line[0] == "\t" ? 1 : -1 +      let spaces_minus_tabs += line[0] == "\t" ? 1 : -1 -    if line[0] == "\t" -      setlocal noexpandtab -      return 1 -    elseif line[0] == " " -      let indent = len(matchstr(line, '^ *')) -      if (indent % 2 == 0 || indent % 3 == 0) && indent < minindent -        let minindent = indent +      if line[0] == "\t" +        setlocal noexpandtab +        return 1 +      elseif line[0] == " " +        let indent = len(matchstr(line, '^ *')) +        if (indent % 2 == 0 || indent % 3 == 0) && indent < minindent +          let minindent = indent +        endif        endif -    endif -  endfor +    endfor -  if minindent < 10 -    setlocal expandtab -    let &shiftwidth=minindent -    return 1 -  endif +    if minindent < 10 +      setlocal expandtab +      let &shiftwidth=minindent +      return 1 +    endif -  return 0 -endfunction +    return 0 +  endfunction -function! s:detect_indent() abort -  if &buftype ==# 'help' -    return -  endif +  function! s:detect_indent() abort +    if &buftype ==# 'help' +      return +    endif -  if s:guess(getline(1, 32)) -    return -  endif -  let pattern = sleuth#GlobForFiletype(&filetype) -  if len(pattern) == 0 -    return -  endif -  let pattern = '{' . pattern . ',.git,.svn,.hg}' -  let dir = expand('%:p:h') -  let level = 3 -  while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && level > 0 -    " Ignore files from homedir and root  -    if dir == expand('~') || dir == '/' +    if s:guess(getline(1, 32)) +      return +    endif +    let pattern = sleuth#GlobForFiletype(&filetype) +    if len(pattern) == 0        return      endif -    for neighbor in glob(dir . '/' . pattern, 0, 1)[0:level] -      " Do not consider directories above .git, .svn or .hg -      if fnamemodify(neighbor, ":h:t")[0] == "." +    let pattern = '{' . pattern . ',.git,.svn,.hg}' +    let dir = expand('%:p:h') +    let level = 3 +    while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && level > 0 +      " Ignore files from homedir and root  +      if dir == expand('~') || dir == '/'          return        endif -      if neighbor !=# expand('%:p') && filereadable(neighbor) -        if s:guess(readfile(neighbor, '', 32)) +      for neighbor in glob(dir . '/' . pattern, 0, 1)[0:level] +        " Do not consider directories above .git, .svn or .hg +        if fnamemodify(neighbor, ":h:t")[0] == "."            return          endif -      endif -    endfor +        if neighbor !=# expand('%:p') && filereadable(neighbor) +          if s:guess(readfile(neighbor, '', 32)) +            return +          endif +        endif +      endfor -    let dir = fnamemodify(dir, ':h') -    let level -= 1 -  endwhile -endfunction +      let dir = fnamemodify(dir, ':h') +      let level -= 1 +    endwhile +  endfunction -setglobal smarttab +  setglobal smarttab -augroup polyglot -  autocmd! -  autocmd FileType * call s:detect_indent() -augroup END +  augroup polyglot +    autocmd! +    autocmd FileType * call s:detect_indent() +  augroup END +endif  " restore Vi compatibility settings  let &cpo = s:cpo_save | 
