mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-05 14:40:20 +09:00
* Add reload setting Can be set to: * auto - Automatically reload files that changed * disabled - Do not reload files * prompt - Prompt the user about reloading the file. * option: Add default value for reload option and documentation --------- Co-authored-by: Wilberto Morales <wilbertomorales777@gmail.com>
This commit is contained in:
@@ -395,20 +395,34 @@ func (h *BufPane) Name() string {
|
||||
return n
|
||||
}
|
||||
|
||||
func (h *BufPane) getReloadSetting() string {
|
||||
reloadSetting := h.Buf.Settings["reload"]
|
||||
return reloadSetting.(string)
|
||||
}
|
||||
|
||||
// HandleEvent executes the tcell event properly
|
||||
func (h *BufPane) HandleEvent(event tcell.Event) {
|
||||
if h.Buf.ExternallyModified() && !h.Buf.ReloadDisabled {
|
||||
InfoBar.YNPrompt("The file on disk has changed. Reload file? (y,n,esc)", func(yes, canceled bool) {
|
||||
if canceled {
|
||||
h.Buf.DisableReload()
|
||||
}
|
||||
if !yes || canceled {
|
||||
h.Buf.UpdateModTime()
|
||||
} else {
|
||||
h.Buf.ReOpen()
|
||||
}
|
||||
})
|
||||
reload := h.getReloadSetting()
|
||||
|
||||
if reload == "prompt" {
|
||||
InfoBar.YNPrompt("The file on disk has changed. Reload file? (y,n,esc)", func(yes, canceled bool) {
|
||||
if canceled {
|
||||
h.Buf.DisableReload()
|
||||
}
|
||||
if !yes || canceled {
|
||||
h.Buf.UpdateModTime()
|
||||
} else {
|
||||
h.Buf.ReOpen()
|
||||
}
|
||||
})
|
||||
} else if reload == "auto" {
|
||||
h.Buf.ReOpen()
|
||||
} else if reload == "disabled" {
|
||||
h.Buf.DisableReload()
|
||||
} else {
|
||||
InfoBar.Message("Invalid reload setting")
|
||||
}
|
||||
}
|
||||
|
||||
switch e := event.(type) {
|
||||
|
||||
@@ -52,6 +52,7 @@ var optionValidators = map[string]optionValidator{
|
||||
"fileformat": validateLineEnding,
|
||||
"encoding": validateEncoding,
|
||||
"multiopen": validateMultiOpen,
|
||||
"reload": validateReload,
|
||||
}
|
||||
|
||||
func ReadSettings() error {
|
||||
@@ -294,6 +295,7 @@ var defaultCommonSettings = map[string]interface{}{
|
||||
"mkparents": false,
|
||||
"permbackup": false,
|
||||
"readonly": false,
|
||||
"reload": "prompt",
|
||||
"rmtrailingws": false,
|
||||
"ruler": true,
|
||||
"relativeruler": false,
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user