From 8d158e4ed91cf7c33836532cea1a8eff2d545a8d Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 20 Mar 2018 21:19:23 -0400 Subject: [PATCH] Write file to argument given to 'w' command, if present --- src/core/EncodedString.h | 4 ++++ src/gui/Window.cc | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/EncodedString.h b/src/core/EncodedString.h index 91b7d4d..a442d3e 100644 --- a/src/core/EncodedString.h +++ b/src/core/EncodedString.h @@ -83,6 +83,10 @@ public: { return !(*this == s); } + std::string to_string() const + { + return std::string((const char *)&(*m_data)[0], m_size); + } protected: Encoding::Type m_encoding; diff --git a/src/gui/Window.cc b/src/gui/Window.cc index 1710129..dc1f30e 100644 --- a/src/gui/Window.cc +++ b/src/gui/Window.cc @@ -552,9 +552,22 @@ void Window::handle_command(const EncodedString & command) void Window::command_write_file(const CommandParser & cp) { std::shared_ptr buffer = m_focused_buffer_pane->buffer(); - if (buffer->filename()) + std::string path; + if (cp.size() >= 2) { - buffer->write_to_file(buffer->filename()->c_str()); + path = cp[1].to_string(); + } + else + { + auto filename = buffer->filename(); + if (filename) + { + path = *filename; + } + } + if (path != "") + { + buffer->write_to_file(path.c_str()); } }