mirror of
https://github.com/mawww/kakoune.git
synced 2024-09-11 13:00:41 +03:00
Merge 312002700f
into 6674fe7587
This commit is contained in:
commit
fee058a9d9
47
src/main.cc
47
src/main.cc
@ -1102,13 +1102,14 @@ int main(int argc, char* argv[])
|
|||||||
{ "debug", { ArgCompleter{}, "initial debug option value" } },
|
{ "debug", { ArgCompleter{}, "initial debug option value" } },
|
||||||
{ "version", { {}, "display kakoune version and exit" } },
|
{ "version", { {}, "display kakoune version and exit" } },
|
||||||
{ "ro", { {}, "readonly mode" } },
|
{ "ro", { {}, "readonly mode" } },
|
||||||
{ "help", { {}, "display a help message and quit" } } }
|
{ "help", { {}, "display a help message and quit" } } },
|
||||||
|
ParameterDesc::Flags::WithCoord
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto show_usage = [&]() {
|
auto show_usage = [&]() {
|
||||||
write_stdout(format("Usage: {} [options] [file]... [+<line>[:<col>]|+:]\n\n"
|
write_stdout(format("Usage: {} [options] [--] [file]... [+<line>[:<col>]|+:]\n\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"{}\n"
|
"{}\n"
|
||||||
"Prefixing a positional argument with a plus (`+`) sign will place the\n"
|
"Prefixing a positional argument with a plus (`+`) sign will place the\n"
|
||||||
@ -1122,9 +1123,6 @@ int main(int argc, char* argv[])
|
|||||||
| transform([](auto* s) { return String{s}; })
|
| transform([](auto* s) { return String{s}; })
|
||||||
| gather<Vector<String>>();
|
| gather<Vector<String>>();
|
||||||
|
|
||||||
if (contains(params, "--help"_sv))
|
|
||||||
return show_usage();
|
|
||||||
|
|
||||||
ParametersParser parser{params, param_desc};
|
ParametersParser parser{params, param_desc};
|
||||||
|
|
||||||
const bool show_help_message = (bool)parser.get_switch("help");
|
const bool show_help_message = (bool)parser.get_switch("help");
|
||||||
@ -1185,32 +1183,8 @@ int main(int argc, char* argv[])
|
|||||||
parser.get_switch("i").value_or(StringView{}));
|
parser.get_switch("i").value_or(StringView{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<StringView> files;
|
auto init_coord = parser.get_coord();
|
||||||
Optional<BufferCoord> init_coord;
|
auto files = parser | gather<Vector<StringView>>();
|
||||||
for (auto& name : parser)
|
|
||||||
{
|
|
||||||
if (not name.empty() and name[0_byte] == '+')
|
|
||||||
{
|
|
||||||
if (name == "+" or name == "+:")
|
|
||||||
{
|
|
||||||
client_init = client_init + "; exec gj";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto colon = find(name, ':');
|
|
||||||
if (auto line = str_to_int_ifp({name.begin()+1, colon}))
|
|
||||||
{
|
|
||||||
init_coord = std::max<BufferCoord>({0,0}, {
|
|
||||||
*line - 1,
|
|
||||||
colon != name.end() ?
|
|
||||||
str_to_int_ifp({colon+1, name.end()}).value_or(1) - 1
|
|
||||||
: 0
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
files.emplace_back(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto server_session = parser.get_switch("c"))
|
if (auto server_session = parser.get_switch("c"))
|
||||||
{
|
{
|
||||||
@ -1222,14 +1196,11 @@ int main(int argc, char* argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String new_files;
|
String new_files;
|
||||||
for (auto name : files) {
|
for (auto file : files)
|
||||||
new_files += format("edit '{}'", escape(real_path(name), "'", '\''));
|
{
|
||||||
if (init_coord) {
|
new_files += format("edit -- '{}'\n", escape(real_path(file), "'", '\''));
|
||||||
new_files += format(" {} {}", init_coord->line + 1, init_coord->column + 1);
|
|
||||||
init_coord.reset();
|
|
||||||
}
|
|
||||||
new_files += ";";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return run_client(*server_session, {}, new_files + client_init, init_coord, ui_type, false);
|
return run_client(*server_session, {}, new_files + client_init, init_coord, ui_type, false);
|
||||||
|
@ -31,6 +31,7 @@ ParametersParser::ParametersParser(ParameterList params, const ParameterDesc& de
|
|||||||
const bool switches_only_at_start = desc.flags & ParameterDesc::Flags::SwitchesOnlyAtStart;
|
const bool switches_only_at_start = desc.flags & ParameterDesc::Flags::SwitchesOnlyAtStart;
|
||||||
const bool ignore_unknown_switches = desc.flags & ParameterDesc::Flags::IgnoreUnknownSwitches;
|
const bool ignore_unknown_switches = desc.flags & ParameterDesc::Flags::IgnoreUnknownSwitches;
|
||||||
bool only_pos = desc.flags & ParameterDesc::Flags::SwitchesAsPositional;
|
bool only_pos = desc.flags & ParameterDesc::Flags::SwitchesAsPositional;
|
||||||
|
bool with_coord = desc.flags & ParameterDesc::Flags::WithCoord;
|
||||||
|
|
||||||
Vector<bool> switch_seen(desc.switches.size(), false);
|
Vector<bool> switch_seen(desc.switches.size(), false);
|
||||||
for (size_t i = 0; i < params.size(); ++i)
|
for (size_t i = 0; i < params.size(); ++i)
|
||||||
@ -40,6 +41,25 @@ ParametersParser::ParametersParser(ParameterList params, const ParameterDesc& de
|
|||||||
m_state = State::Switch;
|
m_state = State::Switch;
|
||||||
only_pos = true;
|
only_pos = true;
|
||||||
}
|
}
|
||||||
|
else if (not only_pos and with_coord and not params[i].empty() and params[i][0_byte] == '+')
|
||||||
|
{
|
||||||
|
m_state = State::Switch;
|
||||||
|
with_coord = false;
|
||||||
|
const auto coord_str = params[i].substr(1_byte);
|
||||||
|
const auto colon = find(coord_str, ':');
|
||||||
|
|
||||||
|
const auto line_str = StringView{coord_str.begin(), colon};
|
||||||
|
const LineCount line = line_str.empty() ? INT_MAX : std::max(1, str_to_int(line_str)) - 1;
|
||||||
|
|
||||||
|
ByteCount column = 0;
|
||||||
|
if (colon != coord_str.end())
|
||||||
|
{
|
||||||
|
const auto column_str = StringView{colon + 1, coord_str.end()};
|
||||||
|
column = column_str.empty() ? INT_MAX : std::max(1, str_to_int(column_str)) - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_coord = BufferCoord{line, column};
|
||||||
|
}
|
||||||
else if (not only_pos and not params[i].empty() and params[i][0_byte] == '-')
|
else if (not only_pos and not params[i].empty() and params[i][0_byte] == '-')
|
||||||
{
|
{
|
||||||
StringView switch_name = params[i].substr(1_byte);
|
StringView switch_name = params[i].substr(1_byte);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "hash_map.hh"
|
#include "hash_map.hh"
|
||||||
#include "meta.hh"
|
#include "meta.hh"
|
||||||
#include "array_view.hh"
|
#include "array_view.hh"
|
||||||
|
#include "coord.hh"
|
||||||
#include "optional.hh"
|
#include "optional.hh"
|
||||||
#include "flags.hh"
|
#include "flags.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
@ -62,7 +63,8 @@ struct ParameterDesc
|
|||||||
None = 0,
|
None = 0,
|
||||||
SwitchesOnlyAtStart = 0b0001,
|
SwitchesOnlyAtStart = 0b0001,
|
||||||
SwitchesAsPositional = 0b0010,
|
SwitchesAsPositional = 0b0010,
|
||||||
IgnoreUnknownSwitches = 0b0100
|
IgnoreUnknownSwitches = 0b0100,
|
||||||
|
WithCoord = 0b1000,
|
||||||
};
|
};
|
||||||
friend constexpr bool with_bit_ops(Meta::Type<Flags>) { return true; }
|
friend constexpr bool with_bit_ops(Meta::Type<Flags>) { return true; }
|
||||||
|
|
||||||
@ -142,12 +144,14 @@ struct ParametersParser
|
|||||||
iterator end() const { return iterator(*this, m_positional_indices.size()); }
|
iterator end() const { return iterator(*this, m_positional_indices.size()); }
|
||||||
|
|
||||||
State state() const { return *m_state; }
|
State state() const { return *m_state; }
|
||||||
|
Optional<BufferCoord> get_coord() const { return m_coord; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ParameterList m_params;
|
ParameterList m_params;
|
||||||
Vector<size_t, MemoryDomain::Commands> m_positional_indices;
|
Vector<size_t, MemoryDomain::Commands> m_positional_indices;
|
||||||
HashMap<String, StringView> m_switches;
|
HashMap<String, StringView> m_switches;
|
||||||
Optional<State> m_state;
|
Optional<State> m_state;
|
||||||
|
Optional<BufferCoord> m_coord;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user