#include "buffer.hh" #include "assert.hh" #include "buffer_manager.hh" #include "buffer_utils.hh" #include "client.hh" #include "context.hh" #include "diff.hh" #include "file.hh" #include "flags.hh" #include "option_types.hh" #include "ranges.hh" #include "shared_string.hh" #include "unit_tests.hh" #include "utils.hh" #include "window.hh" #include namespace Kakoune { Buffer::HistoryNode::HistoryNode(HistoryId parent) : parent{parent}, committed{Clock::now()} {} Buffer::Buffer(String name, Flags flags, BufferLines lines, ByteOrderMark bom, EolFormat eolformat, FsStatus fs_status) : Scope{GlobalScope::instance()}, m_name{(flags & Flags::File) ? real_path(parse_filename(name)) : std::move(name)}, m_display_name{(flags & Flags::File) ? compact_path(m_name) : m_name}, m_flags{flags | Flags::NoUndo}, m_history{{HistoryId::Invalid}}, m_history_id{HistoryId::First}, m_last_save_history_id{HistoryId::First}, m_fs_status{fs_status} { #ifdef KAK_DEBUG for (auto& line : lines) kak_assert(not (line->length == 0) and line->data()[line->length-1] == '\n'); #endif static_cast(m_lines) = std::move(lines); m_changes.push_back({ Change::Insert, {0,0}, line_count() }); options().get_local_option("eolformat").set(eolformat); options().get_local_option("BOM").set(bom); // 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 & Buffer::Flags::NoHooks) { on_option_changed(options()["readonly"]); return; } run_hook_in_own_context(Hook::BufCreate, m_name); if (m_flags & Flags::File) { if (m_flags & Buffer::Flags::New) run_hook_in_own_context(Hook::BufNewFile, m_name); else { kak_assert(m_fs_status.timestamp != InvalidTime); run_hook_in_own_context(Hook::BufOpenFile, m_name); } } for (auto& option : options().flatten_options() | transform(&std::unique_ptr