Better ordering for reading syntax files
Ref
@@ -548,59 +548,63 @@ func (b *Buffer) UpdateRules() {
return
}
syntaxFile := ""
+ foundDef := false
var header *highlight.Header
- for _, f := range config.ListRuntimeFiles(config.RTSyntaxHeader) {
+ // search for the syntax file in the user's custom syntax files
+ for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) {
data, err := f.Data()
if err != nil {
- screen.TermMessage("Error loading syntax header file " + f.Name() + ": " + err.Error())
+ screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error())
continue
}
- header, err = highlight.MakeHeader(data)
+ header, err = highlight.MakeHeaderYaml(data)
+ file, err := highlight.ParseFile(data)
if err != nil {
- screen.TermMessage("Error reading syntax header file", f.Name(), err)
+ screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
continue
}
- if ft == "unknown" || ft == "" {
- if highlight.MatchFiletype(header.FtDetect, b.Path, b.lines[0].data) {
- syntaxFile = f.Name()
- break
+ if ((ft == "unknown" || ft == "") && highlight.MatchFiletype(header.FtDetect, b.Path, b.lines[0].data)) || header.FileType == ft {
+ syndef, err := highlight.ParseDef(file, header)
+ if err != nil {
+ screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
+ continue
}
- } else if header.FileType == ft {
+ b.SyntaxDef = syndef
syntaxFile = f.Name()
+ foundDef = true
break
}
}
- if syntaxFile == "" {
- // search for the syntax file in the user's custom syntax files
- for _, f := range config.ListRealRuntimeFiles(config.RTSyntax) {
+ // search in the default syntax files
+ for _, f := range config.ListRuntimeFiles(config.RTSyntaxHeader) {
data, err := f.Data()
if err != nil {
- screen.TermMessage("Error loading syntax file " + f.Name() + ": " + err.Error())
+ screen.TermMessage("Error loading syntax header file " + f.Name() + ": " + err.Error())
continue
}
- header, err = highlight.MakeHeaderYaml(data)
- file, err := highlight.ParseFile(data)
+ header, err = highlight.MakeHeader(data)
if err != nil {
- screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
+ screen.TermMessage("Error reading syntax header file", f.Name(), err)
continue
}
- if ((ft == "unknown" || ft == "") && highlight.MatchFiletype(header.FtDetect, b.Path, b.lines[0].data)) || header.FileType == ft {
- syndef, err := highlight.ParseDef(file, header)
- if err != nil {
- screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error())
- continue
+ if ft == "unknown" || ft == "" {
+ if highlight.MatchFiletype(header.FtDetect, b.Path, b.lines[0].data) {
+ syntaxFile = f.Name()
+ break
}
- b.SyntaxDef = syndef
+ } else if header.FileType == ft {
syntaxFile = f.Name()
break
}
}
- } else {
+
+ if syntaxFile != "" && !foundDef {
+ // we found a syntax file using a syntax header file
for _, f := range config.ListRuntimeFiles(config.RTSyntax) {
if f.Name() == syntaxFile {
data, err := f.Data()
