]> git.lizzy.rs Git - micro.git/commitdiff
Empty highlighting for unknown filetypes
authorZachary Yedidia <zyedidia@gmail.com>
Tue, 28 Jan 2020 23:34:44 +0000 (18:34 -0500)
committerZachary Yedidia <zyedidia@gmail.com>
Tue, 28 Jan 2020 23:34:44 +0000 (18:34 -0500)
internal/buffer/buffer.go
pkg/highlight/highlighter.go

index 9e3cfcc9254df8a398882ddc7eac19cfa916c511..e4af6be539df2381d0952acdb044d2c685216136 100644 (file)
@@ -610,13 +610,16 @@ func (b *Buffer) UpdateRules() {
        }
 
        if b.Highlighter == nil || syntaxFile != "" {
-               if b.SyntaxDef != nil {
-                       b.Settings["filetype"] = b.SyntaxDef.FileType
-                       b.Highlighter = highlight.NewHighlighter(b.SyntaxDef)
-                       if b.Settings["syntax"].(bool) {
-                               b.Highlighter.HighlightStates(b)
-                               b.Highlighter.HighlightMatches(b, 0, b.End().Y)
-                       }
+               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)
+                       b.Highlighter.HighlightMatches(b, 0, b.End().Y)
                }
        }
 }
index ec8eeaee95ceec41ab3ecc2363510502907d4a2d..ae7c71b3d4b841b7574701f1bc0fe01882718eb0 100644 (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