mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-16 13:57:07 +09:00
Support includes
This commit is contained in:
@@ -533,9 +533,28 @@ func (b *Buffer) UpdateRules() {
|
||||
}
|
||||
|
||||
// TODO: includes
|
||||
// if b.SyntaxDef != nil {
|
||||
// highlight.ResolveIncludes(b.SyntaxDef, files)
|
||||
// }
|
||||
if b.SyntaxDef != nil && highlight.HasIncludes(b.SyntaxDef) {
|
||||
includes := highlight.GetIncludes(b.SyntaxDef)
|
||||
|
||||
var files []*highlight.File
|
||||
for _, f := range config.ListRuntimeFiles(config.RTSyntax) {
|
||||
data, _ := f.Data()
|
||||
header, _ := highlight.MakeHeaderYaml(data)
|
||||
|
||||
for _, i := range includes {
|
||||
if header.FileType == i {
|
||||
file, _ := highlight.ParseFile(data)
|
||||
files = append(files, file)
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(files) >= len(includes) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
highlight.ResolveIncludes(b.SyntaxDef, files)
|
||||
}
|
||||
|
||||
if b.Highlighter == nil || syntaxFile != "" {
|
||||
if b.SyntaxDef != nil {
|
||||
|
||||
@@ -220,6 +220,40 @@ func ParseDef(f *File, header *Header) (s *Def, err error) {
|
||||
return s, err
|
||||
}
|
||||
|
||||
// HasIncludes returns whether this syntax def has any include statements
|
||||
func HasIncludes(d *Def) bool {
|
||||
hasIncludes := len(d.rules.includes) > 0
|
||||
for _, r := range d.rules.regions {
|
||||
hasIncludes = hasIncludes || hasIncludesInRegion(r)
|
||||
}
|
||||
return hasIncludes
|
||||
}
|
||||
|
||||
func hasIncludesInRegion(region *region) bool {
|
||||
hasIncludes := len(region.rules.includes) > 0
|
||||
for _, r := range region.rules.regions {
|
||||
hasIncludes = hasIncludes || hasIncludesInRegion(r)
|
||||
}
|
||||
return hasIncludes
|
||||
}
|
||||
|
||||
// GetIncludes returns a list of filetypes that are included by this syntax def
|
||||
func GetIncludes(d *Def) []string {
|
||||
includes := d.rules.includes
|
||||
for _, r := range d.rules.regions {
|
||||
includes = append(includes, getIncludesInRegion(r)...)
|
||||
}
|
||||
return includes
|
||||
}
|
||||
|
||||
func getIncludesInRegion(region *region) []string {
|
||||
includes := region.rules.includes
|
||||
for _, r := range region.rules.regions {
|
||||
includes = append(includes, getIncludesInRegion(r)...)
|
||||
}
|
||||
return includes
|
||||
}
|
||||
|
||||
// ResolveIncludes will sort out the rules for including other filetypes
|
||||
// You should call this after parsing all the Defs
|
||||
func ResolveIncludes(def *Def, files []*File) {
|
||||
|
||||
Reference in New Issue
Block a user