]> git.lizzy.rs Git - micro.git/blob - cmd/micro/highlight/ftdetect.go
Don't skip included rules in end
[micro.git] / cmd / micro / highlight / ftdetect.go
1 package highlight
2
3 // DetectFiletype will use the list of syntax definitions provided and the filename and first line of the file
4 // to determine the filetype of the file
5 // It will return the corresponding syntax definition for the filetype
6 func DetectFiletype(defs []*Def, filename string, firstLine []byte) *Def {
7         for _, d := range defs {
8                 if d.ftdetect[0].MatchString(filename) {
9                         return d
10                 }
11                 if len(d.ftdetect) > 1 {
12                         if d.ftdetect[1].MatchString(string(firstLine)) {
13                                 return d
14                         }
15                 }
16         }
17
18         emptyDef := new(Def)
19         emptyDef.FileType = "Unknown"
20         emptyDef.rules = new(rules)
21         return emptyDef
22 }