summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-12-07 15:39:54 +1100
committerMaxime Coste <mawww@kakoune.org>2019-12-07 15:40:57 +1100
commit15df0fc78133059b28545bf0508fbd20c6b02c92 (patch)
tree4e04de8fc552c0203993cdc4fa94e3d5648d0eb6 /src
parent42094209fdb80cad3bf2bc0add5276f15b672d96 (diff)
Add -scratch and -file switches to the rename-buffer command
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/commands.cc b/src/commands.cc
index b3277ebe..2d5b2d81 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -823,13 +823,28 @@ const CommandDesc rename_buffer_cmd = {
"rename-buffer",
nullptr,
"rename-buffer <name>: change current buffer name",
- single_param,
+ ParameterDesc{
+ {
+ { "scratch", { false, "convert a file buffer to a scratch buffer" } },
+ { "file", { false, "convert a scratch buffer to a file buffer" } }
+ },
+ ParameterDesc::Flags::None, 1, 1
+ },
CommandFlags::None,
CommandHelper{},
filename_completer<false>,
[](const ParametersParser& parser, Context& context, const ShellContext&)
{
- if (not context.buffer().set_name(parser[0]))
+ if (parser.get_switch("scratch") and parser.get_switch("file"))
+ throw runtime_error("scratch and file are incompatible switches");
+
+ auto& buffer = context.buffer();
+ if (parser.get_switch("scratch"))
+ buffer.flags() &= ~(Buffer::Flags::File | Buffer::Flags::New);
+ if (parser.get_switch("file"))
+ buffer.flags() |= Buffer::Flags::File;
+
+ if (not buffer.set_name(parser[0]))
throw runtime_error(format("unable to change buffer name to '{}': a buffer with this name already exists", parser[0]));
}
};