From 2a53c503800091d639208d388a99dc46df81e082 Mon Sep 17 00:00:00 2001 From: Yggdroot Date: Tue, 5 Mar 2013 17:28:40 +0800 Subject: [PATCH] add filetype support --- after/plugin/indentLine.vim | 53 ++++++++++++++++++++++++++----------- doc/indentLine.txt | 24 +++++++++++++---- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/after/plugin/indentLine.vim b/after/plugin/indentLine.vim index 63535d4..dfd9e2a 100644 --- a/after/plugin/indentLine.vim +++ b/after/plugin/indentLine.vim @@ -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 " " 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! SetIndentLine() function! 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! ResetWidth(...) if a:0 > 0 let &l:shiftwidth = a:1 endif - syn clear IndentLine + + if exists("b:indentLine_enabled") + syn clear IndentLine + endif call SetIndentLine() endfunction "{{{1 function! IndentLinesToggle() function! 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 SetIndentLine() endif endfunction @@ -96,13 +104,28 @@ endfunction function! Setup() if !exists("b:indentLine_set") let b:indentLine_set = 1 - call 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 SetIndentLine() + endif + + if &ft == "" + call InitColor() + endif endif endfunction "{{{1 commands -autocmd BufWinEnter * call Setup() -autocmd BufRead,ColorScheme * call InitColor() +exec 'autocmd BufWinEnter '.g:indentLine_fileType.' call Setup()' +exec 'autocmd BufRead,ColorScheme '.g:indentLine_fileType.' call InitColor()' command! -nargs=? IndentLinesReset call ResetWidth() command! IndentLinesToggle call IndentLinesToggle() diff --git a/doc/indentLine.txt b/doc/indentLine.txt index 35bdc0c..47cc12c 100644 --- a/doc/indentLine.txt +++ b/doc/indentLine.txt @@ -27,7 +27,7 @@ g:indentLine_loaded *g:loaded_indentLine* g:indentLine_char *g:indentLine_char* Specify a character to be used as indent line. You also can use other characters: - | ¦ �� + | ¦ ┆ │ Default value is "|". g:indentLine_color_term *g:indentLine_color_term* @@ -42,13 +42,27 @@ g:indentLine_color_gui *g:indentLine_color_gui* g:indentLine_indentLevel *g:indentLine_indentLevel* Specify how much indent level do you want to use for indentLine. Most program will not has bigger indent level than - 20. - Default value is 20. -g:indentLine_enabled + 10. + Default value is 10. + +g:indentLine_enabled *g:indentLine_enabled* Specify whether to enable indentLine plugin by default. If value is not 0, the plugin is on by default, otherwise off. Default value is 1. +g:indentLine_fileType *g:indentLine_fileType* + This variable specify a list of comma separated file types. + When opening these types of files, the plugin is enabled by + default. + e.g. let g:indentLine_fileType = '*.c,*.h' + Default value is "*" which means all file types is supported. + +g:indentLine_fileTypeExclude *g:indentLine_fileTypeExclude* + This variable specify a list of comma separated file types. + When opening these types of files, the plugin is disabled by + default. + e.g. let g:indentLine_fileType = '*.txt,*.sh' + Default value is "" which means no file types is excluded. ============================================================================== COMMANDS *indentLine-commands* @@ -75,4 +89,4 @@ NagatoPain Salman Halim Christophe ============================================================================== -vim:tw=78:ts=8:ft=help:norl:noet +vim:tw=78:ts=8:ft=help:norl