1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-29 14:44:56 +03:00

Propagate the hooks disabled state through prompt, menu, and command execution

Maintain it as well during buffer creation even if the hooks are not executed
in client context.

Fixes #818
This commit is contained in:
Maxime Coste 2016-11-14 13:59:33 +00:00
parent cb074793a0
commit b3ba769220
8 changed files with 49 additions and 12 deletions

View File

@ -710,6 +710,9 @@ void Buffer::on_option_changed(const Option& option)
void Buffer::run_hook_in_own_context(StringView hook_name, StringView param)
{
if (m_flags & Buffer::Flags::NoHooks)
return;
InputHandler hook_handler({ *this, Selection{} }, Context::Flags::Transient);
hooks().run_hook(hook_name, param, hook_handler.context());
}

View File

@ -109,8 +109,9 @@ public:
New = 1 << 1,
Fifo = 1 << 2,
NoUndo = 1 << 3,
Debug = 1 << 4,
ReadOnly = 1 << 5,
NoHooks = 1 << 4,
Debug = 1 << 5,
ReadOnly = 1 << 6,
};
Buffer(String name, Flags flags, StringView data = {},

View File

@ -57,20 +57,20 @@ ByteCount get_byte_to_column(const Buffer& buffer, ColumnCount tabstop, DisplayC
return (int)(it - line.begin());
}
Buffer* open_file_buffer(StringView filename)
Buffer* open_file_buffer(StringView filename, Buffer::Flags flags)
{
MappedFile file_data{filename};
return BufferManager::instance().create_buffer(
filename.str(), Buffer::Flags::File, file_data, file_data.st.st_mtim);
filename.str(), Buffer::Flags::File | flags, file_data, file_data.st.st_mtim);
}
Buffer* open_or_create_file_buffer(StringView filename)
Buffer* open_or_create_file_buffer(StringView filename, Buffer::Flags flags)
{
auto& buffer_manager = BufferManager::instance();
if (file_exists(filename))
{
MappedFile file_data{filename};
return buffer_manager.create_buffer(filename.str(), Buffer::Flags::File,
return buffer_manager.create_buffer(filename.str(), Buffer::Flags::File | flags,
file_data, file_data.st.st_mtim);
}
return buffer_manager.create_buffer(

View File

@ -76,8 +76,10 @@ ByteCount get_byte_to_column(const Buffer& buffer, ColumnCount tabstop,
DisplayCoord coord);
Buffer* create_fifo_buffer(String name, int fd, bool scroll = false);
Buffer* open_file_buffer(StringView filename);
Buffer* open_or_create_file_buffer(StringView filename);
Buffer* open_file_buffer(StringView filename,
Buffer::Flags flags = Buffer::Flags::None);
Buffer* open_or_create_file_buffer(StringView filename,
Buffer::Flags flags = Buffer::Flags::None);
void reload_file_buffer(Buffer& buffer);
void write_to_debug_buffer(StringView str);

View File

@ -222,6 +222,8 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&)
auto& buffer_manager = BufferManager::instance();
Buffer* buffer = buffer_manager.get_buffer_ifp(name);
const bool no_hooks = context.hooks_disabled();
const auto flags = no_hooks ? Buffer::Flags::NoHooks : Buffer::Flags::None;
if (force_reload and buffer and buffer->flags() & Buffer::Flags::File)
reload_file_buffer(*buffer);
@ -236,18 +238,20 @@ void edit(const ParametersParser& parser, Context& context, const ShellContext&)
}
if (not buffer)
buffer = buffer_manager.create_buffer(name, Buffer::Flags::None);
buffer = buffer_manager.create_buffer(name, flags);
}
else if (auto fifo = parser.get_switch("fifo"))
buffer = open_fifo(name, *fifo, (bool)parser.get_switch("scroll"));
else if (not buffer)
{
buffer = parser.get_switch("existing") ? open_file_buffer(name)
: open_or_create_file_buffer(name);
buffer = parser.get_switch("existing") ? open_file_buffer(name, flags)
: open_or_create_file_buffer(name, flags);
if (buffer->flags() & Buffer::Flags::New)
context.print_status({ format("new file '{}'", name),
get_face("StatusLine") });
}
buffer->flags() &= ~Buffer::Flags::NoHooks;
}
const size_t param_count = parser.positional_count();

View File

@ -528,6 +528,10 @@ public:
if (context().has_client())
context().client().menu_hide();
context().print_status(DisplayLine{});
// Maintain hooks disabled in callback if they were before pop_mode
ScopedSetBool disable_hooks(context().hooks_disabled(),
context().hooks_disabled());
pop_mode();
int selected = m_selected - m_choices.begin();
m_callback(selected, MenuEvent::Validate, context());
@ -546,6 +550,10 @@ public:
{
if (context().has_client())
context().client().menu_hide();
// Maintain hooks disabled in callback if they were before pop_mode
ScopedSetBool disable_hooks(context().hooks_disabled(),
context().hooks_disabled());
pop_mode();
int selected = m_selected - m_choices.begin();
m_callback(selected, MenuEvent::Abort, context());
@ -680,6 +688,10 @@ public:
context().print_status(DisplayLine{});
if (context().has_client())
context().client().menu_hide();
// Maintain hooks disabled in callback if they were before pop_mode
ScopedSetBool disable_hooks(context().hooks_disabled(),
context().hooks_disabled());
pop_mode();
// call callback after pop_mode so that callback
// may change the mode
@ -693,6 +705,10 @@ public:
context().print_status(DisplayLine{});
if (context().has_client())
context().client().menu_hide();
// Maintain hooks disabled in callback if they were before pop_mode
ScopedSetBool disable_hooks(context().hooks_disabled(),
context().hooks_disabled());
pop_mode();
m_callback(line, PromptEvent::Abort, context());
return;
@ -935,6 +951,9 @@ public:
void on_key(Key key) override
{
// maintain hooks disabled in the callback if they were before pop_mode
ScopedSetBool disable_hooks(context().hooks_disabled(),
context().hooks_disabled());
pop_mode();
m_callback(key, context());
}

View File

@ -201,7 +201,12 @@ void goto_commands(Context& context, NormalParams params)
Buffer* buffer = BufferManager::instance().get_buffer_ifp(path);
if (not buffer)
buffer = open_file_buffer(path);
{
buffer = open_file_buffer(path, context.hooks_disabled() ?
Buffer::Flags::NoHooks
: Buffer::Flags::None);
buffer->flags() &= ~Buffer::Flags::NoHooks;
}
if (buffer != &context.buffer())
{

View File

@ -369,6 +369,9 @@ void Window::on_option_changed(const Option& option)
void Window::run_hook_in_own_context(StringView hook_name, StringView param)
{
if (m_buffer->flags() & Buffer::Flags::NoHooks)
return;
InputHandler hook_handler({ *m_buffer, Selection{} }, Context::Flags::Transient);
hook_handler.context().set_window(*this);
if (m_client)