func (u *Undo) Exec(target interface{}) (executed, consume bool) { finder, ok := target.(EditorFinder) if !ok { return false, false } editor := finder.CurrentEditor() if editor == nil { u.err = "undo: no file open" return true, true } history := editor.History() edit, ok := history.Undo() if !ok { u.warn = "undo: nothing to undo" return true, true } text, _ := editor.Controller().ReplaceAt(editor.Runes(), edit.At, edit.At+len(edit.New), edit.Old) editor.Controller().SetTextRunes(text) absDelta := edit.Delta if absDelta < 0 { absDelta = -absDelta } editor.Controller().SetSelection(gxui.CreateTextSelection(edit.At, edit.At+absDelta, true)) editor.ScrollToRune(edit.At) return true, true }
func (gi *GotoDef) Exec(on interface{}) (executed, consume bool) { opener, ok := on.(LineOpener) if !ok { return false, false } editor := opener.CurrentEditor() if editor == nil { return true, true } proj := opener.Project() lastCaret := editor.Controller().LastCaret() cmd := exec.Command("godef", "-f", editor.Filepath(), "-o", strconv.Itoa(lastCaret), "-i") cmd.Stdin = bytes.NewBufferString(editor.Text()) errBuffer := &bytes.Buffer{} cmd.Stderr = errBuffer cmd.Env = []string{"PATH=" + os.Getenv("PATH")} if proj.Gopath != "" { cmd.Env[0] += string(os.PathListSeparator) + filepath.Join(proj.Gopath, "bin") cmd.Env = append(cmd.Env, "GOPATH="+proj.Gopath) } output, err := cmd.Output() if err != nil { gi.err = fmt.Sprintf("godef error: %s", string(output)) return true, true } path, line, column, err := parseGodef(output) if err != nil { gi.err = err.Error() return true, true } opener.OpenLine(path, line, column) return true, true }