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

Code before:
	fini        int32
	cursors     []*Cursor
	curCursor   int
	StartCursor Loc

	// OptionCallback is called after a buffer option value is changed.
	// The display module registers its OptionCallback to ensure the buffer window
	// is properly updated when needed. This is a workaround for the fact that
	// the buffer module cannot directly call the display's API (it would mean
	// a circular dependency between packages).
	OptionCallback func(option string, nativeValue interface{})

	// The display module registers its own GetVisualX function for getting
	// the correct visual x location of a cursor when softwrap is used.
	// This is hacky. Maybe it would be better to move all the visual x logic
	// from buffer to display, but it would require rewriting a lot of code.
	GetVisualX func(loc Loc) int

	// Last search stores the last successful search
	LastSearch      string
	LastSearchRegex bool
	// HighlightSearch enables highlighting all instances of the last successful search
	HighlightSearch bool

	// OverwriteMode is used to identify if a inserted character shall replace
	// the following character.
	OverwriteMode bool
}

// NewBufferFromFileAtLoc opens a new buffer with a given cursor location
// If cursorLoc is {-1, -1} the location does not overwrite what the cursor location
// would otherwise be (start of file, or saved cursor position if `savecursor` is
// enabled)
func NewBufferFromFileAtLoc(path string, btype BufType, cursorLoc Loc) (*Buffer, error) {
	var err error
	filename := path
	if config.GetGlobalOption("parsecursor").(bool) && cursorLoc.X == -1 && cursorLoc.Y == -1 {
		var cursorPos []string
		filename, cursorPos = util.GetPathAndCursorPosition(filename)
		cursorLoc, err = ParseCursorLocation(cursorPos)
		if err != nil {
			cursorLoc = Loc{-1, -1}
		}
	}

	filename, err = util.ReplaceHome(filename)
	if err != nil {
		return nil, err
	}

	f, err := os.OpenFile(filename, os.O_WRONLY, 0)

Review comment (suggestion):
`an` is used instead of `a` before a word than begins with a vowel... And regardless, this sentence sounds unclear and weird, don't you find? I suppose a lot of people would have a hard time trying to understand this comment, before finally realizing "ah, that's simply what the Insert key does".

If you're so keen to reword the original comment, let's reword it to make it more clear, not less clear, e.g. something like: "OverwriteMode indicates that we are in overwrite mode (toggled by Insert key by default) i.e. that typing a character shall replace the character under the cursor instead of inserting a character before it."

Code after:
	fini        int32
	cursors     []*Cursor
	curCursor   int
	StartCursor Loc

	// OptionCallback is called after a buffer option value is changed.
	// The display module registers its OptionCallback to ensure the buffer window
	// is properly updated when needed. This is a workaround for the fact that
	// the buffer module cannot directly call the display's API (it would mean
	// a circular dependency between packages).
	OptionCallback func(option string, nativeValue interface{})

	// The display module registers its own GetVisualX function for getting
	// the correct visual x location of a cursor when softwrap is used.
	// This is hacky. Maybe it would be better to move all the visual x logic
	// from buffer to display, but it would require rewriting a lot of code.
	GetVisualX func(loc Loc) int

	// Last search stores the last successful search
	LastSearch      string
	LastSearchRegex bool
	// HighlightSearch enables highlighting all instances of the last successful search
	HighlightSearch bool

	// OverwriteMode indicates that we are in overwrite mode (toggled by
	// Insert key by default) i.e. that typing a character shall replace the
	// character under the cursor instead of inserting a character before it.
	OverwriteMode bool
}

// NewBufferFromFileAtLoc opens a new buffer with a given cursor location
// If cursorLoc is {-1, -1} the location does not overwrite what the cursor location
// would otherwise be (start of file, or saved cursor position if `savecursor` is
// enabled)
func NewBufferFromFileAtLoc(path string, btype BufType, cursorLoc Loc) (*Buffer, error) {
	var err error
	filename := path
	if config.GetGlobalOption("parsecursor").(bool) && cursorLoc.X == -1 && cursorLoc.Y == -1 {
		var cursorPos []string
		filename, cursorPos = util.GetPathAndCursorPosition(filename)
		cursorLoc, err = ParseCursorLocation(cursorPos)
		if err != nil {
			cursorLoc = Loc{-1, -1}
		}
	}

	filename, err = util.ReplaceHome(filename)
	if err != nil {
		return nil, err
	}