mirror of
https://github.com/mawww/kakoune.git
synced 2024-10-05 17:18:00 +03:00
Use WithCoord
parameter parsing for argv
This moves the parameter parsing for the `+<line>:<column>` switch of the commandline to the `ParametersParser`. The position switch now respects the `--` separator between switches and files. The manpage does not document the old behaviour of `+:[column]`. `+:[column]` works exactly like `+`. This is compatible with the previously documented behaviour for `+:`.
This commit is contained in:
parent
0cdb088981
commit
fa64755de2
@ -14,7 +14,8 @@
|
||||
.Op Fl ui Ar ui_type
|
||||
.Op Fl e Ar command
|
||||
.Op Fl E Ar command
|
||||
.Op Sy + Ns Ar line Ns Oo Sy \&: Ns Ar column Oc | Sy +:
|
||||
.Op Sy + Ns Oo Ns Ar line Oc | Sy + Ns Ar line Ns Sy \&: Ns Oo Ns Ar column Oc
|
||||
.Op Fl Fl
|
||||
.Op Ar file ...
|
||||
.
|
||||
.Nm
|
||||
@ -151,10 +152,10 @@ Begin in
|
||||
.Em readonly mode ,
|
||||
all the buffers opened will not be written to disk.
|
||||
.
|
||||
.It Sy + Ns Ar line Ns Oo Sy \&: Ns Ar column Oc | Sy +:
|
||||
.It Sy + Ns Oo Ns Ar line Oc | Sy + Ns Ar line Ns Sy \&: Ns Oo Ns Ar column Oc
|
||||
Specify a target line and column for the first file.
|
||||
When the plus sign is followed by only a colon, then the cursor is sent
|
||||
to the last line of the file.
|
||||
When the line is omitted the cursor will go to the end of the buffer.
|
||||
When colon is present but the column is omitted the cursor will got to the end of the given line.
|
||||
.
|
||||
.It Ar file ...
|
||||
One or more
|
||||
|
42
src/main.cc
42
src/main.cc
@ -1102,7 +1102,8 @@ int main(int argc, char* argv[])
|
||||
{ "debug", { ArgCompleter{}, "initial debug option value" } },
|
||||
{ "version", { {}, "display kakoune version and exit" } },
|
||||
{ "ro", { {}, "readonly mode" } },
|
||||
{ "help", { {}, "display a help message and quit" } } }
|
||||
{ "help", { {}, "display a help message and quit" } } },
|
||||
ParameterDesc::Flags::WithCoord
|
||||
};
|
||||
|
||||
try
|
||||
@ -1182,32 +1183,8 @@ int main(int argc, char* argv[])
|
||||
parser.get_switch("i").value_or(StringView{}));
|
||||
}
|
||||
|
||||
Vector<StringView> files;
|
||||
Optional<BufferCoord> init_coord;
|
||||
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);
|
||||
}
|
||||
auto init_coord = parser.get_coord();
|
||||
auto files = parser | gather<Vector<StringView>>();
|
||||
|
||||
if (auto server_session = parser.get_switch("c"))
|
||||
{
|
||||
@ -1219,14 +1196,11 @@ int main(int argc, char* argv[])
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
String new_files;
|
||||
for (auto name : files) {
|
||||
new_files += format("edit '{}'", escape(real_path(name), "'", '\''));
|
||||
if (init_coord) {
|
||||
new_files += format(" {} {}", init_coord->line + 1, init_coord->column + 1);
|
||||
init_coord.reset();
|
||||
}
|
||||
new_files += ";";
|
||||
for (auto file : files)
|
||||
{
|
||||
new_files += format("edit -- '{}'\n", escape(real_path(file), "'", '\''));
|
||||
}
|
||||
|
||||
return run_client(*server_session, {}, new_files + client_init, init_coord, ui_type, false);
|
||||
|
Loading…
Reference in New Issue
Block a user