Files
zyedidia.micro/cmd/micro/highlight/ftdetect.go
Zachary Yedidia 87f54be13a Add support for lookbehind in region regexes
Use the 'regexp2' library for lookahead and lookbehind in region
start and end regular expressions to support things like closing quotes
that aren't preceded by backslashes.
2017-03-22 19:03:06 -04:00

20 lines
432 B
Go

package highlight
func DetectFiletype(defs []*Def, filename string, firstLine []byte) *Def {
for _, d := range defs {
if isMatch, _ := d.ftdetect[0].MatchString(filename); isMatch {
return d
}
if len(d.ftdetect) > 1 {
if isMatch, _ := d.ftdetect[1].MatchString(string(firstLine)); isMatch {
return d
}
}
}
emptyDef := new(Def)
emptyDef.FileType = "Unknown"
emptyDef.rules = new(Rules)
return emptyDef
}