romainl/Apprentice

SpellBad and CursorLine improvement

puremourning opened this issue · 4 comments

I mentioned before that hitest.vim didn't work well on my setup, but that I couldn't repro with clean env. I have now reproduced it:

lxlvykz

The key appears to be the addition of set spell, and therefore I guess the SpellBad group.

Steps to repro:

  1. vim -Nu test.vim
  2. source $VIMRUNTIME/syntax/hitest.vim
  3. jjjjjjj (move the cursor)

test.vim:

" Adjust as necessary
set runtimepath+=$HOME/.vim/bundle/Apprentice

set background=dark

" Below required for termguicolors outside of xterm
let &t_8f = "\<Esc>[38:2:%lu:%lu:%lum"
let &t_8b = "\<Esc>[48:2:%lu:%lu:%lum"

set termguicolors

colorscheme apprentice

set cursorline
set textwidth=80
set colorcolumn=+1

set spell

filetype plugin indent on
syn on

I realise that hitest.vim isn't real code and doesn't disable spell highlighting, but I started investigating this because I do have set spell and the red text toggling depending on the cursor position was jarring (I thought it was a setup issue).

In terms of resolution, I'm not totally sure. Colorschemes that I've used before don't use a colour for SpellBad (just the underline) which seems to work well, and doesn't toggle with cursorline, etc. But of course I leave the creative direction to your good self. For example, running hi SpellBad guifg=NONE works well for me :)

Anyway, I hope this report is useful. If not, or it's intentional, feel free to close (no hard feelings :))

I have a different logic for Spell* depending on if we run in a GUI or not:

if has("gui_running")
    hi SpellBad       ctermbg=NONE ctermfg=131  guibg=NONE    guifg=NONE    cterm=undercurl      gui=undercurl guisp=#af5f5f
    hi SpellCap       ctermbg=NONE ctermfg=73   guibg=NONE    guifg=NONE    cterm=undercurl      gui=undercurl guisp=#5fafaf
    hi SpellLocal     ctermbg=NONE ctermfg=65   guibg=NONE    guifg=NONE    cterm=undercurl      gui=undercurl guisp=#5f875f
    hi SpellRare      ctermbg=NONE ctermfg=208  guibg=NONE    guifg=NONE    cterm=undercurl      gui=undercurl guisp=#ff8700
else
    hi SpellBad       ctermbg=NONE ctermfg=131  guibg=NONE    guifg=#af5f5f cterm=undercurl      gui=undercurl guisp=NONE
    hi SpellCap       ctermbg=NONE ctermfg=73   guibg=NONE    guifg=#5fafaf cterm=undercurl      gui=undercurl guisp=NONE
    hi SpellLocal     ctermbg=NONE ctermfg=65   guibg=NONE    guifg=#5f875f cterm=undercurl      gui=undercurl guisp=NONE
    hi SpellRare      ctermbg=NONE ctermfg=208  guibg=NONE    guifg=#ff8700 cterm=undercurl      gui=undercurl guisp=NONE
endif

but that logic obviously breaks in the termguicolors situation which is kind of a problem. I could add a &termguicolors test next to the gui_running one, I guess.

I'll download iTerm and make a few tests.

That said, set spell is more or less guaranteed to wreak havoc in hitest.vim since it contains many bad words.

That said, set spell is more or less guaranteed to wreak havoc in hitest.vim since it contains many bad words.

No doubt. Like I said I only ran hitest because I noticed this for normal text (e.g. in comments).

I tried the following hack

diff --git a/colors/apprentice.vim b/colors/apprentice.vim
index e9e58a3..6eb2179 100644
--- a/colors/apprentice.vim
+++ b/colors/apprentice.vim
@@ -35,7 +35,7 @@ endif

 let colors_name = "apprentice"

-if ($TERM =~ '256' || &t_Co >= 256) || has("gui_running")
+if ($TERM =~ '256' || &t_Co >= 256) || has("gui_running") || &termguicolors
   hi Normal           ctermbg=235  ctermfg=250  guibg=#262626 guifg=#bcbcbc cterm=NONE           gui=NONE
   hi LineNr           ctermbg=234  ctermfg=242  guibg=#1c1c1c guifg=#6c6c6c cterm=NONE           gui=NONE
   hi FoldColumn       ctermbg=234  ctermfg=242  guibg=#1c1c1c guifg=#6c6c6c cterm=NONE           gui=NONE
@@ -113,7 +113,8 @@ if ($TERM =~ '256' || &t_Co >= 256) || has("gui_running")
   hi debugPC          ctermbg=67                guibg=#5f87af
   hi debugBreakpoint  ctermbg=131               guibg=#af5f5f

-  if has("gui_running")
+  if has("gui_running") || &termguicolors
     hi SpellBad       ctermbg=NONE ctermfg=131  guibg=NONE    guifg=NONE    cterm=undercurl      gui=undercurl guisp=#af5f5f
     hi SpellCap       ctermbg=NONE ctermfg=73   guibg=NONE    guifg=NONE    cterm=undercurl      gui=undercurl guisp=#5fafaf
     hi SpellLocal     ctermbg=NONE ctermfg=65   guibg=NONE    guifg=NONE    cterm=undercurl      gui=undercurl guisp=#5f875f

And I didn't notice any obvious difference.

Maybe this is just a fundamental Vim limitation. In the TODO list there is:

Cursorline highlighting combines with Search ('hlsearch') but not with
SpellBad. (Jim Karsten, 2009 Mar 18)

Yeah this behaviour is the same, with/without termguicolors. The behaviour of SpellBad and CursorLine is not specific to this colour scheme.