Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect highlighting with termguicolors, cursorline and spell #1343

Closed
puremourning opened this issue Dec 29, 2016 · 3 comments
Closed

Incorrect highlighting with termguicolors, cursorline and spell #1343

puremourning opened this issue Dec 29, 2016 · 3 comments

Comments

@puremourning
Copy link
Contributor

puremourning commented Dec 29, 2016

Issue

When the termguicolors, spell and cursorline are set and the Normal highlight group sets a background colour, misspelled words are rendered incorrectly when they appear outside of another highlighting group and the cursor is on that line.

Steps to reproduce

  • Create a file vimrc_hl_test with the following contents:
set termguicolors
set cursorline
syntax clear
highlight clear
hi! Normal cterm=NONE gui=NONE ctermfg=12 guifg=white ctermbg=8 guibg=black
hi! SpellBad cterm=NONE,undercurl gui=NONE,undercurl ctermfg=NONE guifg=NONE ctermbg=NONE guibg=NONE guisp=#d33682
syntax enable
syntax on
syn spell toplevel
set spell
  • Edit a file with the following command: vim -Nu vimrc_hl_test and type Slpelling error.<ESC>j

Expected behaviour

The word Slpelling is rendered underlined with a foreground colour of 'white'

Actual behaviour

The word Slpelling is rendered underlined, but with a foreground colour of 'black'.

Follow-ups

  • Variations of guifg and guibg on the Normal group do not change the behaviour. It appears still rendered as black.
  • set notermguicolors - The text is rendered as expected (or at least the same colour as the other text)

Installed versions, environment etc.

OS: macOS
Vim: master as of today (c4bfeda)
True color terminal: iterm2

:version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Dec 29 2016 20:42:18)
MacOS X (unix) version
Included patches: 1-134
Compiled by ben@Bens-MacBook-Pro.local
Huge version without GUI.  Features included (+) or not (-):
+acl             +cindent         +cryptv          -ebcdic          +float           +job             +listcmds        +mouse_dec       +multi_byte      +persistent_undo +rightleft       +syntax          +textobjects     +visualextra     -xfontset
+arabic          -clientserver    -cscope          +emacs_tags      +folding         +jumplist        +localmap        -mouse_gpm       +multi_lang      +postscript      +ruby/dyn        +tag_binary      +timers          +viminfo         -xim
+autocmd         +clipboard       +cursorbind      +eval            -footer          +keymap          -lua             -mouse_jsbterm   -mzscheme        +printer         +scrollbind      +tag_old_static  +title           +vreplace        -xpm
-balloon_eval    +cmdline_compl   +cursorshape     +ex_extra        +fork()          +lambda          +menu            +mouse_netterm   +netbeans_intg   +profile         +signs           -tag_any_white   -toolbar         +wildignore      -xsmp
-browse          +cmdline_hist    +dialog_con      +extra_search    -gettext         +langmap         +mksession       +mouse_sgr       +num64           -python          +smartindent     -tcl             +user_commands   +wildmenu        -xterm_clipboard
++builtin_terms  +cmdline_info    +diff            +farsi           -hangul_input    +libcall         +modify_fname    -mouse_sysmouse  +packages        +python3         +startuptime     +termguicolors   +vertsplit       +windows         -xterm_save
+byte_offset     +comments        +digraphs        +file_in_path    +iconv           +linebreak       +mouse           +mouse_urxvt     +path_extra      +quickfix        +statusline      +terminfo        +virtualedit     +writebackup
+channel         +conceal         -dnd             +find_in_path    +insert_expand   +lispindent      -mouseshape      +mouse_xterm     -perl            +reltime         -sun_workshop    +termresponse    +visual          -X11
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/Users/ben/Development/vim2-root/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o vim        -lm -lncurses  -liconv -framework Cocoa     -L/usr/local/Cellar/python3/3.5.1/Frameworks/Python.fr
amework/Versions/3.5/lib/python3.5/config-3.5m -lpython3.5m -framework CoreFoundation

Please don't hesitate to ask if further information is required. I'm afraid I don't currently have a true colour xterm to test in for a more canonical environment.

@puremourning
Copy link
Contributor Author

OK I have a fix for this.

Bens-MacBook-Pro:vim2 ben$ git diff
diff --git a/src/syntax.c b/src/syntax.c
index 75ede361c..ef0e45791 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -8765,6 +8765,8 @@ hl_combine_attr(int char_attr, int prim_attr)
        else
        {
            vim_memset(&new_en, 0, sizeof(new_en));
+           new_en.ae_u.cterm.bg_rgb = INVALCOLOR;
+           new_en.ae_u.cterm.fg_rgb = INVALCOLOR;
            if (char_attr <= HL_ALL)
                new_en.ae_attr = char_attr;
        }

PR incoming.

puremourning added a commit to puremourning/vim that referenced this issue Dec 30, 2016
The 'uninitialised' value for RGB values is INVALCOLOR, but new entries in the
cterm_attr_table were initialised to 0, meaning black.

Fixes vim#1343
@puremourning
Copy link
Contributor Author

I have a test case which shows this is not restricted to just spell. Any highlighting group is affected if it doesn't explicitly set a foreground or background colour.

  • create the following file as vimrc_test:
set termguicolors
set cursorline
syntax clear
highlight clear

syntax enable
syntax on

function! s:Setup()
    syntax keyword Test Splelling
    hi! Normal cterm=NONE gui=NONE ctermfg=12 guifg=white ctermbg=8 guibg=black
    "hi! SpellBad cterm=NONE,undercurl gui=NONE,undercurl ctermfg=NONE guifg=NONE ctermbg=NONE guibg=NONE guisp=#d33682
    hi! Comment cterm=NONE,undercurl gui=NONE,undercurl ctermfg=NONE guifg=NONE ctermbg=NONE guibg=NONE guisp=#d33682
    hi link Test Comment
endfunction

autocmd BufReadPost * call s:Setup()
  • create a file with the contents "Splelling" (e.g. echo Slpelling > test.txt)

  • vim -Nu vimrc_test test.txt

  • Observe that the word Splelling has black foreground colour, should be white.

  • With the fix, observe that it is white.

puremourning added a commit to puremourning/vim that referenced this issue Dec 30, 2016
The 'uninitialised' value for RGB values is INVALCOLOR, but new entries in the
cterm_attr_table were initialised to 0, meaning black.

Fixes vim#1343
@puremourning
Copy link
Contributor Author

Fixed by #1344 (review) / 0cdb72a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant