func (o *View) Py_run_command(tu *py.Tuple) (py.Object, error) { var ( arg1 string arg2 backend.Args ) v, err := tu.GetItem(0) if err != nil { return nil, err } if v2, ok := v.(*py.Unicode); !ok { return nil, fmt.Errorf("Expected type *py.Unicode for backend.View.RunCommand() arg1, not %s", v.Type()) } else { arg1 = v2.String() } arg2 = make(backend.Args) if v, err := tu.GetItem(1); err == nil { v2, ok := v.(*py.Dict) if !ok { return nil, fmt.Errorf("Expected type *py.Dict for backend.View.RunCommand() arg2, not %s", v.Type()) } if v, err := fromPython(v2); err != nil { return nil, err } else { arg2 = v.(backend.Args) } } backend.GetEditor().CommandHandler().RunTextCommand(o.data, arg1, arg2) return toPython(nil) }
func sublime_RunCommand(tu *py.Tuple) (py.Object, error) { var ( arg1 string arg2 backend.Args ) if v, err := tu.GetItem(0); err != nil { return nil, err } else { if v3, err2 := fromPython(v); err2 != nil { return nil, err2 } else { if v2, ok := v3.(string); !ok { return nil, fmt.Errorf("Expected type string for backend.Editor.RunCommand() arg1, not %s", v.Type()) } else { arg1 = v2 } } } arg2 = make(backend.Args) if v, err := tu.GetItem(1); err == nil { if v3, err2 := fromPython(v); err2 != nil { return nil, err2 } else { if v2, ok := v3.(backend.Args); !ok { return nil, fmt.Errorf("Expected type backend.Args for backend.Editor.RunCommand() arg2, not %s", v.Type()) } else { arg2 = v2 } } } backend.GetEditor().RunCommand(arg1, arg2) return toPython(nil) }
func sublime_OkCancelDialog(tu *py.Tuple) (py.Object, error) { var ( arg1 string arg2 string ) if v, err := tu.GetItem(0); err != nil { return nil, err } else { if v3, err2 := fromPython(v); err2 != nil { return nil, err2 } else { if v2, ok := v3.(string); !ok { return nil, fmt.Errorf("Expected type string for backend.DummyFrontend.OkCancelDialog() arg1, not %s", v.Type()) } else { arg1 = v2 } } } if v, err := tu.GetItem(1); err != nil { return nil, err } else { if v3, err2 := fromPython(v); err2 != nil { return nil, err2 } else { if v2, ok := v3.(string); !ok { return nil, fmt.Errorf("Expected type string for backend.DummyFrontend.OkCancelDialog() arg2, not %s", v.Type()) } else { arg2 = v2 } } } backend.GetEditor().Frontend().OkCancelDialog(arg1, arg2) return toPython(nil) }
func (t *tbfe) setupEditor() *backend.Editor { ed := backend.GetEditor() ed.SetFrontend(t) ed.LogInput(false) ed.LogCommands(false) return ed }
func register(cmds []cmd) { e := backend.GetEditor() for i := range cmds { if err := e.CommandHandler().Register(cmds[i].name, cmds[i].cmd); err != nil { log4go.Error("Failed to register command %s: %s", cmds[i].name, err) } } }
func sublime_PackagesPath() (py.Object, error) { ret0 := backend.GetEditor().PackagesPath() var err error var pyret0 py.Object pyret0, err = toPython(ret0) if err != nil { return nil, err } return pyret0, err }
func sublime_NewWindow() (py.Object, error) { ret0 := backend.GetEditor().NewWindow() var err error var pyret0 py.Object pyret0, err = toPython(ret0) if err != nil { return nil, err } return pyret0, err }
func new_window(w *backend.Window) { log4go.Debug("new_window entered") defer log4go.Debug("new_window exited") qw := qt5.NewWidget() qw.Show() qw.SetSizev(600, 400) tw := qt5.NewTabWidget() lbox := qt5.NewVBoxLayout() lbox.AddWidget(tw) c := newQLimeView(backend.GetEditor().Console()) sa := qt5.NewScrollArea() sa.SetWidget(c) lbox.AddWidget(sa) qw.SetLayout(lbox) wnds[w] = QLimeWindow{tw, w} }
func (o *View) Py_visible_region() (py.Object, error) { ret0 := backend.GetEditor().Frontend().VisibleRegion(o.data) var err error var pyret0 py.Object pyret0, err = _regionClass.Alloc(1) if err != nil { } else if v2, ok := pyret0.(*Region); !ok { return nil, fmt.Errorf("Unable to convert return value to the right type?!: %s", pyret0.Type()) } else { v2.data = ret0 } if err != nil { return nil, err } return pyret0, err }
func sublime_LogInput(tu *py.Tuple) (py.Object, error) { var ( arg1 bool ) if v, err := tu.GetItem(0); err != nil { return nil, err } else { if v3, err2 := fromPython(v); err2 != nil { return nil, err2 } else { if v2, ok := v3.(bool); !ok { return nil, fmt.Errorf("Expected type bool for backend.Editor.LogInput() arg1, not %s", v.Type()) } else { arg1 = v2 } } } backend.GetEditor().LogInput(arg1) return toPython(nil) }
func sublime_SetClipboard(tu *py.Tuple) (py.Object, error) { var ( arg1 string ) if v, err := tu.GetItem(0); err != nil { return nil, err } else { if v3, err2 := fromPython(v); err2 != nil { return nil, err2 } else { if v2, ok := v3.(string); !ok { return nil, fmt.Errorf("Expected type string for backend.Editor.SetClipboard() arg1, not %s", v.Type()) } else { arg1 = v2 } } } backend.GetEditor().SetClipboard(arg1) return toPython(nil) }
func TestUpdateVisibleRegion(t *testing.T) { var ( fe tbfe e = backend.GetEditor() w = e.NewWindow() v = w.NewFile() ) fe.layout = make(map[*backend.View]layout) fe.layout[v] = layout{0, 0, 100, 100 - console_height - 1, Region{}, 0} fe.setupCallbacks(v) edit := v.BeginEdit() v.Insert(edit, 0, "foo") v.EndEdit(edit) if end := fe.layout[v].visible.End(); end != 3 { t.Fatalf("Expected 3, got %d", end) } }
func (view *View) Py_show(tu *py.Tuple, kw *py.Dict) (py.Object, error) { var ( arg1 text.Region ) v, err := tu.GetItem(0) if err != nil { return nil, err } if v2, ok := v.(*Region); !ok { if v2, ok := v.(*py.Long); !ok { return nil, fmt.Errorf("Expected type *Region or *Int for primitives.Buffer.Substr() arg1, not %s", v.Type()) } else { arg1.A = int(v2.Int64()) arg1.B = arg1.A + 1 } } else { arg1 = v2.data } backend.GetEditor().Frontend().Show(view.data, arg1) return toPython(nil) }
func sublime_Unregister(tu *py.Tuple) (py.Object, error) { var ( arg1 string ) if v, err := tu.GetItem(0); err != nil { return nil, err } else { if v3, err2 := fromPython(v); err2 != nil { return nil, err2 } else { if v2, ok := v3.(string); !ok { return nil, fmt.Errorf("Expected type string for backend.commandHandler.Unregister() arg1, not %s", v.Type()) } else { arg1 = v2 } } } if err := backend.GetEditor().CommandHandler().Unregister(arg1); err != nil { return nil, err } else { return toPython(nil) } }
func (t *tbfe) key(w http.ResponseWriter, req *http.Request) { log4go.Debug("key: %s", req) kc := req.FormValue("keyCode") var kp backend.KeyPress v, _ := strconv.ParseInt(kc, 10, 32) if req.FormValue("altKey") == "true" { kp.Alt = true } if req.FormValue("ctrlKey") == "true" { kp.Ctrl = true } if req.FormValue("metaKey") == "true" { kp.Super = true } if req.FormValue("shiftKey") == "true" { kp.Shift = true } if !kp.Shift { v = int64(unicode.ToLower(rune(v))) } kp.Key = backend.Key(v) backend.GetEditor().HandleInput(kp) }
func main() { py.InitializeEx(false) defer py.Finalize() e := backend.GetEditor() log4go.AddFilter("stdout", log4go.DEBUG, log4go.NewConsoleLogWriter()) if sc, err := textmate.LoadTheme("../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme"); err != nil { log4go.Error(err) } else { scheme = sc log4go.Debug("scheme: %v", scheme) } backend.OnNewWindow.Add(new_window) backend.OnNew.Add(new_view) backend.OnModified.Add(view_modified) go e.Init() qt5.Main(func() { w := e.NewWindow() w.OpenFile("main.go", 0) w.OpenFile("../../backend/editor.go", 0) qt5.Run() }) }
func (t *tbfe) loop() { ed := backend.GetEditor() ed.SetFrontend(t) //ed.LogInput(true) //ed.LogCommands(true) c := ed.Console() var ( scheme textmate.Theme ) if d, err := ioutil.ReadFile("../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme"); err != nil { log4go.Error("Unable to load colorscheme definition: %s", err) } else if err := loaders.LoadPlist(d, &scheme); err != nil { log4go.Error("Unable to load colorscheme definition: %s", err) } var ( palLut func(col textmate.Color) termbox.Attribute pal = make([]termbox.RGB, 0, 256) mode256 bool ) if err := termbox.SetColorMode(termbox.ColorMode256); err != nil { log4go.Error("Unable to use 256 color mode: %s", err) } else { log4go.Debug("Using 256 color mode") mode256 = true } if !mode256 { pal = pal[:10] // Not correct, but whatever pal[termbox.ColorBlack] = termbox.RGB{0, 0, 0} pal[termbox.ColorWhite] = termbox.RGB{255, 255, 255} pal[termbox.ColorRed] = termbox.RGB{255, 0, 0} pal[termbox.ColorGreen] = termbox.RGB{0, 255, 0} pal[termbox.ColorBlue] = termbox.RGB{0, 0, 255} pal[termbox.ColorMagenta] = termbox.RGB{255, 0, 255} pal[termbox.ColorYellow] = termbox.RGB{255, 255, 0} pal[termbox.ColorCyan] = termbox.RGB{0, 255, 255} diff := func(i, j byte) int { v := int(i) - int(j) if v < 0 { return -v } return v } palLut = func(col textmate.Color) termbox.Attribute { mindist := 10000000 mini := 0 for i, c := range pal { if dist := diff(c.R, col.R) + diff(c.G, col.G) + diff(c.B, col.B); dist < mindist { mindist = dist mini = i } } return termbox.Attribute(mini) } } else { palLut = func(col textmate.Color) termbox.Attribute { tc := termbox.RGB{col.R, col.G, col.B} for i, c := range pal { if c == tc { return termbox.Attribute(i) } } l := len(pal) pal = append(pal, tc) return termbox.Attribute(l) } } for i, s := range scheme.Settings { var ( fi = defaultFg bi = defaultBg ) if fg, ok := s.Settings["foreground"]; ok { fi = palLut(fg) if i == 0 { defaultFg = fi } } if bg, ok := s.Settings["background"]; ok { bi = palLut(bg) if i == 0 { defaultBg = bi } } schemelut[s.Scope] = [2]termbox.Attribute{fi, bi} } if mode256 { termbox.SetColorPalette(pal) } defer func() { termbox.Close() fmt.Println(c.Buffer().Data()) }() w := ed.NewWindow() t.active_window = w v := w.OpenFile("main.go", 0) v.Settings().Set("trace", true) c.Buffer().AddCallback(t.scroll) if err := v.SetSyntaxFile("../../3rdparty/bundles/GoSublime/GoSublime.tmLanguage"); err != nil { log4go.Error("Unable to set syntax file: %s", err) } sel := v.Sel() sel.Clear() // end := v.Buffer().Size() - 2 sel.Add(primitives.Region{0, 0}) // sel.Add(primitives.Region{end - 22, end - 22}) // sel.Add(primitives.Region{end - 16, end - 20}) // sel.Add(primitives.Region{end - 13, end - 10}) evchan := make(chan termbox.Event) go func() { for { evchan <- termbox.PollEvent() } }() sublime.Init() for { blink = !blink termbox.Clear(defaultFg, defaultBg) w, h := termbox.Size() t.renderView(0, 0, w, h-console_height, v) t.renderView(0, h-(console_height), w, (console_height - 1), c) runes := []rune(t.status_message) for i := 0; i < w && i < len(runes); i++ { termbox.SetCell(i, h-1, runes[i], defaultFg, defaultBg) } termbox.Flush() blink_phase := time.Second if p, ok := ed.Settings().Get("caret_blink_phase", 1.0).(float64); ok { blink_phase = time.Duration(float64(time.Second) * p) } select { case ev := <-evchan: switch ev.Type { case termbox.EventKey: var kp backend.KeyPress if ev.Ch != 0 { kp.Key = backend.Key(ev.Ch) } else if v2, ok := lut[ev.Key]; ok { kp = v2 } else { break } if ev.Key == termbox.KeyCtrlQ { return } ed.HandleInput(kp) blink = false } case <-time.After(blink_phase / 2): // Divided by two since we're only doing a simple toggle blink // TODO(q): Shouldn't redraw if blink is disabled... } } }
func (t *tbfe) scroll(b *primitives.Buffer, pos, delta int) { t.Show(backend.GetEditor().Console(), primitives.Region{b.Size(), b.Size()}) }
func (t *tbfe) loop() { backend.OnNew.Add(func(v *backend.View) { v.Settings().AddOnChange("lime.frontend.termbox.render", func() { t.render() }) }) backend.OnModified.Add(func(v *backend.View) { t.render() }) backend.OnSelectionModified.Add(func(v *backend.View) { t.render() }) ed := backend.GetEditor() ed.SetFrontend(t) ed.LogInput(false) ed.LogCommands(false) c := ed.Console() var ( scheme *textmate.Theme ) if sc, err := textmate.LoadTheme("../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme"); err != nil { log4go.Error(err) } else { scheme = sc } var ( palLut func(col textmate.Color) termbox.Attribute pal = make([]termbox.RGB, 0, 256) mode256 bool ) if err := termbox.SetColorMode(termbox.ColorMode256); err != nil { log4go.Error("Unable to use 256 color mode: %s", err) } else { log4go.Debug("Using 256 color mode") mode256 = true } if !mode256 { pal = pal[:10] // Not correct, but whatever pal[termbox.ColorBlack] = termbox.RGB{0, 0, 0} pal[termbox.ColorWhite] = termbox.RGB{255, 255, 255} pal[termbox.ColorRed] = termbox.RGB{255, 0, 0} pal[termbox.ColorGreen] = termbox.RGB{0, 255, 0} pal[termbox.ColorBlue] = termbox.RGB{0, 0, 255} pal[termbox.ColorMagenta] = termbox.RGB{255, 0, 255} pal[termbox.ColorYellow] = termbox.RGB{255, 255, 0} pal[termbox.ColorCyan] = termbox.RGB{0, 255, 255} diff := func(i, j byte) int { v := int(i) - int(j) if v < 0 { return -v } return v } palLut = func(col textmate.Color) termbox.Attribute { mindist := 10000000 mini := 0 for i, c := range pal { if dist := diff(c.R, col.R) + diff(c.G, col.G) + diff(c.B, col.B); dist < mindist { mindist = dist mini = i } } return termbox.Attribute(mini) } } else { palLut = func(col textmate.Color) termbox.Attribute { tc := termbox.RGB{col.R, col.G, col.B} for i, c := range pal { if c == tc { return termbox.Attribute(i) } } l := len(pal) pal = append(pal, tc) return termbox.Attribute(l) } } for i, s := range scheme.Settings { var ( fi = defaultFg bi = defaultBg ) if fg, ok := s.Settings["foreground"]; ok { fi = palLut(fg) if i == 0 { defaultFg = fi } } if bg, ok := s.Settings["background"]; ok { bi = palLut(bg) if i == 0 { defaultBg = bi } } schemelut[s.Scope] = [2]termbox.Attribute{fi, bi} } if mode256 { termbox.SetColorPalette(pal) } evchan := make(chan termbox.Event, 32) defer func() { close(evchan) termbox.Close() fmt.Println(util.Prof) }() w := ed.NewWindow() v := w.OpenFile("main.go", 0) v.Settings().Set("trace", true) v.Settings().Set("syntax", "../../3rdparty/bundles/go.tmbundle/Syntaxes/Go.tmLanguage") c.Buffer().AddCallback(t.scroll) sel := v.Sel() sel.Clear() // end := v.Buffer().Size() - 2 sel.Add(Region{0, 0}) // sel.Add(Region{end - 22, end - 22}) // sel.Add(Region{end - 16, end - 20}) // sel.Add(Region{end - 13, end - 10}) go func() { for { evchan <- termbox.PollEvent() } }() { w, h := termbox.Size() t.lock.Lock() t.layout[v] = layout{0, 0, w, h - console_height - 1, Region{}, 0} t.layout[c] = layout{0, h - console_height + 1, w, console_height - 5, Region{}, 0} t.lock.Unlock() t.Show(v, Region{1, 1}) } t.Show(v, Region{100, 100}) t.Show(v, Region{1, 1}) go func() { ed.Init() sublime.Init() }() for { p := util.Prof.Enter("mainloop") blink_phase := time.Second if p, ok := ed.Settings().Get("caret_blink_phase", 1.0).(float64); ok { blink_phase = time.Duration(float64(time.Second) * p) } timer := time.NewTimer(blink_phase / 2) select { case ev := <-evchan: mp := util.Prof.Enter("evchan") limit := 3 loop: switch ev.Type { case termbox.EventError: log4go.Debug("error occured") return case termbox.EventKey: var kp backend.KeyPress if ev.Ch != 0 { kp.Key = backend.Key(ev.Ch) } else if v2, ok := lut[ev.Key]; ok { kp = v2 } else { break } if ev.Key == termbox.KeyCtrlQ { return } ed.HandleInput(kp) blink = true } if len(evchan) > 0 { limit-- ev = <-evchan goto loop } mp.Exit() case <-timer.C: // // case <-time.After(blink_phase / 2): blink = !blink t.render() // // // Divided by two since we're only doing a simple toggle blink // // // TODO(q): Shouldn't redraw if blink is disabled... } timer.Stop() p.Exit() } }
func (t *tbfe) scroll(b Buffer, pos, delta int) { //fmt.Printf(string(b.Runes()[pos : pos+delta])) t.Show(backend.GetEditor().Console(), Region{b.Size(), b.Size()}) }
func init() { sublime_methods = append(sublime_methods, py.Method{Name: "console", Func: sublime_Console}, py.Method{Name: "set_timeout", Func: sublime_set_timeout}) backend.GetEditor() l := py.InitAndLock() defer l.Unlock() // py.InitializeEx(false) m, err := py.InitModule("sublime", sublime_methods) if err != nil { panic(err) } type class struct { name string c *py.Class } classes := []class{ {"Region", &_regionClass}, {"RegionSet", &_region_setClass}, {"View", &_viewClass}, {"Window", &_windowClass}, {"Edit", &_editClass}, {"Settings", &_settingsClass}, {"WindowCommandGlue", &_windowCommandGlueClass}, {"TextCommandGlue", &_textCommandGlueClass}, {"ApplicationCommandGlue", &_applicationCommandGlueClass}, {"OnQueryContextGlue", &_onQueryContextGlueClass}, {"ViewEventGlue", &_viewEventGlueClass}, } type constant struct { name string constant int } constants := []constant{ {"OP_EQUAL", int(backend.OpEqual)}, {"OP_NOT_EQUAL", int(backend.OpNotEqual)}, {"OP_REGEX_MATCH", int(backend.OpRegexMatch)}, {"OP_NOT_REGEX_MATCH", int(backend.OpNotRegexMatch)}, {"OP_REGEX_CONTAINS", int(backend.OpRegexContains)}, {"OP_NOT_REGEX_CONTAINS", int(backend.OpNotRegexContains)}, {"INHIBIT_WORD_COMPLETIONS", 0}, {"INHIBIT_EXPLICIT_COMPLETIONS", 0}, {"LITERAL", 0}, {"IGNORECASE", 0}, {"CLASS_WORD_START", 0}, {"CLASS_WORD_END", 0}, {"CLASS_PUNCTUATION_START", 0}, {"CLASS_PUNCTUATION_END", 0}, {"CLASS_SUB_WORD_START", 0}, {"CLASS_SUB_WORD_END", 0}, {"CLASS_LINE_START", 0}, {"CLASS_LINE_END", 0}, {"CLASS_EMPTY_LINE", 0}, {"DRAW_EMPTY", int(render.DRAW_EMPTY)}, {"HIDE_ON_MINIMAP", int(render.HIDE_ON_MINIMAP)}, {"DRAW_EMPTY_AS_OVERWRITE", int(render.DRAW_EMPTY_AS_OVERWRITE)}, {"DRAW_NO_FILL", int(render.DRAW_NO_FILL)}, {"DRAW_NO_OUTLINE", int(render.DRAW_NO_OUTLINE)}, {"DRAW_SOLID_UNDERLINE", int(render.DRAW_SOLID_UNDERLINE)}, {"DRAW_STIPPLED_UNDERLINE", int(render.DRAW_STIPPLED_UNDERLINE)}, {"DRAW_SQUIGGLY_UNDERLINE", int(render.DRAW_SQUIGGLY_UNDERLINE)}, {"PERSISTENT", int(render.PERSISTENT)}, {"HIDDEN", int(render.HIDDEN)}, } for _, cl := range classes { c, err := cl.c.Create() if err != nil { panic(err) } if err := m.AddObject(cl.name, c); err != nil { panic(err) } } for _, c := range constants { if err := m.AddIntConstant(c.name, c.constant); err != nil { panic(err) } } py.AddToPath("../../backend/packages/") py.AddToPath("../../3rdparty/bundles/") py.AddToPath("../../backend/sublime/") }
func (t *tbfe) loop() { backend.OnNew.Add(func(v *backend.View) { v.Settings().AddOnChange("lime.frontend.html.render", func() { t.dirty = true }) }) backend.OnModified.Add(func(v *backend.View) { t.dirty = true }) backend.OnSelectionModified.Add(func(v *backend.View) { t.dirty = true }) ed := backend.GetEditor() ed.SetFrontend(t) ed.LogInput(false) ed.LogCommands(false) c := ed.Console() if sc, err := textmate.LoadTheme("../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme"); err != nil { log4go.Error(err) } else { scheme = sc } defer func() { fmt.Println(util.Prof) }() w := ed.NewWindow() v := w.OpenFile("main.go", 0) v.Settings().Set("trace", true) v.Settings().Set("syntax", "../../3rdparty/bundles/go.tmbundle/Syntaxes/Go.tmLanguage") c.Buffer().AddCallback(t.scroll) sel := v.Sel() sel.Clear() // end := v.Buffer().Size() - 2 sel.Add(Region{0, 0}) // sel.Add(Region{end - 22, end - 22}) // sel.Add(Region{end - 16, end - 20}) // sel.Add(Region{end - 13, end - 10}) { w, h := 800, 600 t.lock.Lock() t.layout[v] = layout{0, 0, w, h - console_height - 1, Region{}, 0} t.layout[c] = layout{0, h - console_height + 1, w, console_height - 5, Region{}, 0} t.lock.Unlock() t.Show(v, Region{1, 1}) } t.Show(v, Region{100, 100}) t.Show(v, Region{1, 1}) go func() { ed.Init() sublime.Init() }() log4go.Debug("serving") http.HandleFunc("/key", t.key) http.HandleFunc("/", t.ServeHTTP) http.HandleFunc("/view", t.view) if err := http.ListenAndServe("localhost:8080", nil); err != nil { log4go.Error("Error serving: %s", err) } log4go.Debug("Done") }
func TestSublime(t *testing.T) { ed := backend.GetEditor() ed.Console().Buffer().AddCallback(func(b primitives.Buffer, pos, delta int) { t.Logf("%s", b.Substr(primitives.Region{pos, pos + delta})) }) w := ed.NewWindow() Init() l := py.NewLock() py.AddToPath("testdata") py.AddToPath("testdata/plugins") if m, err := py.Import("sublime_plugin"); err != nil { t.Fatal(err) } else { scanpath("testdata/", m) } subl, err := py.Import("sublime") if err != nil { t.Fatal(err) } if w, err := _windowClass.Alloc(1); err != nil { t.Fatal(err) } else { (w.(*Window)).data = &backend.Window{} subl.AddObject("test_window", w) } og, err := py.Import("objgraph") if err != nil { log4go.Debug(err) return } gr, err := og.Dict().GetItemString("show_growth") if err != nil { log4go.Debug(err) return } log4go.Debug("Before") gr.Base().CallFunctionObjArgs() if dir, err := os.Open("testdata"); err != nil { t.Error(err) } else if files, err := dir.Readdirnames(0); err != nil { t.Error(err) } else { for _, fn := range files { if filepath.Ext(fn) == ".py" { log4go.Debug("Running %s", fn) if _, err := py.Import(fn[:len(fn)-3]); err != nil { log4go.Error(err) t.Error(err) } else { log4go.Debug("Ran %s", fn) } } } } var f func(indent string, v py.Object, buf *bytes.Buffer) f = func(indent string, v py.Object, buf *bytes.Buffer) { b := v.Base() if dir, err := b.Dir(); err != nil { t.Error(err) } else { if l, ok := dir.(*py.List); ok { sl := l.Slice() if indent == "" { for _, v2 := range sl { if item, err := b.GetAttr(v2); err != nil { t.Error(err) } else { ty := item.Type() line := fmt.Sprintf("%s%s\n", indent, v2) buf.WriteString(line) if ty == py.TypeType { f(indent+"\t", item, buf) } item.Decref() } } } else { for _, v2 := range sl { buf.WriteString(fmt.Sprintf("%s%s\n", indent, v2)) } } } else { ty := dir.Type() t.Error("Unexpected type:", ty) } dir.Decref() } } buf := bytes.NewBuffer(nil) f("", subl, buf) l.Unlock() const expfile = "testdata/api.txt" if d, err := ioutil.ReadFile(expfile); err != nil { if err := ioutil.WriteFile(expfile, buf.Bytes(), 0644); err != nil { t.Error(err) } } else if diff := util.Diff(string(d), buf.String()); diff != "" { t.Error(diff) } ed.LogCommands(true) tests := []string{ "state", "registers", "settings", "constants", "registers", "cmd_data", "marks", } for _, test := range tests { ed.CommandHandler().RunWindowCommand(w, "vintage_ex_run_data_file_based_tests", backend.Args{"suite_name": test}) } for _, w := range ed.Windows() { for _, v := range w.Views() { if strings.HasSuffix(v.Buffer().FileName(), "sample.txt") { continue } if strings.Index(v.Buffer().Substr(primitives.Region{0, v.Buffer().Size()}), "FAILED") != -1 { t.Error(v.Buffer()) } } } log4go.Debug("After") l.Lock() gr.Base().CallFunctionObjArgs() l.Unlock() var v *backend.View for _, v2 := range w.Views() { if v == nil || v2.Buffer().Size() > v.Buffer().Size() { v = v2 } } // log4go.Debug("Before") // gr.Base().CallFunctionObjArgs() // for i := 0; i < 500; i++ { // ed.CommandHandler().RunTextCommand(v, "set_motion", backend.Args{"motion": "vi_j"}) // } // for i := 0; i < 500; i++ { // ed.CommandHandler().RunTextCommand(v, "set_motion", backend.Args{"motion": "vi_k"}) // } // log4go.Debug("After") // gr.Base().CallFunctionObjArgs() }
func main() { cleanup() var sublime_methods = "" sn := func(t reflect.Type, m reflect.Method) string { sn := "sublime_" + m.Name sublime_methods += fmt.Sprintf("{Name: \"%s\", Func: %s},\n", pyname(m.Name)[1:], sn) return sn } data := [][]string{ {"../backend/sublime/region_generated.go", generateWrapper(reflect.TypeOf(text.Region{}), true, regexp.MustCompile("Cut").MatchString)}, {"../backend/sublime/regionset_generated.go", generateWrapper(reflect.TypeOf(&text.RegionSet{}), false, regexp.MustCompile("Less|Swap|Adjust|Has|Cut").MatchString)}, {"../backend/sublime/edit_generated.go", generateWrapper(reflect.TypeOf(&backend.Edit{}), false, regexp.MustCompile("Apply|Undo").MatchString)}, {"../backend/sublime/view_generated.go", generateWrapper(reflect.TypeOf(&backend.View{}), false, regexp.MustCompile("Buffer|Syntax|CommandHistory|Show|AddRegions|UndoStack|Transform").MatchString)}, {"../backend/sublime/window_generated.go", generateWrapper(reflect.TypeOf(&backend.Window{}), false, regexp.MustCompile("OpenFile|SetActiveView").MatchString)}, {"../backend/sublime/settings_generated.go", generateWrapper(reflect.TypeOf(&text.Settings{}), false, regexp.MustCompile("Parent|Set|Get|UnmarshalJSON").MatchString)}, {"../backend/sublime/view_buffer_generated.go", generatemethodsEx( reflect.TypeOf(backend.GetEditor().Console().Buffer()), regexp.MustCompile("Erase|Insert|Substr|SetFile|AddCallback|Data|Runes|Settings|Index|Close|Unlock|Lock").MatchString, "o.data.Buffer().", func(t reflect.Type, m reflect.Method) string { mn := "" switch m.Name { case "Line", "LineR", "FullLine", "FullLineR", "WordR", "Word": mn = strings.ToLower(m.Name) case "Id": mn = "Py_buffer_id" default: mn = "Py" + pyname(m.Name) } return "(o *View) " + mn })}, {"../backend/sublime/commands_generated.go", generatemethodsEx(reflect.TypeOf(backend.GetEditor().CommandHandler()), regexp.MustCompile("RunWindowCommand|RunTextCommand|RunApplicationCommand").MatchString, "backend.GetEditor().CommandHandler().", sn), }, {"../backend/sublime/frontend_generated.go", generatemethodsEx(reflect.TypeOf(backend.GetEditor().Frontend()), regexp.MustCompile("Show|VisibleRegion").MatchString, "backend.GetEditor().Frontend().", sn), }, {"../backend/sublime/sublime_api_generated.go", generatemethodsEx(reflect.TypeOf(backend.GetEditor()), regexp.MustCompile("Info|HandleInput|CommandHandler|Windows|Frontend|Console|SetActiveWindow|Init").MatchString, "backend.GetEditor().", sn), }, } data[len(data)-1][1] += fmt.Sprintf(`var sublime_methods = []py.Method{ %s }`, sublime_methods) for _, gen := range data { if gen[0] == "" { continue } wr := `// This file was generated as part of a build step and shouldn't be manually modified package sublime import ( "fmt" "lime/3rdparty/libs/gopy/lib" "lime/backend" "github.com/quarnster/util/text" ) var ( _ = backend.View{} _ = text.Region{} _ = fmt.Errorf ) ` + gen[1] if err := ioutil.WriteFile(gen[0], []byte(wr), 0644); err != nil { panic(err) } else { c := exec.Command("go", "fmt", gen[0]) if o, err := c.CombinedOutput(); err != nil { panic(fmt.Errorf("%s, %s", o, err)) } else { fmt.Printf("%s", string(o)) } } } }
func (t *tbfe) loop() { qml.Init(nil) engine := qml.NewEngine() engine.Context().SetVar("lines", t) engine.Context().SetVar("frontend", t) engine.Context().SetVar("editor", backend.GetEditor()) backend.OnNew.Add(func(v *backend.View) { v.Settings().AddOnChange("lime.frontend.html.render", func(name string) { t.dirty = true }) }) backend.OnModified.Add(func(v *backend.View) { t.dirty = true }) backend.OnSelectionModified.Add(func(v *backend.View) { t.dirty = true }) ed := backend.GetEditor() ed.SetFrontend(t) ed.LogInput(false) ed.LogCommands(false) c := ed.Console() if sc, err := textmate.LoadTheme("../../3rdparty/bundles/TextMate-Themes/GlitterBomb.tmTheme"); err != nil { log4go.Error(err) } else { scheme = sc } defer func() { fmt.Println(util.Prof) }() w := ed.NewWindow() v := w.OpenFile("main.go", 0) v.Settings().Set("trace", true) v.Settings().Set("syntax", "../../3rdparty/bundles/go.tmbundle/Syntaxes/Go.tmLanguage") c.Buffer().AddCallback(t.scroll) sel := v.Sel() sel.Clear() sel.Add(Region{0, 0}) { w, h := 800, 600 t.lock.Lock() t.layout[v] = layout{0, 0, w, h - console_height - 1, Region{}, 0} t.layout[c] = layout{0, h - console_height + 1, w, console_height - 5, Region{}, 0} t.lock.Unlock() t.Show(v, Region{1, 1}) } t.Show(v, Region{100, 100}) t.Show(v, Region{1, 1}) t.Len, _ = v.Buffer().RowCol(v.Buffer().Size()) ed.Init() sublime.Init() component, err := engine.LoadFile("main.qml") if err != nil { log4go.Exit(err) } window := component.CreateWindow(nil) window.Show() qml.Changed(t, &t.Len) log4go.Debug("Done") window.Wait() }