mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 14:55:38 -04:00
Merge pull request #3502 from JoeKar/feature/help-split
action/command: Allow `-vsplit` & `-hsplit` as optional argument for `help` Additionally the help, vsplit and hsplit command can now open multiple files like the tab command.
This commit is contained in:
commit
07f8cfbef1
@ -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
|
||||
}
|
||||
|
@ -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,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 {
|
||||
@ -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 {
|
||||
@ -490,13 +533,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
|
||||
@ -504,7 +549,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()
|
||||
|
@ -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,
|
||||
|
@ -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.
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user