summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-11-14 13:59:33 +0000
committerMaxime Coste <frrrwww@gmail.com>2016-11-14 19:39:35 +0000
commitb3ba769220aad0a3ac2a969d43c58396b3753aa7 (patch)
treefb01b5f5e8cd5260ea23aff309bcdcf9ba017f94 /src
parentcb074793a0af099754a7fba9c2a5755bd2130d31 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/buffer.cc3
-rw-r--r--src/buffer.hh5
-rw-r--r--src/buffer_utils.cc8
-rw-r--r--src/buffer_utils.hh6
-rw-r--r--src/commands.cc10
-rw-r--r--src/input_handler.cc19
-rw-r--r--src/normal.cc7
-rw-r--r--src/window.cc3
8 files changed, 49 insertions, 12 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index a0a66fd8..fddf473e 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -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());
}
diff --git a/src/buffer.hh b/src/buffer.hh
index d95d41bc..839b3d62 100644
--- a/src/buffer.hh
+++ b/src/buffer.hh
@@ -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 = {},
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc
index d26249c9..3f0ec837 100644
--- a/src/buffer_utils.cc
+++ b/src/buffer_utils.cc
@@ -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(
diff --git a/src/buffer_utils.hh b/src/buffer_utils.hh
index 7e3f8ac3..58443062 100644
--- a/src/buffer_utils.hh
+++ b/src/buffer_utils.hh
@@ -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);
diff --git a/src/commands.cc b/src/commands.cc
index a59a4e87..9064bbe5 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -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();
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 231d97f0..7a4ecabd 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -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());
}
diff --git a/src/normal.cc b/src/normal.cc
index 8e2e0936..1b420faa 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -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())
{
diff --git a/src/window.cc b/src/window.cc
index 6752dec8..2c48d278 100644
--- a/src/window.cc
+++ b/src/window.cc
@@ -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)