Example #1
0
func find_prev_instance(start, be, en *gtk.GtkTextIter, pattern string) bool {
	if start.BackwardSearch(pattern, 0, be, en, nil) {
		return true
	}
	source_buf.GetEndIter(be)
	return be.BackwardSearch(pattern, 0, be, en, nil)
}
Example #2
0
func find_next_instance(start, be, en *gtk.GtkTextIter, pattern string) bool {
	if start.ForwardSearch(pattern, 0, be, en, nil) {
		return true
	}
	source_buf.GetStartIter(be)
	return be.ForwardSearch(pattern, 0, be, en, nil)
}
Example #3
0
func mark_set_cb() {
	var cur gtk.GtkTextIter
	var be, en gtk.GtkTextIter

	source_buf.GetSelectionBounds(&be, &en)
	selection := source_buf.GetSlice(&be, &en, false)
	if prev_selection == selection {
		return
	}
	prev_selection = selection

	if selection_flag {
		source_buf.GetStartIter(&be)
		source_buf.GetEndIter(&en)
		source_buf.RemoveTagByName("instance", &be, &en)
		selection_flag = false
	}

	sel_len := len(selection)
	if (sel_len <= 1) || (sel_len >= MAX_SEL_LEN) {
		return
	} else {
		selection_flag = true
	}

	source_buf.GetStartIter(&cur)
	for cur.ForwardSearch(selection, 0, &be, &cur, nil) {
		source_buf.ApplyTagByName("instance", &be, &cur)
	}
}
Example #4
0
File: tools.go Project: mattn/tabby
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.String())
		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.GtkTextIter
			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
	}
}
Example #5
0
func fnr_find_next(pattern string, global bool, map_filled *bool, m *map[string]int) bool {
	var be, en, scope_en gtk.GtkTextIter
	get_iter_at_mark_by_name("fnr_en", &scope_en)
	get_iter_at_mark_by_name("selection_bound", &en)
	if en.ForwardSearch(pattern, 0, &be, &en, &scope_en) {
		move_focus_and_selection(&be, &en)
		return true
	}
	// Have to switch to next file or to beginning of current depending on <global>.
	if global {
		// Switch to next file.
		fnr_find_next_fill_global_map(pattern, m, map_filled)
		next_file := pop_string_from_map(m)
		if "" == next_file {
			return false
		}
		file_save_current()
		file_switch_to(next_file)
		fnr_refresh_scope(true)
		source_buf.GetStartIter(&be)
		source_buf.MoveMarkByName("insert", &be)
		source_buf.MoveMarkByName("selection_bound", &be)
		return fnr_find_next(pattern, global, map_filled, m)
	} else {
		// Temporary fix. Is there necessity to search the document all over again?
		return false
		// Start search from beginning of scope.
		// get_iter_at_mark_by_name("fnr_be", &be)
		// if be.ForwardSearch(pattern, 0, &be, &en, &scope_en) {
		//	move_focus_and_selection(&be, &en)
		//	return true
		//} else {
		//	return false
		//}
	}
	return false
}
Example #6
0
func file_save_current() {
	var be, en gtk.GtkTextIter
	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)
	runtime.GC()
}