Пример #1
0
func file_save_current() {
	var be, en gtk.TextIter
	rec, found := file_map[cur_file]
	if false == found {
		rec = new(FileRecord)
	}
	rec.buf = ([]byte)(get_source())
	rec.modified = source_buf.GetModified()
	source_buf.GetSelectionBounds(&be, &en)
	rec.sel_be = be.GetOffset()
	rec.sel_en = en.GetOffset()
	file_stack_push(cur_file)
	if found {
		runtime.GC()
	}
}
Пример #2
0
func gofmt(file string) {
	rec, _ := file_map[file]
	var buf []byte
	if file == cur_file {
		buf = []byte(get_source())
	} else {
		buf = rec.buf
	}
	bin := os.Getenv("GOBIN")
	if bin != "" {
		bin = filepath.Join(bin, "gofmt")
	} else {
		bin, _ = exec.LookPath("gofmt")
	}
	std, error, e := get_output([]string{bin}, buf)
	if e != nil {
		tabby_log(e.Error())
		return
	}
	if file == cur_file {
		error_buf.SetText(string(error))
	} else {
		rec.error = error
	}
	if 0 != len(error) {
		return
	}
	if file == cur_file {
		if string(buf) != string(std) {
			var be, en gtk.TextIter
			source_buf.GetSelectionBounds(&be, &en)
			sel_be := be.GetOffset()
			source_buf.SetText(string(std))
			source_buf.GetIterAtOffset(&be, sel_be)
			move_focus_and_selection(&be, &be)
		}
	} else if string(rec.buf) != string(std) {
		rec.buf = std
		rec.modified = true
	}
}