summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2025-05-23 10:14:09 +1000
committerMaxime Coste <mawww@kakoune.org>2025-05-23 10:14:09 +1000
commitd5fc4454551d4d9ee462d1291057a016fbfe3882 (patch)
tree56d7e0a943490f36298e0cd0137b8527283d788b
parentb0f541aae65c06f828245e6f90a40967f8e98322 (diff)
Disable BufSetOption hook during buffer registration
The hook is manually triggred at the end of registration, by disabling it we avoid the hook being potentially called multiple times due to interaction with other hooks. Fixes #5324
-rw-r--r--src/buffer.cc6
-rw-r--r--src/buffer.hh1
-rw-r--r--test/regression/5324-BufSetOption-triggers-twice/cmd1
-rw-r--r--test/regression/5324-BufSetOption-triggers-twice/in1
-rw-r--r--test/regression/5324-BufSetOption-triggers-twice/out1
-rw-r--r--test/regression/5324-BufSetOption-triggers-twice/rc4
6 files changed, 14 insertions, 0 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index f0205c54..9a735aaf 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -70,6 +70,8 @@ void Buffer::on_registered()
return;
}
+ m_flags |= Flags::NoBufSetOption;
+
run_hook_in_own_context(Hook::BufCreate, m_name);
if (m_flags & Flags::File)
@@ -82,6 +84,7 @@ void Buffer::on_registered()
run_hook_in_own_context(Hook::BufOpenFile, m_name);
}
}
+ m_flags &= ~Flags::NoBufSetOption;
for (auto& option : options().flatten_options()
| transform(&std::unique_ptr<Option>::get)
@@ -637,6 +640,9 @@ const FsStatus& Buffer::fs_status() const
void Buffer::on_option_changed(const Option& option)
{
+ if (m_flags & Flags::NoBufSetOption)
+ return;
+
if (option.name() == "readonly")
{
if (option.get<bool>())
diff --git a/src/buffer.hh b/src/buffer.hh
index cd895c17..3a885ec8 100644
--- a/src/buffer.hh
+++ b/src/buffer.hh
@@ -120,6 +120,7 @@ public:
NoHooks = 1 << 4,
Debug = 1 << 5,
ReadOnly = 1 << 6,
+ NoBufSetOption = 1 << 7,
};
friend constexpr bool with_bit_ops(Meta::Type<Flags>) { return true; }
friend class BufferIterator;
diff --git a/test/regression/5324-BufSetOption-triggers-twice/cmd b/test/regression/5324-BufSetOption-triggers-twice/cmd
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/test/regression/5324-BufSetOption-triggers-twice/cmd
@@ -0,0 +1 @@
+
diff --git a/test/regression/5324-BufSetOption-triggers-twice/in b/test/regression/5324-BufSetOption-triggers-twice/in
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/test/regression/5324-BufSetOption-triggers-twice/in
@@ -0,0 +1 @@
+
diff --git a/test/regression/5324-BufSetOption-triggers-twice/out b/test/regression/5324-BufSetOption-triggers-twice/out
new file mode 100644
index 00000000..00463676
--- /dev/null
+++ b/test/regression/5324-BufSetOption-triggers-twice/out
@@ -0,0 +1 @@
+hook-ran
diff --git a/test/regression/5324-BufSetOption-triggers-twice/rc b/test/regression/5324-BufSetOption-triggers-twice/rc
new file mode 100644
index 00000000..debaad8a
--- /dev/null
+++ b/test/regression/5324-BufSetOption-triggers-twice/rc
@@ -0,0 +1,4 @@
+hook global BufCreate .*/foo %{ set buffer filetype foo }
+hook global BufSetOption filetype=foo %{ exec -buffer out ihook-ran<esc> }
+edit foo
+delete-buffer foo