diffchar.vim
diffchar.vim copied to clipboard
Fixing highlight colours for neovim
Dear Rick,
I am not sure if you are accepting pull requests for your plugin since I could not find any info on your plugin page.
I am using neovim with truecolors support so I had to do the following fix.
if has('nvim') and termguicolor then use guicolors
Feel free of course to ignore it/alter it/do whatever you want.
Best wishes Panagiotis
Hi,
Thank you for using this plugin and proposing the fix. I have not used neovim but now tried to install and find the problem. I would like to fix as follows in the next update.
let hm = has('gui_running') || (has('termguicolors') && &termguicolors) ? 'gui' : &t_Co > 1 ? 'cterm' : 'term'
Regards,
Hi,
Thank you for this plugin! It is very usefull.
Indeed checking for termguicolors looks like a better check.
By the way, Older versions of neovim use $NVIM_TUI_ENABLE_TRUE_COLOR instead of termguicolor. Version v0.1.5. So it will still be incombatible with these versions.
So probably even a better approach would be to define both term and gui colours, and let vim/neovim/whatevervim to use which they need.
As an example, we can have a look at neomake functions.
The second to last function of neomake/autoload/sings.vim
,
function! neomake#signs#DefineHighlights() abort
,
assigns values to both ctermbg and guibg.
Best regards Panagiotis
Hi, I agree with your idea to look at all the mode: gui, cterm and term. I changed like this. Could you please try to check if it works? Regards,
--- dc64a.vim 2016-10-22 19:25:58.113819300 +0900
+++ dc65ax.vim 2016-11-19 15:44:39.428263600 +0900
@@ -374,16 +374,22 @@
" define a specific highlight group to show a position of a deleted
" unit, _DiffDelPos = DiffChange +/- bold/underline
- let hm = has('gui_running') ? 'gui' : &t_Co > 1 ? 'cterm' : 'term'
let hd = hlID(t:DChar.dhl.C)
- let ha = map(['fg', 'bg', 'sp'], 'v:val . "=" . synIDattr(hd, v:val)')
- let hx = filter(['bold', 'italic', 'reverse', 'inverse', 'standout',
- \'underline', 'undercurl'], 'synIDattr(hd, v:val)') +
- \['bold', 'underline']
- let ha += ['=' . join(filter(copy(hx), 'count(hx, v:val) == 1'), ',')]
+ let ha = []
+ for hm in ['gui', 'cterm']
+ let ha += map(['fg', 'bg', 'sp'],
+ \'hm . v:val . "=" . synIDattr(hd, v:val, hm)')
+ endfor
+ for hm in ['gui', 'cterm', 'term']
+ let hx = filter(['bold', 'italic', 'reverse', 'inverse',
+ \'standout', 'underline', 'undercurl'],
+ \'synIDattr(hd, v:val, hm)') + ['bold', 'underline']
+ let ha += [hm . '=' . join(filter(copy(hx),
+ \'count(hx, v:val) == 1'), ',')]
+ endfor
exec 'silent highlight clear ' . t:DChar.dhl.Z
exec 'silent highlight ' . t:DChar.dhl.Z . ' ' .
- \join(map(filter(ha, 'v:val !~ "=\\(-1\\)\\=$"'), 'hm . v:val'))
+ \join(filter(ha, 'v:val !~ "=\\(-1\\)\\=$"'))
endfunction
function! diffchar#ShowDiffChar(...)
Hi,
This patch seems to be working fine.
I am using centos 7. Tested using vim, gvim, neovim.
$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 10 2014 06:55:55)
Included patches: 1-160
Modified by <[email protected]>
Compiled by <[email protected]>
$ nvim --version
NVIM 0.1.6-dev
Build type: RelWithDebInfo
I tested using cpp, fortran, python, and vim files, using colorschemes jellybeans, and OceanicNext.
Only on vim files I get this error, with both colorschemes, vim, nvim, and gvim.
Error detected while processing function diffchar#DiffModeSyncExpr[9]..diffchar#ResetDiffChar[25]..<SNR>130_ClearDiffChar:
line 3:
E803: ID not found: 1075
E803: ID not found: 1068
E803: ID not found: 1070
E803: ID not found: 1072
Error detected while processing function diffchar#DiffModeSyncExpr[9]..diffchar#ResetDiffChar[68]..<SNR>130_ToggleDiffHL[20]..<SNR>130_RestoreDiffHL:
line 7:
E803: ID not found: 1078
ID not found varies.
But I guess this is a different issue. I will have a look when I find some free time and come back to you. I guess you can close this one. Thank you.
Best wishes Panagiotis
Hi, Thank you for your checking. Yes, this is a different issue. I can not reproduce it in my PC, but if some plugin might get the FileType or ColorSchme events and delete all of existing match ID, diffchar.vim would produce this problem. Anyway, I will change the code in the next update to check if the ID still remains before deleting it: Regards,
--- dc64a.vim 2016-10-22 19:25:58.113819300 +0900
+++ dc65ax.vim 2016-11-23 17:11:22.675601300 +0900
@@ -860,9 +866,12 @@
endfunction
function! s:ClearDiffChar(key, lines)
+ let mx = map(getmatches(), 'v:val.id')
for l in a:lines
if has_key(t:DChar.mid[a:key], l)
- call map(t:DChar.mid[a:key][l], 'matchdelete(v:val)')
+ call map(filter(t:DChar.mid[a:key][l],
+ \'index(mx, v:val) != -1'),
+ \'matchdelete(v:val)')
unlet t:DChar.mid[a:key][l]
unlet t:DChar.hlc[a:key][l]
endif
@@ -1129,7 +1141,9 @@
if mid != -1
let cwin = winnr()
exec 'noautocmd ' . pwin . 'wincmd w'
- call matchdelete(mid)
+ if index(map(getmatches(), 'v:val.id'), mid) != -1
+ call matchdelete(mid)
+ endif
exec 'noautocmd ' . cwin . 'wincmd w'
endif
exec 'au! diffchar WinEnter <buffer=' . winbufnr(pwin) . '>'
@@ -1319,7 +1333,9 @@
let cwin = winnr()
for k in [1, 2]
exec 'noautocmd ' . t:DChar.win[k] . 'wincmd w'
- call map(t:DChar.dtm[k], 'matchdelete(v:val)')
+ let mx = map(getmatches(), 'v:val.id')
+ call map(filter(t:DChar.dtm[k], 'index(mx, v:val) != -1'),
+ \'matchdelete(v:val)')
endfor
exec 'noautocmd ' . cwin . 'wincmd w'