mirror of
https://github.com/Yggdroot/indentLine.git
synced 2025-12-26 05:41:09 +08:00
@@ -10,10 +10,11 @@ if ! has("conceal") || exists("g:indentLine_loaded")
|
||||
endif
|
||||
let g:indentLine_loaded = 1
|
||||
|
||||
let g:indentLine_newVersion = v:version > 704 || v:version == 704 && has("patch792")
|
||||
|
||||
let g:indentLine_char = get(g:,'indentLine_char',(&encoding ==# "utf-8" && &term isnot# "linux" ? '¦' : '|'))
|
||||
let g:indentLine_first_char = get(g:,'indentLine_first_char',(&encoding ==# "utf-8" && &term isnot# "linux" ? '¦' : '|'))
|
||||
let g:indentLine_indentLevel = get(g:,'indentLine_indentLevel',10)
|
||||
let g:indentLine_indentLevel = get(g:,'indentLine_indentLevel',20)
|
||||
let g:indentLine_enabled = get(g:,'indentLine_enabled',1)
|
||||
let g:indentLine_fileType = get(g:,'indentLine_fileType',[])
|
||||
let g:indentLine_fileTypeExclude = get(g:,'indentLine_fileTypeExclude',[])
|
||||
@@ -80,11 +81,39 @@ endfunction
|
||||
|
||||
"{{{1 function! s:IndentLinesEnable()
|
||||
function! s:IndentLinesEnable()
|
||||
if g:indentLine_newVersion
|
||||
if &diff
|
||||
return
|
||||
endif
|
||||
|
||||
if exists("b:indentLine_enabled") && b:indentLine_enabled == 0
|
||||
return
|
||||
endif
|
||||
|
||||
if ! exists("w:indentLine_indentLineId")
|
||||
let w:indentLine_indentLineId = []
|
||||
endif
|
||||
|
||||
call s:SetConcealOption()
|
||||
|
||||
if g:indentLine_showFirstIndentLevel
|
||||
call add(w:indentLine_indentLineId, matchadd('Conceal', '^ ', 0, -1, {'conceal': g:indentLine_first_char}))
|
||||
endif
|
||||
|
||||
let space = &l:shiftwidth is 0 ? &l:tabstop : &l:shiftwidth
|
||||
for i in range(space+1, space * g:indentLine_indentLevel + 1, space)
|
||||
call add(w:indentLine_indentLineId, matchadd('Conceal', '^\s\+\zs\%'.i.'v ', 0, -1, {'conceal': g:indentLine_char}))
|
||||
endfor
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
if exists("b:indentLine_enabled") && b:indentLine_enabled
|
||||
return
|
||||
else
|
||||
let b:indentLine_enabled = 1
|
||||
endif
|
||||
|
||||
call s:SetConcealOption()
|
||||
|
||||
let g:mysyntaxfile = g:indentLine_mysyntaxfile
|
||||
@@ -109,6 +138,17 @@ endfunction
|
||||
|
||||
"{{{1 function! s:IndentLinesDisable()
|
||||
function! s:IndentLinesDisable()
|
||||
if g:indentLine_newVersion
|
||||
if exists("w:indentLine_indentLineId") && ! empty(w:indentLine_indentLineId)
|
||||
for id in w:indentLine_indentLineId
|
||||
call matchdelete(id)
|
||||
endfor
|
||||
let w:indentLine_indentLineId = []
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
let b:indentLine_enabled = 0
|
||||
try
|
||||
syntax clear IndentLine
|
||||
@@ -119,6 +159,18 @@ endfunction
|
||||
|
||||
"{{{1 function! s:IndentLinesToggle()
|
||||
function! s:IndentLinesToggle()
|
||||
if g:indentLine_newVersion
|
||||
if exists("w:indentLine_indentLineId") && ! empty(w:indentLine_indentLineId)
|
||||
let b:indentLine_enabled = 0
|
||||
call s:IndentLinesDisable()
|
||||
else
|
||||
let b:indentLine_enabled = 1
|
||||
call s:IndentLinesEnable()
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
if exists("b:indentLine_enabled") && b:indentLine_enabled
|
||||
call s:IndentLinesDisable()
|
||||
else
|
||||
@@ -132,6 +184,7 @@ function! s:ResetWidth(...)
|
||||
let &l:shiftwidth = a:1
|
||||
endif
|
||||
|
||||
let b:indentLine_enabled = 1
|
||||
call s:IndentLinesDisable()
|
||||
call s:IndentLinesEnable()
|
||||
endfunction
|
||||
@@ -156,17 +209,41 @@ function! s:Setup()
|
||||
call s:InitColor()
|
||||
endif
|
||||
|
||||
if g:indentLine_enabled
|
||||
if g:indentLine_enabled || exists("b:indentLine_enabled") && b:indentLine_enabled
|
||||
call s:IndentLinesEnable()
|
||||
endif
|
||||
|
||||
if g:indentLine_leadingSpaceEnabled
|
||||
if g:indentLine_leadingSpaceEnabled || exists("b:indentLine_leadingSpaceEnabled") && b:indentLine_leadingSpaceEnabled
|
||||
call s:LeadingSpaceEnable()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"{{{1 function! s:LeadingSpaceEnable()
|
||||
function! s:LeadingSpaceEnable()
|
||||
if g:indentLine_newVersion
|
||||
if &diff
|
||||
return
|
||||
endif
|
||||
|
||||
if exists("b:indentLine_leadingSpaceEnabled") && b:indentLine_leadingSpaceEnabled == 0
|
||||
return
|
||||
endif
|
||||
|
||||
if ! exists("w:indentLine_leadingSpaceId")
|
||||
let w:indentLine_leadingSpaceId = []
|
||||
endif
|
||||
|
||||
call s:SetConcealOption()
|
||||
|
||||
call add(w:indentLine_leadingSpaceId, matchadd('Conceal', '\%(^\s*\)\@<= ', 0, -1, {'conceal': g:indentLine_leadingSpaceChar}))
|
||||
|
||||
if exists("w:indentLine_indentLineId") && ! empty(w:indentLine_indentLineId)
|
||||
call s:ResetWidth()
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
if g:indentLine_faster
|
||||
echoerr 'LeadingSpace can not be shown when g:indentLine_faster == 1'
|
||||
return
|
||||
@@ -179,18 +256,43 @@ endfunction
|
||||
|
||||
"{{{1 function! s:LeadingSpaceDisable()
|
||||
function! s:LeadingSpaceDisable()
|
||||
if g:indentLine_newVersion
|
||||
if exists("w:indentLine_leadingSpaceId") && ! empty(w:indentLine_leadingSpaceId)
|
||||
for id in w:indentLine_leadingSpaceId
|
||||
call matchdelete(id)
|
||||
endfor
|
||||
let w:indentLine_leadingSpaceId = []
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
let b:indentLine_leadingSpaceEnabled = 0
|
||||
try
|
||||
syntax clear IndentLineLeadingSpace
|
||||
catch /^Vim\%((\a\+)\)\=:E28/ " catch error E28
|
||||
catch /^Vim\%((\a\+)\)\=:E28/ " catch error E28
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
"{{{1 function! s:LeadingSpaceToggle()
|
||||
function! s:LeadingSpaceToggle()
|
||||
if g:indentLine_newVersion
|
||||
if exists("w:indentLine_leadingSpaceId") && ! empty(w:indentLine_leadingSpaceId)
|
||||
let b:indentLine_leadingSpaceEnabled = 0
|
||||
call s:LeadingSpaceDisable()
|
||||
else
|
||||
let b:indentLine_leadingSpaceEnabled = 1
|
||||
call s:LeadingSpaceEnable()
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
if exists("b:indentLine_leadingSpaceEnabled") && b:indentLine_leadingSpaceEnabled
|
||||
let b:indentLine_leadingSpaceEnabled = 0
|
||||
call s:LeadingSpaceDisable()
|
||||
else
|
||||
let b:indentLine_leadingSpaceEnabled = 1
|
||||
call s:LeadingSpaceEnable()
|
||||
endif
|
||||
endfunction
|
||||
@@ -198,22 +300,35 @@ endfunction
|
||||
"{{{1 augroup indentLine
|
||||
augroup indentLine
|
||||
autocmd!
|
||||
autocmd BufWinEnter * call <SID>Setup()
|
||||
autocmd User * if exists("b:indentLine_enabled") || exists("b:indentLine_leadingSpaceEnabled") |
|
||||
\ call <SID>Setup() | endif
|
||||
autocmd BufRead,BufNewFile,ColorScheme,Syntax * call <SID>InitColor()
|
||||
autocmd BufUnload * let b:indentLine_enabled = 0 | let b:indentLine_leadingSpaceEnabled = 0
|
||||
autocmd SourcePre $VIMRUNTIME/syntax/nosyntax.vim doautocmd indentLine BufUnload
|
||||
autocmd FileChangedShellPost * doautocmd indentLine BufUnload | call <SID>Setup()
|
||||
if g:indentLine_newVersion
|
||||
autocmd BufRead,BufNewFile,ColorScheme,Syntax * call <SID>InitColor()
|
||||
autocmd BufWinEnter * call <SID>IndentLinesDisable() | call <SID>LeadingSpaceDisable() | call <SID>Setup()
|
||||
autocmd WinEnter * call <SID>Setup()
|
||||
else
|
||||
autocmd BufWinEnter * call <SID>Setup()
|
||||
autocmd User * if exists("b:indentLine_enabled") || exists("b:indentLine_leadingSpaceEnabled") |
|
||||
\ call <SID>Setup() | endif
|
||||
autocmd BufRead,BufNewFile,ColorScheme,Syntax * call <SID>InitColor()
|
||||
autocmd BufUnload * let b:indentLine_enabled = 0 | let b:indentLine_leadingSpaceEnabled = 0
|
||||
autocmd SourcePre $VIMRUNTIME/syntax/nosyntax.vim doautocmd indentLine BufUnload
|
||||
autocmd FileChangedShellPost * doautocmd indentLine BufUnload | call <SID>Setup()
|
||||
endif
|
||||
augroup END
|
||||
|
||||
"{{{1 commands
|
||||
command! -nargs=? IndentLinesReset call <SID>ResetWidth(<f-args>)
|
||||
command! IndentLinesToggle call <SID>IndentLinesToggle()
|
||||
command! IndentLinesEnable call <SID>IndentLinesEnable()
|
||||
command! IndentLinesDisable call <SID>IndentLinesDisable()
|
||||
command! LeadingSpaceEnable call <SID>LeadingSpaceEnable()
|
||||
command! LeadingSpaceDisable call <SID>LeadingSpaceDisable()
|
||||
if g:indentLine_newVersion
|
||||
command! IndentLinesEnable let b:indentLine_enabled = 1 | call <SID>IndentLinesEnable()
|
||||
command! IndentLinesDisable let b:indentLine_enabled = 0 | call <SID>IndentLinesDisable()
|
||||
command! LeadingSpaceEnable let b:indentLine_leadingSpaceEnabled = 1 | call <SID>LeadingSpaceEnable()
|
||||
command! LeadingSpaceDisable let b:indentLine_leadingSpaceEnabled = 0 | call <SID>LeadingSpaceDisable()
|
||||
else
|
||||
command! IndentLinesEnable call <SID>IndentLinesEnable()
|
||||
command! IndentLinesDisable call <SID>IndentLinesDisable()
|
||||
command! LeadingSpaceEnable call <SID>LeadingSpaceEnable()
|
||||
command! LeadingSpaceDisable call <SID>LeadingSpaceDisable()
|
||||
endif
|
||||
command! LeadingSpaceToggle call <SID>LeadingSpaceToggle()
|
||||
|
||||
" vim:et:ts=4:sw=4:fdm=marker:fmr={{{,}}}
|
||||
|
||||
Reference in New Issue
Block a user