Add -multimode to open multiple files into split. (#2689)

Adds config option `multimode`, which takes values `tab`, `vsplit`,
or `hsplit` (corresponding to the file-opening commands). I mean to
use it with a command line like

    micro -multimode vsplit foo.h foo.c

to open files in a side-by-side split, but if one really wanted to
one could set it in the config file to change the default behavior of
opening multiple files in tabs.
This commit is contained in:
Andrew Geng
2023-01-23 14:13:42 -05:00
committed by GitHub
parent 43b512fd77
commit 432fc7ed58
3 changed files with 40 additions and 1 deletions

View File

@@ -148,7 +148,19 @@ func (t *TabList) Display() {
var Tabs *TabList
func InitTabs(bufs []*buffer.Buffer) {
Tabs = NewTabList(bufs)
multiMode := config.GetGlobalOption("multimode").(string)
if multiMode == "tab" {
Tabs = NewTabList(bufs)
} else {
Tabs = NewTabList(bufs[:1])
for _, b := range bufs[1:] {
if multiMode == "vsplit" {
MainTab().CurPane().VSplitBuf(b)
} else { // default hsplit
MainTab().CurPane().HSplitBuf(b)
}
}
}
}
func MainTab() *Tab {

View File

@@ -51,6 +51,7 @@ var optionValidators = map[string]optionValidator{
"colorcolumn": validateNonNegativeValue,
"fileformat": validateLineEnding,
"encoding": validateEncoding,
"multimode": validateMultiMode,
}
func ReadSettings() error {
@@ -333,6 +334,7 @@ var DefaultGlobalOnlySettings = map[string]interface{}{
"infobar": true,
"keymenu": false,
"mouse": true,
"multimode": "tab",
"parsecursor": false,
"paste": false,
"pluginchannels": []string{"https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"},
@@ -491,3 +493,19 @@ func validateEncoding(option string, value interface{}) error {
_, err := htmlindex.Get(value.(string))
return err
}
func validateMultiMode(option string, value interface{}) error {
val, ok := value.(string)
if !ok {
return errors.New("Expected string type for multimode")
}
switch val {
case "tab", "hsplit", "vsplit":
default:
return errors.New(option + " must be 'tab', 'hsplit', or 'vsplit'")
}
return nil
}