Skip to content

Commit

Permalink
option: Add default value for reload option and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKar committed Oct 16, 2023
1 parent 1bc2c93 commit 531c1d7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
9 changes: 2 additions & 7 deletions internal/action/bufpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,6 @@ func (h *BufPane) Name() string {

func (h *BufPane) getReloadSetting() string {
reloadSetting := h.Buf.Settings["reload"]

if reloadSetting == nil {
return "prompt"
}

return reloadSetting.(string)
}

Expand All @@ -421,9 +416,9 @@ func (h *BufPane) HandleEvent(event tcell.Event) {
h.Buf.ReOpen()
}
})
} else if (reload == "auto") {
} else if reload == "auto" {
h.Buf.ReOpen()
} else if (reload == "disabled") {
} else if reload == "disabled" {
h.Buf.DisableReload()
} else {
InfoBar.Message("Invalid reload setting")
Expand Down
18 changes: 18 additions & 0 deletions internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var optionValidators = map[string]optionValidator{
"fileformat": validateLineEnding,
"encoding": validateEncoding,
"multiopen": validateMultiOpen,
"reload": validateReload,
}

func ReadSettings() error {
Expand Down Expand Up @@ -294,6 +295,7 @@ var defaultCommonSettings = map[string]interface{}{
"mkparents": false,
"permbackup": false,
"readonly": false,
"reload": "prompt",
"rmtrailingws": false,
"ruler": true,
"relativeruler": false,
Expand Down Expand Up @@ -526,3 +528,19 @@ func validateMultiOpen(option string, value interface{}) error {

return nil
}

func validateReload(option string, value interface{}) error {
val, ok := value.(string)

if !ok {
return errors.New("Expected string type for reload")
}

switch val {
case "prompt", "auto", "disabled":
default:
return errors.New(option + " must be 'prompt', 'auto' or 'disabled'")
}

return nil
}
5 changes: 5 additions & 0 deletions runtime/help/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ Here are the available options:

default value: `false`

* `reload`: controls the reload behavior of the current buffer in case the file
has changed. The available options are `prompt`, `auto` & `disabled`.

default value: `prompt`

* `rmtrailingws`: micro will automatically trim trailing whitespaces at ends of
lines. Note: This setting overrides `keepautoindent`

Expand Down

0 comments on commit 531c1d7

Please sign in to comment.