diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2016-07-10 16:01:33 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2016-07-10 16:34:16 +0100 |
| commit | 530ecf212eedce7ae62c185873ae42033eeee925 (patch) | |
| tree | b968beadab5905f1e43ad450ce94e3d6ddd48ed3 /src/buffer.cc | |
| parent | 6bcfc7268f9a0b642cdda802b072034f587c5370 (diff) | |
Ensure buffer create/close hooks are run at appropriate times
They used to be ran before the buffer was added to the buffer list
we now run them afterwards.
Diffstat (limited to 'src/buffer.cc')
| -rw-r--r-- | src/buffer.cc | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index 089103b1..df9a7613 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -69,8 +69,6 @@ Buffer::Buffer(String name, Flags flags, StringView data, m_last_save_undo_index(0), m_fs_timestamp(fs_timestamp) { - options().register_watcher(*this); - ParsedLines parsed_lines = parse_lines(data); if (parsed_lines.lines.empty()) @@ -87,9 +85,24 @@ Buffer::Buffer(String name, Flags flags, StringView data, apply_options(options(), parsed_lines); - if (flags & Flags::File) + // now we may begin to record undo data + if (not (flags & Flags::NoUndo)) + m_flags &= ~Flags::NoUndo; +} + +void Buffer::on_registered() +{ + // Ignore debug buffer, as it can be created in many + // corner cases (including while destroying the BufferManager + // if a BufClose hooks triggers writing to it. + if (m_flags & Flags::Debug) + return; + + options().register_watcher(*this); + + if (m_flags & Flags::File) { - if (flags & Flags::New) + if (m_flags & Buffer::Flags::New) run_hook_in_own_context("BufNew", m_name); else { @@ -100,19 +113,21 @@ Buffer::Buffer(String name, Flags flags, StringView data, run_hook_in_own_context("BufCreate", m_name); - // now we may begin to record undo data - if (not (flags & Flags::NoUndo)) - m_flags &= ~Flags::NoUndo; - for (auto& option : options().flatten_options()) on_option_changed(*option); } -Buffer::~Buffer() +void Buffer::on_unregistered() { - run_hook_in_own_context("BufClose", m_name); + if (m_flags & Flags::Debug) + return; options().unregister_watcher(*this); + run_hook_in_own_context("BufClose", m_name); +} + +Buffer::~Buffer() +{ m_values.clear(); } |
