Empty highlighting for unknown filetypes

This commit is contained in:
Zachary Yedidia 2020-01-28 18:34:44 -05:00
parent d74f40882d
commit 477bdb3dc8
2 changed files with 12 additions and 7 deletions

View file

@ -610,8 +610,12 @@ func (b *Buffer) UpdateRules() {
}
if b.Highlighter == nil || syntaxFile != "" {
if b.SyntaxDef != nil {
b.Settings["filetype"] = b.SyntaxDef.FileType
} else {
b.SyntaxDef = &highlight.EmptyDef
}
if b.SyntaxDef != nil {
b.Highlighter = highlight.NewHighlighter(b.SyntaxDef)
if b.Settings["syntax"].(bool) {
b.Highlighter.HighlightStates(b)
@ -619,7 +623,6 @@ func (b *Buffer) UpdateRules() {
}
}
}
}
// ClearMatches clears all of the syntax highlighting for the buffer
func (b *Buffer) ClearMatches() {

View file

@ -68,6 +68,8 @@ func combineLineMatch(src, dst LineMatch) LineMatch {
// A State represents the region at the end of a line
type State *region
var EmptyDef = Def{nil, &rules{}}
// LineStates is an interface for a buffer-like object which can also store the states and matches for every line
type LineStates interface {
LineBytes(n int) []byte