summaryrefslogtreecommitdiff
path: root/src/buffer_utils.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-02-11 13:06:19 +1100
committerMaxime Coste <mawww@kakoune.org>2018-02-11 13:06:19 +1100
commit66fe2d84daa1ec72c2eb1385b1d8da705277403e (patch)
tree5326fb976627721b564e3ee7e8126cd8dab9db19 /src/buffer_utils.cc
parent3584e00d19f542aa15a74fe411a3a7ddebd89037 (diff)
Refuse modification of ReadOnly buffers and make Debug buffer readonly
The debug buffer is a bit special as lots of events might mutate it, permitting it to be modified leads to some buggy behaviour: For example, `pipe` uses a ForwardChangeTracker to track buffer changes, but when applied on a debug buffer with the profile flag on, each shell execution will trigger an additional modification of the buffer while applying the changes, leading to an assertion failing as changes might not be happening in a forward way anymore. Trying to modify a debug buffer will now raise an error immediatly.
Diffstat (limited to 'src/buffer_utils.cc')
-rw-r--r--src/buffer_utils.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc
index 1e282695..4a6e3816 100644
--- a/src/buffer_utils.cc
+++ b/src/buffer_utils.cc
@@ -181,12 +181,17 @@ void write_to_debug_buffer(StringView str)
// where the user can put its cursor to scroll with new messages
const bool eol_back = not str.empty() and str.back() == '\n';
if (Buffer* buffer = BufferManager::instance().get_buffer_ifp(debug_buffer_name))
+ {
+ buffer->flags() &= ~Buffer::Flags::ReadOnly;
+ auto restore = on_scope_end([buffer] { buffer->flags() |= Buffer::Flags::ReadOnly; });
+
buffer->insert(buffer->back_coord(), eol_back ? str : str + "\n");
+ }
else
{
String line = str + (eol_back ? "\n" : "\n\n");
BufferManager::instance().create_buffer(
- debug_buffer_name.str(), Buffer::Flags::NoUndo | Buffer::Flags::Debug,
+ debug_buffer_name.str(), Buffer::Flags::NoUndo | Buffer::Flags::Debug | Buffer::Flags::ReadOnly,
line, InvalidTime);
}
}