From d4f155cae78126e04d50cb24e21c9288ae81caab Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 28 Dec 2012 13:51:14 +0100 Subject: [PATCH] new clients always takes last used buffer, support multiple file on command line --- src/client_manager.cc | 4 ++-- src/client_manager.hh | 3 +-- src/main.cc | 34 +++++++++++++++++----------------- src/remote.cc | 4 +--- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/client_manager.cc b/src/client_manager.cc index cf9a02a6..020a4d9e 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -8,9 +8,9 @@ namespace Kakoune { void ClientManager::create_client(std::unique_ptr&& ui, - Buffer& buffer, int event_fd, - const String& init_commands) + int event_fd, const String& init_commands) { + Buffer& buffer = **BufferManager::instance().begin(); m_clients.emplace_back(new Client{std::move(ui), get_unused_window_for_buffer(buffer)}); InputHandler* input_handler = &m_clients.back()->input_handler; diff --git a/src/client_manager.hh b/src/client_manager.hh index 2c1adf0d..1b00c50f 100644 --- a/src/client_manager.hh +++ b/src/client_manager.hh @@ -13,8 +13,7 @@ class ClientManager : public Singleton { public: void create_client(std::unique_ptr&& ui, - Buffer& buffer, int event_fd, - const String& init_cmd); + int event_fd, const String& init_cmd); bool empty() const { return m_clients.empty(); } size_t count() const { return m_clients.size(); } diff --git a/src/main.cc b/src/main.cc index eadcef1f..1e6619d7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -631,10 +631,8 @@ void register_registers() } } -void create_local_client(const String& file, const String& init_command) +void create_local_client(const String& init_command) { - Buffer* buffer = nullptr; - class LocalNCursesUI : public NCursesUI { ~LocalNCursesUI() @@ -649,20 +647,8 @@ void create_local_client(const String& file, const String& init_command) }; UserInterface* ui = new LocalNCursesUI{}; - if (not file.empty()) - { - buffer = create_buffer_from_file(file); - if (not buffer) - { - ui->print_status("new file " + file, -1); - buffer = new Buffer(file, Buffer::Flags::New | Buffer::Flags::File); - } - } - else - buffer = new Buffer("*scratch*", Buffer::Flags::None); - ClientManager::instance().create_client( - std::unique_ptr{ui}, *buffer, 0, init_command); + std::unique_ptr{ui}, 0, init_command); } RemoteClient* connect_to(const String& pid, const String& init_command) @@ -771,7 +757,21 @@ int main(int argc, char* argv[]) write_debug("error while parsing kakrc: " + error.description()); } - create_local_client(parser.positional_count() > 0 ? parser[0] : "", init_command); + if (parser.positional_count() != 0) + { + // create buffers in reverse order so that the first given buffer + // is the most recently created one. + for (int i = parser.positional_count() - 1; i >= 0; --i) + { + const String& file = parser[i]; + if (not create_buffer_from_file(file)) + new Buffer(file, Buffer::Flags::New | Buffer::Flags::File); + } + } + else + new Buffer("*scratch*", Buffer::Flags::None); + + create_local_client(init_command); while (not client_manager.empty()) event_manager.handle_next_events(); diff --git a/src/remote.cc b/src/remote.cc index 7fe9730f..0fb9f451 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -3,7 +3,6 @@ #include "display_buffer.hh" #include "debug.hh" #include "client_manager.hh" -#include "buffer_manager.hh" #include "event_manager.hh" #include @@ -370,11 +369,10 @@ void handle_remote(int socket) { String init_command = read(socket); - auto& buffer = *BufferManager::instance().begin(); RemoteUI* ui = new RemoteUI{socket}; EventManager::instance().unwatch(socket); ClientManager::instance().create_client( - std::unique_ptr{ui}, *buffer, socket, init_command); + std::unique_ptr{ui}, socket, init_command); } }