Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/action/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,8 @@ func (h *BufPane) ToggleHelp() bool {
if h.Buf.Type == buffer.BTHelp {
h.Quit()
} else {
h.openHelp("help")
hsplit := config.GlobalSettings["helpsplit"] == "hsplit"
h.openHelp("help", hsplit, false)
}
return true
}
Expand Down
98 changes: 72 additions & 26 deletions internal/action/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ func (h *BufPane) ReopenCmd(args []string) {
}
}

func (h *BufPane) openHelp(page string) error {
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 {
Expand All @@ -437,33 +437,74 @@ func (h *BufPane) openHelp(page string) error {
helpBuffer.SetOptionNative("hltaberrors", false)
helpBuffer.SetOptionNative("hltrailingws", false)

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

// HelpCmd tries to open the given help page in a horizontal split
// 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")
h.openHelp("help", hsplit, false)
} else {
if config.FindRuntimeFile(config.RTHelp, args[0]) != nil {
err := h.openHelp(args[0])
if err != nil {
InfoBar.Error(err)
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)
}
}

if len(topics) < 1 {
// Do the same as without arg
h.openHelp("help", hsplit, forceSplit)
return
}
if len(topics) > 1 {
forceSplit = true
}

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

// VSplitCmd opens a vertical split with file given in the first argument
// VSplitCmd opens one or more vertical splits with the files given as arguments
// If no file is given, it opens an empty buffer in a new split
func (h *BufPane) VSplitCmd(args []string) {
if len(args) == 0 {
Expand All @@ -472,16 +513,18 @@ func (h *BufPane) VSplitCmd(args []string) {
return
}

buf, err := buffer.NewBufferFromFile(args[0], buffer.BTDefault)
if err != nil {
InfoBar.Error(err)
return
}
for _, a := range args {
buf, err := buffer.NewBufferFromFile(a, buffer.BTDefault)
if err != nil {
InfoBar.Error(err)
return
}

h.VSplitBuf(buf)
h.VSplitBuf(buf)
}
}

// HSplitCmd opens a horizontal split with file given in the first argument
// HSplitCmd opens one or more horizontal splits with the files given as arguments
// If no file is given, it opens an empty buffer in a new split
func (h *BufPane) HSplitCmd(args []string) {
if len(args) == 0 {
Expand All @@ -490,21 +533,24 @@ func (h *BufPane) HSplitCmd(args []string) {
return
}

buf, err := buffer.NewBufferFromFile(args[0], buffer.BTDefault)
if err != nil {
InfoBar.Error(err)
return
}
for _, a := range args {
buf, err := buffer.NewBufferFromFile(a, buffer.BTDefault)
if err != nil {
InfoBar.Error(err)
return
}

h.HSplitBuf(buf)
h.HSplitBuf(buf)
}
}

// EvalCmd evaluates a lua expression
func (h *BufPane) EvalCmd(args []string) {
InfoBar.Error("Eval unsupported")
}

// NewTabCmd opens the given file in a new tab
// NewTabCmd opens one or more tabs with the files given as arguments
// If no file is given, it opens an empty buffer in a new tab
func (h *BufPane) NewTabCmd(args []string) {
width, height := screen.Screen.Size()
iOffset := config.GetInfoBarOffset()
Expand Down
3 changes: 3 additions & 0 deletions internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var optionValidators = map[string]optionValidator{
"detectlimit": validateNonNegativeValue,
"encoding": validateEncoding,
"fileformat": validateChoice,
"helpsplit": validateChoice,
"matchbracestyle": validateChoice,
"multiopen": validateChoice,
"reload": validateChoice,
Expand All @@ -41,6 +42,7 @@ var optionValidators = map[string]optionValidator{
var OptionChoices = map[string][]string{
"clipboard": {"internal", "external", "terminal"},
"fileformat": {"unix", "dos"},
"helpsplit": {"hsplit", "vsplit"},
"matchbracestyle": {"underline", "highlight"},
"multiopen": {"tab", "hsplit", "vsplit"},
"reload": {"prompt", "auto", "disabled"},
Expand Down Expand Up @@ -109,6 +111,7 @@ var DefaultGlobalOnlySettings = map[string]interface{}{
"divchars": "|-",
"divreverse": true,
"fakecursor": false,
"helpsplit": "hsplit",
"infobar": true,
"keymenu": false,
"mouse": true,
Expand Down
21 changes: 15 additions & 6 deletions runtime/help/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ quotes here but these are not necessary when entering the command in micro.
This command will modify `bindings.json` and overwrite any bindings to
`key` that already exist.

* `help ['topic']`: opens the corresponding help topic. If no topic is provided
opens the default help screen. Help topics are stored as `.md` files in the
`runtime/help` directory of the source tree, which is embedded in the final
binary.
* `help ['topic'] ['flags']`: opens the corresponding help topics.
If no topic is provided opens the default help screen. If multiple topics are
provided (separated via ` `) they are opened all as splits.
Help topics are stored as `.md` files in the `runtime/help` directory of
the source tree, which is embedded in the final binary.
The `flags` are optional.
* `-hsplit`: Opens the help topic in a horizontal split
* `-vsplit`: Opens the help topic in a vertical split

The default split type is defined by the global `helpsplit` option.

* `save ['filename']`: saves the current buffer. If the file is provided it
will 'save as' the filename.
Expand Down Expand Up @@ -72,12 +78,15 @@ quotes here but these are not necessary when entering the command in micro.
command's output will be displayed in one line when it finishes running.

* `vsplit ['filename']`: opens a vertical split with `filename`. If no filename
is provided, a vertical split is opened with an empty buffer.
is provided, a vertical split is opened with an empty buffer. If multiple
files are provided (separated via ` `) they are opened all as splits.

* `hsplit ['filename']`: same as `vsplit` but opens a horizontal split instead
of a vertical split.

* `tab ['filename']`: opens the given file in a new tab.
* `tab ['filename']`: opens the given file in a new tab. If no filename
is provided, a tab is opened with an empty buffer. If multiple files are
provided (separated via ` `) they are opened all as tabs.

* `tabmove '[-+]n'`: Moves the active tab to another slot. `n` is an integer.
If `n` is prefixed with `-` or `+`, then it represents a relative position
Expand Down
7 changes: 7 additions & 0 deletions runtime/help/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ Here are the available options:
default value: `unknown`. This will be automatically overridden depending
on the file you open.

* `helpsplit`: sets the split type to be used by the `help` command.
Possible values:
* `vsplit`: open help in a vertical split pane
* `hsplit`: open help in a horizontal split pane

default value: `hsplit`

* `hlsearch`: highlight all instances of the searched text after a successful
search. This highlighting can be temporarily turned off via the
`UnhighlightSearch` action (triggered by the Esc key by default) or toggled
Expand Down