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

Code before:
func (h *BufPane) ReopenCmd(args []string) {
	if h.Buf.Modified() {
		InfoBar.YNPrompt("Save file before reopen?", func(yes, canceled bool) {
			if !canceled && yes {
				h.Save()
				h.ReOpen()
			} else if !canceled {
				h.ReOpen()
			}
		})
	} else {
		h.ReOpen()
	}
}

func (h *BufPane) openHelp(page string, hsplit bool) error {
	if data, err := config.FindRuntimeFile(config.RTHelp, page).Data(); err != nil {
		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 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:]
		}


Review comment (refactor):
Is it a good idea to just remove this unconditionally? Shouldn't we add e.g. another flag for that (e.g. `-n` meaning "new pane"), or e.g. another option?

Code after:
func (h *BufPane) ReopenCmd(args []string) {
	if h.Buf.Modified() {
		InfoBar.YNPrompt("Save file before reopen?", func(yes, canceled bool) {
			if !canceled && yes {
				h.Save()
				h.ReOpen()
			} else if !canceled {
				h.ReOpen()
			}
		})
	} else {
		h.ReOpen()
	}
}

func (h *BufPane) openHelp(page string, hsplit bool, forceSplit bool) error {
	if data, err := config.FindRuntimeFile(config.RTHelp, page).Data(); err != nil {
		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":