mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-28 22:22:41 +03:00
Port more code to use the format function instead of adhoc string concat
This commit is contained in:
parent
57a03d8495
commit
f19bb4fe6d
@ -86,7 +86,7 @@ Buffer& BufferManager::get_buffer(StringView name)
|
||||
{
|
||||
Buffer* res = get_buffer_ifp(name);
|
||||
if (not res)
|
||||
throw runtime_error("no such buffer '"_str + name + "'");
|
||||
throw runtime_error(format("no such buffer '{}'", name));
|
||||
return *res;
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ String parse_filename(StringView filename)
|
||||
{
|
||||
if (filename.length() >= 1 and filename[0_byte] == '~' and
|
||||
(filename.length() == 1 or filename[1_byte] == '/'))
|
||||
return parse_filename("$HOME"_str + filename.substr(1_byte));
|
||||
return parse_filename("$HOME" + filename.substr(1_byte));
|
||||
|
||||
ByteCount pos = 0;
|
||||
String result;
|
||||
|
@ -31,7 +31,7 @@ Highlighter& HighlighterGroup::get_child(StringView path)
|
||||
StringView id(path.begin(), sep_it);
|
||||
auto it = m_highlighters.find(id);
|
||||
if (it == m_highlighters.end())
|
||||
throw child_not_found("no such id: "_str + id);
|
||||
throw child_not_found("no such id: " + id);
|
||||
if (sep_it == path.end())
|
||||
return *it->second;
|
||||
else
|
||||
|
@ -1150,7 +1150,7 @@ public:
|
||||
StringView id(path.begin(), sep_it);
|
||||
auto it = m_groups.find(id);
|
||||
if (it == m_groups.end())
|
||||
throw child_not_found("no such id: "_str + id);
|
||||
throw child_not_found(format("no such id: {}", id));
|
||||
if (sep_it == path.end())
|
||||
return it->second;
|
||||
else
|
||||
|
@ -390,12 +390,12 @@ int run_server(StringView session, StringView init_command,
|
||||
if (not ignore_kakrc) try
|
||||
{
|
||||
Context initialisation_context{Context::EmptyContextFlag{}};
|
||||
command_manager.execute("source " + runtime_directory() + "/kakrc",
|
||||
command_manager.execute(format("source {}/kakrc", runtime_directory()),
|
||||
initialisation_context);
|
||||
}
|
||||
catch (Kakoune::runtime_error& error)
|
||||
{
|
||||
write_debug("error while parsing kakrc:\n "_str + error.what());
|
||||
write_debug(format("error while parsing kakrc:\n {}", error.what()));
|
||||
}
|
||||
catch (Kakoune::client_removed&)
|
||||
{
|
||||
@ -419,7 +419,7 @@ int run_server(StringView session, StringView init_command,
|
||||
}
|
||||
catch (Kakoune::runtime_error& error)
|
||||
{
|
||||
write_debug("error while opening command line files: "_str + error.what());
|
||||
write_debug(format("error while opening command line files: {}", error.what()));
|
||||
}
|
||||
else
|
||||
new Buffer("*scratch*", Buffer::Flags::None);
|
||||
|
@ -585,14 +585,14 @@ void regex_prompt(Context& context, const String prompt, T func)
|
||||
catch (RegexError& err)
|
||||
{
|
||||
if (event == PromptEvent::Validate)
|
||||
throw runtime_error("regex error: "_str + err.what());
|
||||
throw runtime_error(format("regex error: {}", err.what()));
|
||||
else
|
||||
context.input_handler().set_prompt_face(get_face("Error"));
|
||||
}
|
||||
catch (std::runtime_error& err)
|
||||
{
|
||||
if (event == PromptEvent::Validate)
|
||||
throw runtime_error("regex error: "_str + err.what());
|
||||
throw runtime_error(format("regex error: {}", err.what()));
|
||||
else
|
||||
{
|
||||
context.input_handler().set_prompt_face(get_face("Error"));
|
||||
@ -643,7 +643,7 @@ void search_next(Context& context, NormalParams params)
|
||||
}
|
||||
catch (RegexError& err)
|
||||
{
|
||||
throw runtime_error("regex error: "_str + err.what());
|
||||
throw runtime_error(format("regex error: ", err.what()));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -178,7 +178,7 @@ inline void option_from_string(StringView str, LineAndColumn<EffectiveType, Line
|
||||
{
|
||||
auto vals = split(str, tuple_separator);
|
||||
if (vals.size() != 2)
|
||||
throw runtime_error("expected <line>"_str + tuple_separator + "<column>");
|
||||
throw runtime_error(format("expected <line>{}<column>", tuple_separator));
|
||||
opt.line = str_to_int(vals[0]);
|
||||
opt.column = str_to_int(vals[1]);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ void option_from_string(StringView str, Regex& re)
|
||||
}
|
||||
catch (RegexError& err)
|
||||
{
|
||||
throw runtime_error("unable to create regex: "_str + err.what());
|
||||
throw runtime_error(format("unable to create regex: {}", err.what()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -624,10 +624,10 @@ Server::Server(String session_name)
|
||||
sockaddr_un addr = session_addr(m_session);
|
||||
|
||||
if (bind(listen_sock, (sockaddr*) &addr, sizeof(sockaddr_un)) == -1)
|
||||
throw runtime_error("unable to bind listen socket "_str + addr.sun_path);
|
||||
throw runtime_error(format("unable to bind listen socket '{}'", addr.sun_path));
|
||||
|
||||
if (listen(listen_sock, 4) == -1)
|
||||
throw runtime_error("unable to listen on socket "_str + addr.sun_path);
|
||||
throw runtime_error(format("unable to listen on socket '{}'", addr.sun_path));
|
||||
|
||||
auto accepter = [this](FDWatcher& watcher, EventMode mode) {
|
||||
sockaddr_un client_addr;
|
||||
|
@ -18,11 +18,7 @@ static const Regex env_var_regex(R"(\bkak_(\w+)\b)");
|
||||
ShellManager::ShellManager()
|
||||
{
|
||||
const char* path = getenv("PATH");
|
||||
String new_path;
|
||||
if (path)
|
||||
new_path = path + ":"_str;
|
||||
|
||||
new_path += split_path(get_kak_binary_path()).first;
|
||||
auto new_path = format("{}:{}", path, split_path(get_kak_binary_path()).first);
|
||||
setenv("PATH", new_path.c_str(), 1);
|
||||
}
|
||||
|
||||
@ -98,7 +94,7 @@ std::pair<String, int> ShellManager::eval(
|
||||
else try
|
||||
{
|
||||
String value = get_val(name, context);
|
||||
setenv(("kak_"_str + name).c_str(), value.c_str(), 1);
|
||||
setenv(format("kak_{}", name).c_str(), value.c_str(), 1);
|
||||
}
|
||||
catch (runtime_error&) {}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public:
|
||||
constexpr StringView() = default;
|
||||
constexpr StringView(const char* data, ByteCount length)
|
||||
: m_data{data}, m_length{length} {}
|
||||
constexpr StringView(const char* data) : m_data{data}, m_length{strlen(data)} {}
|
||||
constexpr StringView(const char* data) : m_data{data}, m_length{data ? strlen(data) : 0} {}
|
||||
constexpr StringView(const char* begin, const char* end) : m_data{begin}, m_length{(int)(end - begin)} {}
|
||||
StringView(const String& str) : m_data{str.data()}, m_length{(int)str.length()} {}
|
||||
StringView(const char& c) : m_data(&c), m_length(1) {}
|
||||
|
Loading…
Reference in New Issue
Block a user