From 26f0806915179c178daae99564955cc2e9f6fe1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:34:41 +0200 Subject: [PATCH 1/6] action/command: Add optional flag `-hsplit` & `-vsplit` to `help` --- internal/action/actions.go | 2 +- internal/action/command.go | 50 ++++++++++++++++++++++++++++++++------ runtime/help/commands.md | 11 ++++++--- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index cf6d954f..05ef4e1e 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1723,7 +1723,7 @@ func (h *BufPane) ToggleHelp() bool { if h.Buf.Type == buffer.BTHelp { h.Quit() } else { - h.openHelp("help") + h.openHelp("help", true, false) } return true } diff --git a/internal/action/command.go b/internal/action/command.go index 5f56fcdb..9192e1dc 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -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 { @@ -437,10 +437,12 @@ 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 @@ -450,15 +452,49 @@ func (h *BufPane) openHelp(page string) error { func (h *BufPane) HelpCmd(args []string) { if len(args) < 1 { // Open the default help if the user just typed "> help" - h.openHelp("help") + h.openHelp("help", true, false) } else { - if config.FindRuntimeFile(config.RTHelp, args[0]) != nil { - err := h.openHelp(args[0]) + var topics []string + hsplit := true + 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 + } + + if config.FindRuntimeFile(config.RTHelp, topics[0]) != nil { + err := h.openHelp(topics[0], hsplit, forceSplit) if err != nil { InfoBar.Error(err) } } else { - InfoBar.Error("Sorry, no help for ", args[0]) + InfoBar.Error("Sorry, no help for ", topics[0]) } } } diff --git a/runtime/help/commands.md b/runtime/help/commands.md index a9219901..b62a40b1 100644 --- a/runtime/help/commands.md +++ b/runtime/help/commands.md @@ -21,10 +21,13 @@ 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 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. + The `flags` are optional. + * `-hsplit`: Opens the help topic in a horizontal split (default for initial split) + * `-vsplit`: Opens the help topic in a vertical split * `save ['filename']`: saves the current buffer. If the file is provided it will 'save as' the filename. From 2c62d4b70c3621d1a459687d48ba450bb80e79ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sun, 13 Oct 2024 13:03:16 +0200 Subject: [PATCH 2/6] action/command: Allow multiple `help` pages to be opened --- internal/action/command.go | 14 ++++++++------ runtime/help/commands.md | 5 +++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/internal/action/command.go b/internal/action/command.go index 9192e1dc..3c14dea2 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -488,13 +488,15 @@ func (h *BufPane) HelpCmd(args []string) { forceSplit = true } - if config.FindRuntimeFile(config.RTHelp, topics[0]) != nil { - err := h.openHelp(topics[0], hsplit, forceSplit) - if err != nil { - InfoBar.Error(err) + 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 ", topics[0]) } } } diff --git a/runtime/help/commands.md b/runtime/help/commands.md index b62a40b1..7d71d785 100644 --- a/runtime/help/commands.md +++ b/runtime/help/commands.md @@ -21,8 +21,9 @@ 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'] ['flags']`: opens the corresponding help topic. - If no topic is provided opens the default help screen. +* `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. From acabf2b492a7edff491aca7b0e4818a6e2473355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sun, 13 Oct 2024 15:25:51 +0200 Subject: [PATCH 3/6] action/command: Align `vsplit` & `hsplit` to `tab`'s multiopen handling --- internal/action/command.go | 32 ++++++++++++++++++-------------- runtime/help/commands.md | 3 ++- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/internal/action/command.go b/internal/action/command.go index 3c14dea2..b5b9794f 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -501,7 +501,7 @@ func (h *BufPane) HelpCmd(args []string) { } } -// 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 { @@ -510,16 +510,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 { @@ -528,13 +530,15 @@ 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 diff --git a/runtime/help/commands.md b/runtime/help/commands.md index 7d71d785..c406d740 100644 --- a/runtime/help/commands.md +++ b/runtime/help/commands.md @@ -76,7 +76,8 @@ 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. From ff4c5c83f2116accb317ea86fa526cea87abf267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:53:54 +0200 Subject: [PATCH 4/6] runtime/help: Align `tab`'s documentation to `vsplit` --- internal/action/command.go | 3 ++- runtime/help/commands.md | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/action/command.go b/internal/action/command.go index b5b9794f..cd8c81a1 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -546,7 +546,8 @@ 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() diff --git a/runtime/help/commands.md b/runtime/help/commands.md index c406d740..b1cd98dd 100644 --- a/runtime/help/commands.md +++ b/runtime/help/commands.md @@ -82,7 +82,9 @@ quotes here but these are not necessary when entering the command in micro. * `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 From 47b84f75e1f35218f96dc76a2a6a428ce3091539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Tue, 15 Oct 2024 06:19:07 +0200 Subject: [PATCH 5/6] config/settings: Add option `helpsplit` for permanent `help` split type For downward compatibility the default split type for the `help` command is set to be `hsplit`. --- internal/action/actions.go | 3 ++- internal/action/command.go | 4 ++-- internal/config/settings.go | 3 +++ runtime/help/commands.md | 4 +++- runtime/help/options.md | 7 +++++++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index 05ef4e1e..7e3d452a 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -1723,7 +1723,8 @@ func (h *BufPane) ToggleHelp() bool { if h.Buf.Type == buffer.BTHelp { h.Quit() } else { - h.openHelp("help", true, false) + hsplit := config.GlobalSettings["helpsplit"] == "hsplit" + h.openHelp("help", hsplit, false) } return true } diff --git a/internal/action/command.go b/internal/action/command.go index cd8c81a1..13d9f1b2 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -450,12 +450,12 @@ func (h *BufPane) openHelp(page string, hsplit bool, forceSplit bool) error { // HelpCmd tries to open the given help page in a horizontal split 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", true, false) + h.openHelp("help", hsplit, false) } else { var topics []string - hsplit := true forceSplit := false const errSplit = "hsplit and vsplit are not allowed at the same time" for _, arg := range args { diff --git a/internal/config/settings.go b/internal/config/settings.go index b8cfcd51..910a3072 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -29,6 +29,7 @@ var optionValidators = map[string]optionValidator{ "detectlimit": validateNonNegativeValue, "encoding": validateEncoding, "fileformat": validateChoice, + "helpsplit": validateChoice, "matchbracestyle": validateChoice, "multiopen": validateChoice, "reload": validateChoice, @@ -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"}, @@ -109,6 +111,7 @@ var DefaultGlobalOnlySettings = map[string]interface{}{ "divchars": "|-", "divreverse": true, "fakecursor": false, + "helpsplit": "hsplit", "infobar": true, "keymenu": false, "mouse": true, diff --git a/runtime/help/commands.md b/runtime/help/commands.md index b1cd98dd..a20c8c39 100644 --- a/runtime/help/commands.md +++ b/runtime/help/commands.md @@ -27,9 +27,11 @@ quotes here but these are not necessary when entering the command in micro. 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 (default for initial split) + * `-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. diff --git a/runtime/help/options.md b/runtime/help/options.md index ff781834..0ea3b4ee 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -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 From 39b2b2639adec3f1e3012ae0beca7e5a8db29a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:47:42 +0200 Subject: [PATCH 6/6] action/command: Precise `HelpCmd()` documentation --- internal/action/command.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/action/command.go b/internal/action/command.go index 13d9f1b2..f5fdfffb 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -448,7 +448,10 @@ func (h *BufPane) openHelp(page string, hsplit bool, forceSplit bool) error { 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 {