1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-18 08:51:46 +03:00

change filter mode to make backup of files to .kak-bak and edit in place

Add a -q option to filter mode to be quiet about errors while applying
keys.
This commit is contained in:
Maxime Coste 2014-11-11 23:40:07 +00:00
parent f6e9018bf0
commit fab9c92006

View File

@ -421,7 +421,7 @@ int run_server(StringView session, StringView init_command,
return 0; return 0;
} }
int run_filter(StringView keystr, memoryview<StringView> files) int run_filter(StringView keystr, memoryview<StringView> files, bool quiet)
{ {
StringRegistry string_registry; StringRegistry string_registry;
GlobalScope global_scope; GlobalScope global_scope;
@ -448,16 +448,18 @@ int run_filter(StringView keystr, memoryview<StringView> files)
} }
catch (Kakoune::runtime_error& err) catch (Kakoune::runtime_error& err)
{ {
fprintf(stderr, "error while applying keys to buffer '%s': %s\n", if (not quiet)
buffer.display_name().c_str(), err.what()); fprintf(stderr, "error while applying keys to buffer '%s': %s\n",
buffer.display_name().c_str(), err.what());
} }
}; };
for (auto& file : files) for (auto& file : files)
{ {
Buffer* buffer = create_buffer_from_file(file); Buffer* buffer = create_buffer_from_file(file);
write_buffer_to_file(*buffer, file + ".kak-bak");
apply_keys_to_buffer(*buffer); apply_keys_to_buffer(*buffer);
write_buffer_to_file(*buffer, file + ".kak-out"); write_buffer_to_file(*buffer, file);
buffer_manager.delete_buffer(*buffer); buffer_manager.delete_buffer(*buffer);
} }
if (not isatty(0)) if (not isatty(0))
@ -523,7 +525,8 @@ int main(int argc, char* argv[])
{ "s", { true, "set session name" } }, { "s", { true, "set session name" } },
{ "d", { false, "run as a headless session (requires -s)" } }, { "d", { false, "run as a headless session (requires -s)" } },
{ "p", { true, "just send stdin as commands to the given session" } }, { "p", { true, "just send stdin as commands to the given session" } },
{ "f", { true, "act as a filter, executing given keys on given files" } } } { "f", { true, "act as a filter, executing given keys on given files" } },
{ "q", { false, "in filter mode, be quiet about errors applying keys" } } }
}; };
try try
{ {
@ -547,7 +550,8 @@ int main(int argc, char* argv[])
for (size_t i = 0; i < parser.positional_count(); ++i) for (size_t i = 0; i < parser.positional_count(); ++i)
files.emplace_back(parser[i]); files.emplace_back(parser[i]);
return run_filter(parser.option_value("f"), files); return run_filter(parser.option_value("f"), files,
parser.has_option("q"));
} }
String init_command; String init_command;