diff --git a/README.asciidoc b/README.asciidoc index 2984620a..3dc5b676 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -254,7 +254,8 @@ Commands are entered using +:+. * +source +: execute commands in * +runtime +: execute commands in , is relative to kak executable path. - * +name +: set current client name + * +nameclient +: set current client name + * +namebuf +: set current buffer name * +exec [-client ] +: execute as if pressed in normal mode. if client if specified, exec keys in the named client context. * +eval [-client ] +: execute as if entered in command line diff --git a/src/buffer.cc b/src/buffer.cc index 1d017c40..932b5532 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -72,6 +72,20 @@ String Buffer::display_name() const return m_name; } +bool Buffer::set_name(String name) +{ + Buffer* other = BufferManager::instance().get_buffer_ifp(name); + if (other == nullptr or other == this) + { + if (m_flags & Flags::File) + m_name = real_path(name); + else + m_name = std::move(name); + return true; + } + return false; +} + BufferIterator Buffer::iterator_at(const BufferCoord& line_and_column, bool avoid_eol) const { diff --git a/src/buffer.hh b/src/buffer.hh index 8518da14..b1482294 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -109,6 +109,8 @@ public: Flags flags() const { return m_flags; } Flags& flags() { return m_flags; } + bool set_name(String name); + void insert(BufferIterator pos, String content); void erase(BufferIterator begin, BufferIterator end); diff --git a/src/commands.cc b/src/commands.cc index 59434197..1aa04ea4 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -240,6 +240,14 @@ void delete_buffer(const CommandParameters& params, Context& context) manager.delete_buffer(buffer); } +void set_buffer_name(const CommandParameters& params, Context& context) +{ + ParametersParser parser(params, OptionMap{}, + ParametersParser::Flags::None, 1, 1); + if (not context.buffer().set_name(parser[0])) + throw runtime_error("unable to change buffer name to " + parser[0]); +} + template Group& get_group(Group& root, const String& group_path) { @@ -900,6 +908,7 @@ void register_commands() cm.register_commands({ "b", "buffer" }, show_buffer, buffer_completer); cm.register_commands({ "db", "delbuf" }, delete_buffer, buffer_completer); cm.register_commands({ "db!", "delbuf!" }, delete_buffer, buffer_completer); + cm.register_commands({"nb", "namebuf"}, set_buffer_name); auto get_highlighters = [](const Context& c) -> HighlighterGroup& { return c.window().highlighters(); }; auto get_filters = [](const Context& c) -> FilterGroup& { return c.window().filters(); }; @@ -943,7 +952,7 @@ void register_commands() })); cm.register_commands({"ca", "colalias"}, define_color_alias); - cm.register_commands({"name"}, set_client_name); + cm.register_commands({"nc", "nameclient"}, set_client_name); cm.register_command("cd", change_working_directory, filename_completer); }