mirror of
https://github.com/Yggdroot/indentLine.git
synced 2026-01-09 04:52:21 +08:00
add filetype support
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
" Script Name: indentLine.vim
|
||||
" Version: 1.0.4
|
||||
" Last Change: Jan 23, 2013
|
||||
" Version: 1.0.5
|
||||
" Last Change: March 5, 2013
|
||||
" Author: Yggdroot <archofortune@gmail.com>
|
||||
"
|
||||
" Description: To show the indent lines
|
||||
@@ -11,8 +11,8 @@ if !has("conceal") || exists("g:indentLine_loaded")
|
||||
endif
|
||||
let g:indentLine_loaded = 1
|
||||
|
||||
" | ¦ ┆ │
|
||||
if !exists("g:indentLine_char")
|
||||
" | ¦ ┆ │
|
||||
if &encoding ==? "utf-8"
|
||||
let g:indentLine_char = "¦"
|
||||
else
|
||||
@@ -28,6 +28,14 @@ if !exists("g:indentLine_enabled")
|
||||
let g:indentLine_enabled = 1
|
||||
endif
|
||||
|
||||
if !exists("g:indentLine_fileType")
|
||||
let g:indentLine_fileType = "*"
|
||||
endif
|
||||
|
||||
if !exists("g:indentLine_fileTypeExclude")
|
||||
let g:indentLine_fileTypeExclude = ""
|
||||
endif
|
||||
|
||||
set conceallevel=1
|
||||
set concealcursor=inc
|
||||
|
||||
@@ -59,13 +67,7 @@ endfunction
|
||||
|
||||
"{{{1 function! <SID>SetIndentLine()
|
||||
function! <SID>SetIndentLine()
|
||||
if !exists("b:indentLine_enabled")
|
||||
let b:indentLine_enabled = g:indentLine_enabled
|
||||
if !b:indentLine_enabled
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
let b:indentLine_enabled = 1
|
||||
let space = &l:shiftwidth
|
||||
for i in range(space+1, space * g:indentLine_indentLevel + 1, space)
|
||||
exec 'syn match IndentLine /\(^\s\+\)\@<=\%'.i.'v / containedin=ALL conceal cchar=' . g:indentLine_char
|
||||
@@ -77,17 +79,23 @@ function! <SID>ResetWidth(...)
|
||||
if a:0 > 0
|
||||
let &l:shiftwidth = a:1
|
||||
endif
|
||||
syn clear IndentLine
|
||||
|
||||
if exists("b:indentLine_enabled")
|
||||
syn clear IndentLine
|
||||
endif
|
||||
call <SID>SetIndentLine()
|
||||
endfunction
|
||||
|
||||
"{{{1 function! <SID>IndentLinesToggle()
|
||||
function! <SID>IndentLinesToggle()
|
||||
if !exists("b:indentLine_enabled")
|
||||
let b:indentLine_enabled = 0
|
||||
endif
|
||||
|
||||
if b:indentLine_enabled
|
||||
let b:indentLine_enabled = 0
|
||||
syn clear IndentLine
|
||||
else
|
||||
let b:indentLine_enabled = 1
|
||||
call <SID>SetIndentLine()
|
||||
endif
|
||||
endfunction
|
||||
@@ -96,13 +104,28 @@ endfunction
|
||||
function! <SID>Setup()
|
||||
if !exists("b:indentLine_set")
|
||||
let b:indentLine_set = 1
|
||||
call <SID>SetIndentLine()
|
||||
|
||||
if !empty(filter(split(g:indentLine_fileTypeExclude, ','), 'v:val ==? "*.".expand("%:e:e") || v:val == "*"'))
|
||||
return
|
||||
endif
|
||||
|
||||
if !exists("b:indentLine_enabled")
|
||||
let b:indentLine_enabled = g:indentLine_enabled
|
||||
endif
|
||||
|
||||
if b:indentLine_enabled
|
||||
call <SID>SetIndentLine()
|
||||
endif
|
||||
|
||||
if &ft == ""
|
||||
call <SID>InitColor()
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"{{{1 commands
|
||||
autocmd BufWinEnter * call <SID>Setup()
|
||||
autocmd BufRead,ColorScheme * call <SID>InitColor()
|
||||
exec 'autocmd BufWinEnter '.g:indentLine_fileType.' call <SID>Setup()'
|
||||
exec 'autocmd BufRead,ColorScheme '.g:indentLine_fileType.' call <SID>InitColor()'
|
||||
|
||||
command! -nargs=? IndentLinesReset call <SID>ResetWidth(<f-args>)
|
||||
command! IndentLinesToggle call <SID>IndentLinesToggle()
|
||||
|
||||
Reference in New Issue
Block a user