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

Code before:
		return errors.New(fmt.Sprintf("Unable to load help text for %s: %v", page, err))
	} else {
		helpBuffer := buffer.NewBufferFromString(string(data), page+".md", buffer.BTHelp)
		helpBuffer.SetName("Help " + page)
		helpBuffer.SetOptionNative("hltaberrors", false)
		helpBuffer.SetOptionNative("hltrailingws", false)

		if h.Buf.Type == buffer.BTHelp {
			h.OpenBuffer(helpBuffer)
		} else if hsplit {
			h.HSplitBuf(helpBuffer)
		} else {
			h.VSplitBuf(helpBuffer)
		}
	}
	return nil
}

// HelpCmd tries to open the given help page in a horizontal split
func (h *BufPane) HelpCmd(args []string) {
	hsplit := true
	if len(args) < 1 {
		// Open the default help if the user just typed "> help"
		h.openHelp("help", hsplit)
	} else {
		if args[0] == "hsplit" || args[0] == "vsplit" {
			if len(args) == 1 {
				InfoBar.Error("Please provide help for ", args[0])
				return
			}
			if args[0] == "vsplit" {
				hsplit = false
			}
			args = args[1:]
		}

		if config.FindRuntimeFile(config.RTHelp, args[0]) != nil {
			err := h.openHelp(args[0], hsplit)
			if err != nil {
				InfoBar.Error(err)
			}
		} else {
			InfoBar.Error("Sorry, no help for ", args[0])
		}
	}
}

// VSplitCmd opens a vertical split with file given in the first argument
// If no file is given, it opens an empty buffer in a new split
func (h *BufPane) VSplitCmd(args []string) {
	if len(args) == 0 {

Review comment (suggestion):
It might be better to add a flag e.g. `-v` (meaning vsplit) that can be anywhere in the command, not necessarily the 1st argument, similarly to the `replace` command.

...Or maybe we shouldn't overthink this and should simply add an option, e.g. `helpsplit`.

Code after:
		return errors.New(fmt.Sprintf("Unable to load help text for %s: %v", page, err))
	} else {
		helpBuffer := buffer.NewBufferFromString(string(data), page+".md", buffer.BTHelp)
		helpBuffer.SetName("Help " + page)
		helpBuffer.SetOptionNative("hltaberrors", false)
		helpBuffer.SetOptionNative("hltrailingws", false)

		if h.Buf.Type == buffer.BTHelp && !forceSplit {
			h.OpenBuffer(helpBuffer)
		} else if hsplit {
			h.HSplitBuf(helpBuffer)
		} else {
			h.VSplitBuf(helpBuffer)
		}
	}
	return nil
}

// HelpCmd tries to open the given help page according to the split type
// configured with the "helpsplit" option. It can be overriden by the optional
// arguments "-vpslit" or "-hsplit". In case more than one help page is given
// as argument then it opens all of them with the defined split type.
func (h *BufPane) HelpCmd(args []string) {
	hsplit := config.GlobalSettings["helpsplit"] == "hsplit"
	if len(args) < 1 {
		// Open the default help if the user just typed "> help"
		h.openHelp("help", hsplit, false)
	} else {
		var topics []string
		forceSplit := false
		const errSplit = "hsplit and vsplit are not allowed at the same time"
		for _, arg := range args {
			switch arg {
			case "-vsplit":
				if forceSplit {
					InfoBar.Error(errSplit)
					return
				}
				hsplit = false
				forceSplit = true
			case "-hsplit":
				if forceSplit {
					InfoBar.Error(errSplit)
					return
				}
				hsplit = true
				forceSplit = true
			default:
				topics = append(topics, arg)
			}
		}