mirror of
https://github.com/zyedidia/micro.git
synced 2024-10-06 00:22:12 +03:00
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
@ -754,6 +754,21 @@ func (v *View) Save(usePlugin bool) bool {
|
||||
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
|
||||
func (v *View) Find(usePlugin bool) bool {
|
||||
if usePlugin && !PreActionCall("Find", v) {
|
||||
|
@ -237,8 +237,12 @@ func Quit(args []string) {
|
||||
|
||||
// Save saves the buffer in the main view
|
||||
func Save(args []string) {
|
||||
// Save the main view
|
||||
CurView().Save(true)
|
||||
if len(args) == 0 {
|
||||
// Save the main view
|
||||
CurView().Save(true)
|
||||
} else {
|
||||
CurView().Buf.SaveAs(args[0])
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
* `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`.
|
||||
The `flags` are optional.
|
||||
|
@ -143,6 +143,7 @@ Delete
|
||||
Center
|
||||
InsertTab
|
||||
Save
|
||||
SaveAs
|
||||
Find
|
||||
FindNext
|
||||
FindPrevious
|
||||
|
Loading…
Reference in New Issue
Block a user