From 9429b662ca916a36fa386c8968a833ace9744f1c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 25 Mar 2013 19:58:23 +0100 Subject: [PATCH] move absolute path logic to Buffer class --- src/buffer.cc | 11 +++++++++++ src/buffer.hh | 1 + src/buffer_manager.cc | 9 ++++++--- src/client_manager.cc | 6 ++---- src/commands.cc | 3 +-- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index eefc739a..c8ad73c0 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -5,6 +5,7 @@ #include "assert.hh" #include "utils.hh" #include "context.hh" +#include "file.hh" #include @@ -21,6 +22,9 @@ Buffer::Buffer(String name, Flags flags, std::vector lines) { BufferManager::instance().register_buffer(*this); + if (flags & Flags::File) + m_name = real_path(m_name); + if (lines.empty()) lines.emplace_back("\n"); @@ -58,6 +62,13 @@ Buffer::~Buffer() assert(m_change_listeners.empty()); } +String Buffer::display_name() const +{ + if (m_flags & Flags::File) + return compact_path(m_name); + return m_name; +} + BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column, bool avoid_eol) const { diff --git a/src/buffer.hh b/src/buffer.hh index f29ca77f..f3c80afc 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -153,6 +153,7 @@ public: BufferIterator iterator_at_line_end(LineCount line) const; const String& name() const { return m_name; } + String display_name() const; // returns true if the buffer is in a different state than // the last time it was saved diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index 0fae2a17..7e62acfb 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -5,6 +5,7 @@ #include "exception.hh" #include "string.hh" #include "client_manager.hh" +#include "file.hh" namespace Kakoune { @@ -49,7 +50,9 @@ Buffer* BufferManager::get_buffer_ifp(const String& name) { for (auto& buf : m_buffers) { - if (buf->name() == name) + if (buf->name() == name or + (buf->flags() & Buffer::Flags::File and + real_path(buf->name()) == real_path(parse_filename(name)))) return buf.get(); } return nullptr; @@ -80,7 +83,7 @@ CandidateList BufferManager::complete_buffername(const String& prefix, CandidateList result; for (auto& buffer : m_buffers) { - const String& name = buffer->name(); + String name = buffer->display_name(); if (name.substr(0, real_prefix.length()) == real_prefix) result.push_back(escape(name)); } @@ -92,7 +95,7 @@ CandidateList BufferManager::complete_buffername(const String& prefix, Regex ex(real_prefix.begin(), real_prefix.end()); for (auto& buffer : m_buffers) { - const String& name = buffer->name(); + String name = buffer->display_name(); if (boost::regex_search(name.begin(), name.end(), ex)) result.push_back(escape(name)); } diff --git a/src/client_manager.cc b/src/client_manager.cc index 9e8e9d64..a7919cf1 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -195,11 +195,9 @@ static String generate_status_line(const Context& context) { BufferCoord cursor = context.editor().main_selection().last().coord(); std::ostringstream oss; - String name = context.buffer().name(); - if (context.buffer().flags() & Buffer::Flags::File) - name = compact_path(name); - oss << name << " " << (int)cursor.line+1 << "," << (int)cursor.column+1; + oss << context.buffer().display_name() + << " " << (int)cursor.line+1 << "," << (int)cursor.column+1; if (context.buffer().is_modified()) oss << " [+]"; if (context.input_handler().is_recording()) diff --git a/src/commands.cc b/src/commands.cc index 1a95ec15..7731ae11 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -97,8 +97,7 @@ void edit(const CommandParameters& params, Context& context) if (param_count == 0 or param_count > 3) throw wrong_argument_count(); - const bool file = not parser.has_option("scratch") and not parser.has_option("fifo"); - String name = file ? real_path(parse_filename(parser[0])) : parser[0]; + const String name = parser[0]; Buffer* buffer = nullptr; if (not force_reload)