Add reopen cmd and other encodings support

This commit is contained in:
Zachary Yedidia
2019-01-23 19:06:20 -05:00
parent ef3f081347
commit ad50d7aa56
11 changed files with 78 additions and 19 deletions

View File

@@ -48,6 +48,7 @@ func InitCommands() {
"togglelog": Command{(*BufPane).ToggleLogCmd, nil},
"plugin": Command{(*BufPane).PluginCmd, nil},
"reload": Command{(*BufPane).ReloadCmd, nil},
"reopen": Command{(*BufPane).ReopenCmd, nil},
"cd": Command{(*BufPane).CdCmd, buffer.FileComplete},
"pwd": Command{(*BufPane).PwdCmd, nil},
"open": Command{(*BufPane).OpenCmd, buffer.FileComplete},
@@ -234,6 +235,22 @@ func (h *BufPane) ToggleLogCmd(args []string) {
func (h *BufPane) ReloadCmd(args []string) {
}
// ReopenCmd reopens the buffer (reload from disk)
func (h *BufPane) ReopenCmd(args []string) {
if h.Buf.Modified() {
InfoBar.YNPrompt("Save file before reopen?", func(yes, canceled bool) {
if !canceled && yes {
h.Save()
h.Buf.ReOpen()
} else if !canceled {
h.Buf.ReOpen()
}
})
} else {
h.Buf.ReOpen()
}
}
func (h *BufPane) openHelp(page string) error {
if data, err := config.FindRuntimeFile(config.RTHelp, page).Data(); err != nil {
return errors.New(fmt.Sprint("Unable to load help text", page, "\n", err))