move absolute path logic to Buffer class

This commit is contained in:
Maxime Coste 2013-03-25 19:58:23 +01:00
parent 58caeaa8a8
commit 9429b662ca
5 changed files with 21 additions and 9 deletions

View File

@ -5,6 +5,7 @@
#include "assert.hh"
#include "utils.hh"
#include "context.hh"
#include "file.hh"
#include <algorithm>
@ -21,6 +22,9 @@ Buffer::Buffer(String name, Flags flags, std::vector<String> 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
{

View File

@ -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

View File

@ -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));
}

View File

@ -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())

View File

@ -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)