Added early support for terminal vim
This commit is contained in:
parent
0c0ac44889
commit
6d903df6e7
@ -32,12 +32,9 @@ endfunction
|
|||||||
"
|
"
|
||||||
function! indent_guides#enable()
|
function! indent_guides#enable()
|
||||||
let g:indent_guides_autocmds_enabled = 1
|
let g:indent_guides_autocmds_enabled = 1
|
||||||
|
call indent_guides#highlight_colors()
|
||||||
call indent_guides#clear_matches()
|
call indent_guides#clear_matches()
|
||||||
|
|
||||||
if g:indent_guides_auto_colors
|
|
||||||
call indent_guides#highlight_colors()
|
|
||||||
endif
|
|
||||||
|
|
||||||
" loop through each indent level and define a highlight pattern
|
" loop through each indent level and define a highlight pattern
|
||||||
" will automagically figure out whether to use tabs or spaces
|
" will automagically figure out whether to use tabs or spaces
|
||||||
for level in range(1, g:indent_guides_indent_levels)
|
for level in range(1, g:indent_guides_indent_levels)
|
||||||
@ -80,34 +77,71 @@ endfunction
|
|||||||
" Automagically calculates and defines the indent highlight colors.
|
" Automagically calculates and defines the indent highlight colors.
|
||||||
"
|
"
|
||||||
function! indent_guides#highlight_colors()
|
function! indent_guides#highlight_colors()
|
||||||
|
" define default highlights
|
||||||
|
exe 'hi IndentGuidesOdd guibg=lightgrey ctermbg=1'
|
||||||
|
exe 'hi IndentGuidesEven guibg=darkgrey ctermbg=0'
|
||||||
|
|
||||||
if g:indent_guides_auto_colors
|
if g:indent_guides_auto_colors
|
||||||
let hi_normal = indent_guides#capture_highlight('normal')
|
if has('gui_running')
|
||||||
let hex_pattern = 'guibg=\zs'. g:indent_guides_hex_color_pattern . '\ze'
|
call indent_guides#gui_highlight_colors()
|
||||||
let name_pattern = "guibg='\\?\\zs[0-9A-Za-z ]\\+\\ze'\\?"
|
else
|
||||||
let hi_normal_guibg = ''
|
call indent_guides#cterm_highlight_colors()
|
||||||
|
|
||||||
" capture the backgroud color from the normal highlight
|
|
||||||
if hi_normal =~ hex_pattern
|
|
||||||
" hex color code is being used, eg. '#FFFFFF'
|
|
||||||
let hi_normal_guibg = matchstr(hi_normal, hex_pattern)
|
|
||||||
elseif hi_normal =~ name_pattern
|
|
||||||
" color name is being used, eg. 'white'
|
|
||||||
let color_name = matchstr(hi_normal, name_pattern)
|
|
||||||
let hi_normal_guibg = color_helper#color_name_to_hex(color_name)
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if hi_normal_guibg =~ g:indent_guides_hex_color_pattern
|
|
||||||
" calculate the highlight background colors
|
|
||||||
let hi_odd_bg = indent_guides#lighten_or_darken_color(hi_normal_guibg)
|
|
||||||
let hi_even_bg = indent_guides#lighten_or_darken_color(hi_odd_bg)
|
|
||||||
|
|
||||||
" define the new highlights
|
|
||||||
exe 'hi IndentGuidesOdd guibg=' . hi_odd_bg
|
|
||||||
exe 'hi IndentGuidesEven guibg=' . hi_even_bg
|
|
||||||
end
|
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
"
|
||||||
|
" Automagically calculates and defines the indent highlight colors for
|
||||||
|
" terminal vim.
|
||||||
|
"
|
||||||
|
function! indent_guides#cterm_highlight_colors()
|
||||||
|
let hi_search = indent_guides#capture_highlight('search')
|
||||||
|
let pattern = "ctermbg=\\zs[0-9A-Za-z]\\+\\ze"
|
||||||
|
let hi_search_ctermbg = ''
|
||||||
|
|
||||||
|
" capture the backgroud color from the search highlight
|
||||||
|
if hi_search =~ pattern
|
||||||
|
let hi_search_ctermbg = matchstr(hi_search, pattern)
|
||||||
|
endif
|
||||||
|
|
||||||
|
if hi_search_ctermbg =~ "[0-9A-Za-z]\\+"
|
||||||
|
" define the new highlights
|
||||||
|
exe 'hi IndentGuidesOdd ctermbg=none'
|
||||||
|
exe 'hi IndentGuidesEven ctermbg=' . hi_search_ctermbg
|
||||||
|
end
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
"
|
||||||
|
" Automagically calculates and defines the indent highlight colors for gui
|
||||||
|
" vim.
|
||||||
|
"
|
||||||
|
function! indent_guides#gui_highlight_colors()
|
||||||
|
let hi_normal = indent_guides#capture_highlight('normal')
|
||||||
|
let hex_pattern = 'guibg=\zs'. g:indent_guides_hex_color_pattern . '\ze'
|
||||||
|
let name_pattern = "guibg='\\?\\zs[0-9A-Za-z ]\\+\\ze'\\?"
|
||||||
|
let hi_normal_guibg = ''
|
||||||
|
|
||||||
|
" capture the backgroud color from the normal highlight
|
||||||
|
if hi_normal =~ hex_pattern
|
||||||
|
" hex color code is being used, eg. '#FFFFFF'
|
||||||
|
let hi_normal_guibg = matchstr(hi_normal, hex_pattern)
|
||||||
|
elseif hi_normal =~ name_pattern
|
||||||
|
" color name is being used, eg. 'white'
|
||||||
|
let color_name = matchstr(hi_normal, name_pattern)
|
||||||
|
let hi_normal_guibg = color_helper#color_name_to_hex(color_name)
|
||||||
|
endif
|
||||||
|
|
||||||
|
if hi_normal_guibg =~ g:indent_guides_hex_color_pattern
|
||||||
|
" calculate the highlight background colors
|
||||||
|
let hi_odd_bg = indent_guides#lighten_or_darken_color(hi_normal_guibg)
|
||||||
|
let hi_even_bg = indent_guides#lighten_or_darken_color(hi_odd_bg)
|
||||||
|
|
||||||
|
" define the new highlights
|
||||||
|
exe 'hi IndentGuidesOdd guibg=' . hi_odd_bg
|
||||||
|
exe 'hi IndentGuidesEven guibg=' . hi_even_bg
|
||||||
|
end
|
||||||
|
endfunction
|
||||||
|
|
||||||
"
|
"
|
||||||
" Takes a color and darkens or lightens it depending on whether a dark or light
|
" Takes a color and darkens or lightens it depending on whether a dark or light
|
||||||
" colorscheme is being used.
|
" colorscheme is being used.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
" Author: Nate Kane <nathanaelkane AT gmail DOT com>
|
" Author: Nate Kane <nathanaelkane AT gmail DOT com>
|
||||||
" Homepage: http://github.com/nathanaelkane/vim-indent-guides
|
" Homepage: http://github.com/nathanaelkane/vim-indent-guides
|
||||||
|
|
||||||
if exists('g:loaded_indent_guides') || &cp || !has('gui_running')
|
if exists('g:loaded_indent_guides') || &cp
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user