Skip to content

Commit 26f0806

Browse files
committed
action/command: Add optional flag -hsplit & -vsplit to help
1 parent d60413f commit 26f0806

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed

internal/action/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ func (h *BufPane) ToggleHelp() bool {
17231723
if h.Buf.Type == buffer.BTHelp {
17241724
h.Quit()
17251725
} else {
1726-
h.openHelp("help")
1726+
h.openHelp("help", true, false)
17271727
}
17281728
return true
17291729
}

internal/action/command.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ func (h *BufPane) ReopenCmd(args []string) {
428428
}
429429
}
430430

431-
func (h *BufPane) openHelp(page string) error {
431+
func (h *BufPane) openHelp(page string, hsplit bool, forceSplit bool) error {
432432
if data, err := config.FindRuntimeFile(config.RTHelp, page).Data(); err != nil {
433433
return errors.New(fmt.Sprintf("Unable to load help text for %s: %v", page, err))
434434
} else {
@@ -437,10 +437,12 @@ func (h *BufPane) openHelp(page string) error {
437437
helpBuffer.SetOptionNative("hltaberrors", false)
438438
helpBuffer.SetOptionNative("hltrailingws", false)
439439

440-
if h.Buf.Type == buffer.BTHelp {
440+
if h.Buf.Type == buffer.BTHelp && !forceSplit {
441441
h.OpenBuffer(helpBuffer)
442-
} else {
442+
} else if hsplit {
443443
h.HSplitBuf(helpBuffer)
444+
} else {
445+
h.VSplitBuf(helpBuffer)
444446
}
445447
}
446448
return nil
@@ -450,15 +452,49 @@ func (h *BufPane) openHelp(page string) error {
450452
func (h *BufPane) HelpCmd(args []string) {
451453
if len(args) < 1 {
452454
// Open the default help if the user just typed "> help"
453-
h.openHelp("help")
455+
h.openHelp("help", true, false)
454456
} else {
455-
if config.FindRuntimeFile(config.RTHelp, args[0]) != nil {
456-
err := h.openHelp(args[0])
457+
var topics []string
458+
hsplit := true
459+
forceSplit := false
460+
const errSplit = "hsplit and vsplit are not allowed at the same time"
461+
for _, arg := range args {
462+
switch arg {
463+
case "-vsplit":
464+
if forceSplit {
465+
InfoBar.Error(errSplit)
466+
return
467+
}
468+
hsplit = false
469+
forceSplit = true
470+
case "-hsplit":
471+
if forceSplit {
472+
InfoBar.Error(errSplit)
473+
return
474+
}
475+
hsplit = true
476+
forceSplit = true
477+
default:
478+
topics = append(topics, arg)
479+
}
480+
}
481+
482+
if len(topics) < 1 {
483+
// Do the same as without arg
484+
h.openHelp("help", hsplit, forceSplit)
485+
return
486+
}
487+
if len(topics) > 1 {
488+
forceSplit = true
489+
}
490+
491+
if config.FindRuntimeFile(config.RTHelp, topics[0]) != nil {
492+
err := h.openHelp(topics[0], hsplit, forceSplit)
457493
if err != nil {
458494
InfoBar.Error(err)
459495
}
460496
} else {
461-
InfoBar.Error("Sorry, no help for ", args[0])
497+
InfoBar.Error("Sorry, no help for ", topics[0])
462498
}
463499
}
464500
}

runtime/help/commands.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ quotes here but these are not necessary when entering the command in micro.
2121
This command will modify `bindings.json` and overwrite any bindings to
2222
`key` that already exist.
2323

24-
* `help ['topic']`: opens the corresponding help topic. If no topic is provided
25-
opens the default help screen. Help topics are stored as `.md` files in the
26-
`runtime/help` directory of the source tree, which is embedded in the final
27-
binary.
24+
* `help ['topic'] ['flags']`: opens the corresponding help topic.
25+
If no topic is provided opens the default help screen.
26+
Help topics are stored as `.md` files in the `runtime/help` directory of
27+
the source tree, which is embedded in the final binary.
28+
The `flags` are optional.
29+
* `-hsplit`: Opens the help topic in a horizontal split (default for initial split)
30+
* `-vsplit`: Opens the help topic in a vertical split
2831

2932
* `save ['filename']`: saves the current buffer. If the file is provided it
3033
will 'save as' the filename.

0 commit comments

Comments
 (0)