Add exception reporting in filter mode
This commit is contained in:
parent
8d4531d419
commit
5c3f01fea2
40
src/main.cc
40
src/main.cc
|
@ -397,32 +397,46 @@ int run_filter(StringView keystr, memoryview<StringView> files)
|
||||||
register_env_vars();
|
register_env_vars();
|
||||||
register_registers();
|
register_registers();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
auto keys = parse_keys(keystr);
|
auto keys = parse_keys(keystr);
|
||||||
|
|
||||||
|
auto apply_keys_to_buffer = [&](Buffer& buffer)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
InputHandler input_handler{{ buffer, Selection{} }};
|
||||||
|
|
||||||
|
for (auto& key : keys)
|
||||||
|
input_handler.handle_key(key);
|
||||||
|
}
|
||||||
|
catch (Kakoune::runtime_error& err)
|
||||||
|
{
|
||||||
|
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);
|
||||||
InputHandler input_handler{{ *buffer, Selection{} }};
|
apply_keys_to_buffer(*buffer);
|
||||||
|
|
||||||
for (auto& key : keys)
|
|
||||||
input_handler.handle_key(key);
|
|
||||||
|
|
||||||
write_buffer_to_file(*buffer, file + ".kak-out");
|
write_buffer_to_file(*buffer, file + ".kak-out");
|
||||||
|
|
||||||
buffer_manager.delete_buffer(*buffer);
|
buffer_manager.delete_buffer(*buffer);
|
||||||
}
|
}
|
||||||
if (not isatty(0))
|
if (not isatty(0))
|
||||||
{
|
{
|
||||||
Buffer* buffer = create_buffer_from_data(read_fd(0), "*stdin*", Buffer::Flags::None);
|
Buffer* buffer = create_buffer_from_data(read_fd(0), "*stdin*",
|
||||||
InputHandler input_handler{{ *buffer, Selection{} }};
|
Buffer::Flags::None);
|
||||||
|
apply_keys_to_buffer(*buffer);
|
||||||
for (auto& key : keys)
|
|
||||||
input_handler.handle_key(key);
|
|
||||||
|
|
||||||
write_buffer_to_fd(*buffer, 1);
|
write_buffer_to_fd(*buffer, 1);
|
||||||
|
|
||||||
buffer_manager.delete_buffer(*buffer);
|
buffer_manager.delete_buffer(*buffer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Kakoune::runtime_error& err)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "error: %s\n", err.what());
|
||||||
|
}
|
||||||
|
|
||||||
buffer_manager.clear_buffer_trash();
|
buffer_manager.clear_buffer_trash();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user