mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-19 15:27:20 +09:00
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.
20 lines
432 B
Go
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
|
|
}
|