diff --git a/src/commands.cc b/src/commands.cc index a7d56c07..da755cf6 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -35,7 +35,7 @@ namespace Kakoune namespace { -Buffer* open_fifo(const String& name , const String& filename, bool scroll) +Buffer* open_fifo(StringView name, StringView filename, bool scroll) { int fd = open(parse_filename(filename).c_str(), O_RDONLY); fcntl(fd, F_SETFD, FD_CLOEXEC); @@ -44,7 +44,7 @@ Buffer* open_fifo(const String& name , const String& filename, bool scroll) BufferManager::instance().delete_buffer_if_exists(name); - return create_fifo_buffer(std::move(name), fd, scroll); + return create_fifo_buffer(name, fd, scroll); } template @@ -1163,7 +1163,7 @@ const CommandDesc prompt_cmd = { context.input_handler().prompt( params[0], std::move(initstr), get_face("Prompt"), Completer{}, - [=](const String& str, PromptEvent event, Context& context) + [=](StringView str, PromptEvent event, Context& context) { if (event != PromptEvent::Validate) return; diff --git a/src/input_handler.cc b/src/input_handler.cc index badac088..fde0aa51 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -474,7 +474,7 @@ void history_push(std::vector& history, StringView entry) class Prompt : public InputMode { public: - Prompt(InputHandler& input_handler, const String& prompt, + Prompt(InputHandler& input_handler, StringView prompt, String initstr, Face face, Completer completer, PromptCallback callback) : InputMode(input_handler), m_prompt(prompt), m_prompt_face(face), @@ -1058,7 +1058,7 @@ void InputHandler::repeat_last_insert() kak_assert(dynamic_cast(m_mode.get()) != nullptr); } -void InputHandler::prompt(const String& prompt, String initstr, +void InputHandler::prompt(StringView prompt, String initstr, Face prompt_face, Completer completer, PromptCallback callback) { diff --git a/src/input_handler.hh b/src/input_handler.hh index 7911f3c6..8039d6cc 100644 --- a/src/input_handler.hh +++ b/src/input_handler.hh @@ -27,7 +27,7 @@ enum class PromptEvent Abort, Validate }; -using PromptCallback = std::function; +using PromptCallback = std::function; using KeyCallback = std::function; class InputMode; @@ -50,7 +50,7 @@ public: // abort or validation with corresponding PromptEvent value // returns to normal mode after validation if callback does // not change the mode itself - void prompt(const String& prompt, String initstr, + void prompt(StringView prompt, String initstr, Face prompt_face, Completer completer, PromptCallback callback); void set_prompt_face(Face prompt_face); diff --git a/src/normal.cc b/src/normal.cc index 89a92df3..8a3b0f6a 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -355,7 +355,7 @@ void command(Context& context, int) context.input_handler().prompt( ":", "", get_face("Prompt"), std::bind(&CommandManager::complete, &CommandManager::instance(), _1, _2, _3, _4), - [](const String& cmdline, PromptEvent event, Context& context) { + [](StringView cmdline, PromptEvent event, Context& context) { if (context.has_ui()) { context.ui().info_hide(); @@ -379,7 +379,7 @@ void pipe(Context& context, int) { const char* prompt = mode == InsertMode::Replace ? "pipe:" : "pipe (ins):"; context.input_handler().prompt(prompt, "", get_face("Prompt"), shell_complete, - [](const String& cmdline, PromptEvent event, Context& context) + [](StringView cmdline, PromptEvent event, Context& context) { if (event != PromptEvent::Validate) return; @@ -389,7 +389,7 @@ void pipe(Context& context, int) real_cmd = context.main_sel_register_value("|"); else { - RegisterManager::instance()['|'] = cmdline; + RegisterManager::instance()['|'] = String{cmdline}; real_cmd = cmdline; } @@ -530,7 +530,7 @@ void regex_prompt(Context& context, const String prompt, T func) { SelectionList selections = context.selections(); context.input_handler().prompt(prompt, "", get_face("Prompt"), complete_nothing, - [=](const String& str, PromptEvent event, Context& context) mutable { + [=](StringView str, PromptEvent event, Context& context) mutable { try { if (event != PromptEvent::Change and context.has_ui()) @@ -546,7 +546,9 @@ void regex_prompt(Context& context, const String prompt, T func) if (event == PromptEvent::Validate) context.push_jump(); - func(str.empty() ? Regex{} : Regex{str}, event, context); + Regex regex = str.empty() ? Regex{} + : Regex{str.begin(), str.end()}; + func(std::move(regex), event, context); } catch (RegexError& err) { @@ -748,7 +750,7 @@ void keep_pipe(Context& context, int) { context.input_handler().prompt( "keep pipe:", "", get_face("Prompt"), shell_complete, - [](const String& cmdline, PromptEvent event, Context& context) { + [](StringView cmdline, PromptEvent event, Context& context) { if (event != PromptEvent::Validate) return; const Buffer& buffer = context.buffer();