aserebryakov / filestyle

filestyle is a Vim plugin that highlights unwanted whitespace and characters.
http://www.vim.org/scripts/script.php?script_id=5065
Apache License 2.0
30 stars 5 forks source link

[BUG]: Errors when starting Vim in a narrow terminal #36

Closed Markus00000 closed 6 years ago

Markus00000 commented 9 years ago

Starting Vim in a narrow terminal with fewer than 40 columns produces these messages at startup and while editing:

FileStyle: ctermbg parameter should be defined explicitly
Press ENTER or type command to continue

Error detected while processing functio
n FileStyleActivate..FileStyleCheck..Fi
leStyleClearIgnoredPatters..FileStyleHi
ghlightPattern:
line    7:
E28: No such highlight group name: File
StyleIgnoredPattern
Error detected while processing functio
n FileStyleActivate..FileStyleCheck..Fi
leStyleClearBufferMatches:
line    3:
E802: Invalid ID: -1 (must be greater t
han or equal to 1)
Press ENTER or type command to continue

Error detected while processing functio
n FileStyleActivate..FileStyleCheck..Fi
leStyleClearIgnoredPatters..FileStyleHi
ghlightPattern:
line    7:
E28: No such highlight group name: File
StyleIgnoredPattern
Press ENTER or type command to continue
aserebryakov commented 9 years ago

The first of all it looks like ctermbg was not defined in colorscheme. Does running with wide terminal resolve the issue?

Markus00000 commented 9 years ago

Yes, it is specific to terminals with fewer than 40 columns. No errors for wider terminals. It also happens with the default color scheme.

Can you reproduce it?

aserebryakov commented 9 years ago

I succeed to reproduce the issue. As I can see, the issue can be caused by the following code:

redir => l:colors
silent highlight
redir END

let l:normal_start = match(l:colors, 'Normal\s\+xxx')
....
let l:normal_end = match(l:colors, '\n', l:normal_start)
let l:normal_group = l:colors[(l:normal_start):(l:normal_end)]

if (match(l:normal_group, 'ctermbg=') == -1)
  echom 'FileStyle: ctermbg parameter should be defined explicitly'
  return
endif

In case of narrow terminal, the Normal definition in highlight is longer than a single line, so it is needed to find more correct criteria of the definition ending.

aserebryakov commented 9 years ago

The issue should be fixed by commit 37967573a19df5d57f94b41c24b739e9973cf58a.

Markus00000 commented 9 years ago

Fixed.

Juanitou commented 6 years ago

Sorry for necroing this issue, but this exact errors also happens when using the default colorscheme in vim (not gvim), as this default schema clears the Normal definition and so ctermbg is not defined.

aserebryakov commented 6 years ago

@Juanitou Normal highlight group is required to support the ignored patterns. Probably the better way is suppressing the feature instead of showing errors.

Juanitou commented 6 years ago

Thanks for your quick reply. I do not really understand what this feature is about. I hope you find a solution in your new milestone.

aserebryakov commented 6 years ago

@Juanitou ignored patterns allows to specify the pattern that is not highlighted even if it violates some rules.

Juanitou commented 6 years ago

Thanks. As I continue to use the plugin, I hope to help you find a better solution than simply removing the feature.

Juanitou commented 6 years ago

Thanks!