aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2019-05-17 22:48:07 +0200
committerTeddy Wing2019-05-17 22:48:07 +0200
commitd389fdd35788385415dc972dd5c4ef7dcb3448c0 (patch)
tree4ff652b13a1c08714573fd542ba599ba59e3edc3
parentd95ed0309d8c24dd62c65ed25ee5c260df28989a (diff)
downloaddotvim-d389fdd35788385415dc972dd5c4ef7dcb3448c0.tar.bz2
diff-corrections: Restore old 'cursorline' and Comment highlight
When diff mode is deactivated, the old values for 'cursorline' and the Comment highlight colour should be restored. Thanks to Tony Mechelynck (http://vim.1045645.n5.nabble.com/template/NamlServlet.jtp?macro=user_nodes&user=28373) for the tip on how to save and restore highlight colours: > The following is untested. It requires Vim version 7. > > function SaveCursorColor() > redir => highlight > silent hi Cursor > redir END > if highlight =~ 'links to ' > let s:hl-link = matchstr(highlight, 'links to \zs\S*') > elseif highlight =~ '\<cleared\>' > let s:hl-link = 'NONE' > else > let s:hl-link = '' > for substr in ['term', 'cterm', 'ctermfg', 'ctermbg', > \ 'gui', 'guifg', 'guibg', 'guisp'] > if highlight =~ substr . '=' > let s:hl-{substr} = matchstr(highlight, > \ substr . '=\S*') > else > let s:hl-{substr} = '' > endif > endfor > endif > endfunction > function RestoreCursorColor() > if !exists('s:hl-link') > echoerr 'Cursor not saved, cannot restore' > return > endif > hi clear Cursor > if s:hl-link == '' > exe 'hi Cursor' s:hl-term s:hl-cterm s:hl-ctermfg > \ s:hl-ctermbg s:hl-gui s:hl-guifg s:hl-guibg > \ s:hl-guisp > elseif hl-link != 'NONE' > exe 'hi link Cursor' s:hl-link > endif > endfunction > > > Best regards, > Tony. http://vim.1045645.n5.nabble.com/How-to-save-restore-the-hightlight-for-cursor-td1182624.html
-rw-r--r--bundle/diff-corrections/autoload/diff_corrections.vim26
1 files changed, 26 insertions, 0 deletions
diff --git a/bundle/diff-corrections/autoload/diff_corrections.vim b/bundle/diff-corrections/autoload/diff_corrections.vim
index c9e77ff..620c1b0 100644
--- a/bundle/diff-corrections/autoload/diff_corrections.vim
+++ b/bundle/diff-corrections/autoload/diff_corrections.vim
@@ -1,3 +1,5 @@
+let s:old_cursorline = &cursorline
+
function! diff_corrections#Run()
if &diff
if exists('g:colors_name') && g:colors_name ==# 'twilight256'
@@ -5,5 +7,29 @@ function! diff_corrections#Run()
endif
set nocursorline
+ else
+ if exists('g:colors_name') && g:colors_name ==# 'twilight256'
+ execute 'highlight ' . s:old_highlight_comment
+ endif
+
+ let &cursorline = s:old_cursorline
endif
endfunction
+
+
+function! s:SaveCommentColor()
+ redir => old_highlight
+ silent highlight Comment
+ redir END
+
+ let parts = split(old_highlight, ' ')
+ call filter(parts, {_idx, val -> val !=? "" && val !=? "xxx"})
+
+ let restore = join(parts, ' ')
+
+ " Remove ^@ character from the beginning that messes up the `execute` call
+ return restore[1:]
+endfunction
+
+
+let s:old_highlight_comment = s:SaveCommentColor()