Add SaveAs action and command
Fixes #340 You can bind the action `SaveAs` and if you provide an argument to the `save` command it will save as. For example `> save test.txt`.
This commit is contained in:
parent
1739f0631a
commit
301e86a46e
5 changed files with 26 additions and 5 deletions
|
@ -754,6 +754,21 @@ func (v *View) Save(usePlugin bool) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SaveAs saves the buffer to disk with the given name
|
||||||
|
func (v *View) SaveAs(usePlugin bool) bool {
|
||||||
|
filename, canceled := messenger.Prompt("Filename: ", "Save", NoCompletion)
|
||||||
|
if !canceled {
|
||||||
|
// the filename might or might not be quoted, so unquote first then join the strings.
|
||||||
|
filename = strings.Join(SplitCommandArgs(filename), " ")
|
||||||
|
v.Buf.Path = filename
|
||||||
|
v.Buf.Name = filename
|
||||||
|
|
||||||
|
v.Save(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Find opens a prompt and searches forward for the input
|
// Find opens a prompt and searches forward for the input
|
||||||
func (v *View) Find(usePlugin bool) bool {
|
func (v *View) Find(usePlugin bool) bool {
|
||||||
if usePlugin && !PreActionCall("Find", v) {
|
if usePlugin && !PreActionCall("Find", v) {
|
||||||
|
|
|
@ -237,8 +237,12 @@ func Quit(args []string) {
|
||||||
|
|
||||||
// Save saves the buffer in the main view
|
// Save saves the buffer in the main view
|
||||||
func Save(args []string) {
|
func Save(args []string) {
|
||||||
|
if len(args) == 0 {
|
||||||
// Save the main view
|
// Save the main view
|
||||||
CurView().Save(true)
|
CurView().Save(true)
|
||||||
|
} else {
|
||||||
|
CurView().Buf.SaveAs(args[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace runs search and replace
|
// Replace runs search and replace
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -5,7 +5,8 @@ Here are the possible commands that you can use.
|
||||||
|
|
||||||
* `quit`: Quits micro.
|
* `quit`: Quits micro.
|
||||||
|
|
||||||
* `save`: Saves the current buffer.
|
* `save filename?`: Saves the current buffer. If the filename is provided it will
|
||||||
|
'save as' the filename.
|
||||||
|
|
||||||
* `replace "search" "value" flags`: This will replace `search` with `value`.
|
* `replace "search" "value" flags`: This will replace `search` with `value`.
|
||||||
The `flags` are optional.
|
The `flags` are optional.
|
||||||
|
|
|
@ -143,6 +143,7 @@ Delete
|
||||||
Center
|
Center
|
||||||
InsertTab
|
InsertTab
|
||||||
Save
|
Save
|
||||||
|
SaveAs
|
||||||
Find
|
Find
|
||||||
FindNext
|
FindNext
|
||||||
FindPrevious
|
FindPrevious
|
||||||
|
|
Loading…
Reference in a new issue