// Scaning path for finding plugins that contain files // whith specific suffix func ScanPlugins(path string, suffix string) []*Plugin { var plugins []*Plugin f, err := os.Open(path) if err != nil { log.Warn(err) return nil } defer f.Close() dirs, err := f.Readdirnames(-1) if err != nil { log.Warn(err) return nil } for _, dir := range dirs { dir2 := pt.Join(path, dir) f2, err := os.Open(dir2) if err != nil { log.Warn(err) continue } defer f2.Close() fi, err := f2.Readdir(-1) if err != nil { continue } for _, f := range fi { fn := f.Name() if strings.HasSuffix(fn, suffix) { plugins = append(plugins, NewPlugin(dir2, suffix)) break } } } return plugins }
func (p *Pattern) Cache(data string, pos int) (pat *Pattern, ret MatchObject) { if p.cachedData == data { if p.cachedMatch == nil { return nil, nil } if p.cachedMatch[0] >= pos && p.cachedPat.cachedMatch != nil { p.hits++ return p.cachedPat, p.cachedMatch } } else { p.cachedPatterns = nil } if p.cachedPatterns == nil { p.cachedPatterns = make([]*Pattern, len(p.Patterns)) for i := range p.cachedPatterns { p.cachedPatterns[i] = &p.Patterns[i] } } p.misses++ if p.Match.re != nil { pat, ret = p, p.Match.Find(data, pos) } else if p.Begin.re != nil { pat, ret = p, p.Begin.Find(data, pos) } else if p.Include != "" { if z := p.Include[0]; z == '#' { key := p.Include[1:] if p2, ok := p.owner.Repository[key]; ok { pat, ret = p2.Cache(data, pos) } else { log.Fine("Not found in repository: %s", p.Include) } } else if z == '$' { // TODO(q): Implement tmLanguage $ include directives log.Warn("Unhandled include directive: %s", p.Include) } else if l, err := Provider.GetLanguage(p.Include); err != nil { if !failed[p.Include] { log.Warn("Include directive %s failed: %s", p.Include, err) } failed[p.Include] = true } else { return l.RootPattern.Cache(data, pos) } } else { pat, ret = p.FirstMatch(data, pos) } p.cachedData = data p.cachedMatch = ret p.cachedPat = pat return }
func (k *KeyPress) UnmarshalJSON(d []byte) error { combo := strings.Split(string(d[1:len(d)-1]), "+") for _, c := range combo { lower := strings.ToLower(c) switch lower { case "super": k.Super = true case "ctrl": k.Ctrl = true case "alt": k.Alt = true case "shift": k.Shift = true default: if v, ok := keylut[lower]; ok { k.Key = v } else { r := []Key(c) if len(r) != 1 { log.Warn("Unknown key value with %d bytes: %s", len(c), c) return nil } k.Key = Key(c[0]) k.fix() } } } return nil }
func (p *plugin) load(pkg *packages.Packet) { if err := pkg.Load(); err != nil { log.Errorf("Failed to load packet %s: %s", pkg.Name(), err) } else { log.Info("Loaded %s", pkg.Name()) if err := watcher.Watch(pkg.Name(), pkg); err != nil { log.Warn("Couldn't watch %s: %s", pkg.Name(), err) } } }
func (c *Color) UnmarshalJSON(data []byte) error { i64, err := strconv.ParseInt(string(data[2:len(data)-1]), 16, 64) if err != nil { log.Warn("Couldn't properly load color from %s: %s", string(data), err) } c.A = uint8((i64 >> 24) & 0xff) c.R = uint8((i64 >> 16) & 0xff) c.G = uint8((i64 >> 8) & 0xff) c.B = uint8((i64 >> 0) & 0xff) return nil }
func (r *Regex) UnmarshalJSON(data []byte) error { str := string(data[1 : len(data)-1]) str = strings.Replace(str, "\\\\", "\\", -1) str = strings.Replace(str, "\\n", "\n", -1) str = strings.Replace(str, "\\t", "\t", -1) if re, err := rubex.Compile(str); err != nil { log.Warn("Couldn't compile language pattern %s: %s", str, err) } else { r.re = re } return nil }