Correctly detect synatx ft from header

This commit is contained in:
Zachary Yedidia
2017-05-03 11:04:56 -04:00
parent d3f32b5bc3
commit 67ec0d3c80
2 changed files with 8 additions and 5 deletions

View File

@@ -6,7 +6,9 @@ import "regexp"
// to determine the filetype of the file // to determine the filetype of the file
// It will return the corresponding syntax definition for the filetype // It will return the corresponding syntax definition for the filetype
func MatchFiletype(ftdetect [2]*regexp.Regexp, filename string, firstLine []byte) bool { func MatchFiletype(ftdetect [2]*regexp.Regexp, filename string, firstLine []byte) bool {
return ftdetect[0].MatchString(filename) if ftdetect[0].MatchString(filename) {
return true
}
if ftdetect[1] != nil { if ftdetect[1] != nil {
return ftdetect[1].Match(firstLine) return ftdetect[1].Match(firstLine)

View File

@@ -84,13 +84,14 @@ func LoadInput() []*Buffer {
var filename string var filename string
var input []byte var input []byte
var err error var err error
var buffers []*Buffer args := flag.Args()
buffers := make([]*Buffer, 0, len(args))
if len(flag.Args()) > 0 { if len(args) > 0 {
// Option 1 // Option 1
// We go through each file and load it // We go through each file and load it
for i := 0; i < len(flag.Args()); i++ { for i := 0; i < len(args); i++ {
filename = flag.Args()[i] filename = args[i]
// Check that the file exists // Check that the file exists
var input *os.File var input *os.File