Repository: zyedidia/micro
File: internal/action/bufpane.go (Go)

Code before:
	if err != nil {
		screen.TermMessage(err)
	}
	return b
}

// PluginCBRune is the same as PluginCB but also passes a rune to the plugins
func (h *BufPane) PluginCBRune(cb string, r rune) bool {
	b, err := config.RunPluginFnBool(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
	if err != nil {
		screen.TermMessage(err)
	}
	return b
}

func (h *BufPane) resetMouse() {
	for me := range h.mousePressed {
		delete(h.mousePressed, me)
	}
}

// OpenBuffer opens the given buffer in this pane.
func (h *BufPane) OpenBuffer(b *buffer.Buffer) {
	h.Buf.Close()
	h.Buf = b
	// Set the OverwriteModeActive by default to false on open
	h.Buf.OverwriteModeActive = false
	h.BWindow.SetBuffer(b)
	h.Cursor = b.GetActiveCursor()
	h.Resize(h.GetView().Width, h.GetView().Height)
	h.initialRelocate()
	// Set mouseReleased to true because we assume the mouse is not being
	// pressed when the editor is opened
	h.resetMouse()
	h.lastClickTime = time.Time{}
}

// GotoLoc moves the cursor to a new location and adjusts the view accordingly.
// Use GotoLoc when the new location may be far away from the current location.
func (h *BufPane) GotoLoc(loc buffer.Loc) {
	sloc := h.SLocFromLoc(loc)
	d := h.Diff(h.SLocFromLoc(h.Cursor.Loc), sloc)

	h.Cursor.GotoLoc(loc)

	// If the new location is far away from the previous one,
	// ensure the cursor is at 25% of the window height
	height := h.BufView().Height
	if util.Abs(d) >= height {
		v := h.GetView()
		v.StartLine = h.Scroll(sloc, -height/4)

Review comment (suggestion):
The comment tells *exactly* what is entirely obvious without the comment, and nothing more. (The original comment for `isOverwriteMode` at least told something more; although not exactly a revelation either.)

Code after:
	if err != nil {
		screen.TermMessage(err)
	}
	return b
}

// PluginCBRune is the same as PluginCB but also passes a rune to the plugins
func (h *BufPane) PluginCBRune(cb string, r rune) bool {
	b, err := config.RunPluginFnBool(h.Buf.Settings, cb, luar.New(ulua.L, h), luar.New(ulua.L, string(r)))
	if err != nil {
		screen.TermMessage(err)
	}
	return b
}

func (h *BufPane) resetMouse() {
	for me := range h.mousePressed {
		delete(h.mousePressed, me)
	}
}

// OpenBuffer opens the given buffer in this pane.
func (h *BufPane) OpenBuffer(b *buffer.Buffer) {
	h.Buf.Close()
	h.Buf = b
	h.BWindow.SetBuffer(b)
	h.Cursor = b.GetActiveCursor()
	h.Resize(h.GetView().Width, h.GetView().Height)
	h.initialRelocate()
	// Set mouseReleased to true because we assume the mouse is not being
	// pressed when the editor is opened
	h.resetMouse()
	h.lastClickTime = time.Time{}
}

// GotoLoc moves the cursor to a new location and adjusts the view accordingly.
// Use GotoLoc when the new location may be far away from the current location.
func (h *BufPane) GotoLoc(loc buffer.Loc) {
	sloc := h.SLocFromLoc(loc)
	d := h.Diff(h.SLocFromLoc(h.Cursor.Loc), sloc)

	h.Cursor.GotoLoc(loc)

	// If the new location is far away from the previous one,
	// ensure the cursor is at 25% of the window height
	height := h.BufView().Height
	if util.Abs(d) >= height {
		v := h.GetView()
		v.StartLine = h.Scroll(sloc, -height/4)
		h.ScrollAdjust()
		v.StartCol = 0