1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-08-17 00:30:26 +03:00

Compare commits

...

8 Commits

Author SHA1 Message Date
Philipp Jungkamp
f812403782
Merge 312002700f into 80fcfebca8 2024-06-27 15:54:54 +02:00
Maxime Coste
80fcfebca8 Fix order of evaluation issue when compiling regex alternations
The previous implementation was relying on the left hand side of the
assignement's side effects to be sequenced before the right hand side
evaluation (so --split_pos was expected to have taken place)

This is actually counter to C++17 which guarantees evaluation of the
right hand side of the assignement first. For some reason this is
not the case with GCC on linux.
2024-06-26 22:38:01 +10:00
Maxime Coste
cbdd200e73 Fix corner case in passin arguments to grep and make 2024-06-26 20:35:34 +10:00
Maxime Coste
374a7a8c99 Remove some selection copies in pipe and throw early if read only
Throwing early avoids losing selections in this case.
2024-06-24 21:18:17 +10:00
Philipp Jungkamp
312002700f 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.
2024-06-16 20:30:56 +02:00
Philipp Jungkamp
0cdb088981 Add WithCoord flag to ParameterDesc
Adding the `WithCoord` flag will make the `ParametersParser` try to
parse a special `+<line>:<column>` VIM-style switch.
2024-06-16 20:30:56 +02:00
Philipp Jungkamp
7e9c4b7f6a Remove --help commandline special case
This special case was not handled in the `ParametersParser` and
therefore did not respect the `--` separator for switches.
2024-06-16 18:39:03 +02:00
Philipp Jungkamp
385a1aec18 Show [--] in -help output
The current help output of kakoune doesn't mention that a double dash
(`--`) can be used to separate the files from options.
2024-06-16 14:48:37 +02:00
7 changed files with 52 additions and 47 deletions

View File

@ -28,7 +28,7 @@ define-command -params .. -docstring %{
esac
fi
$kak_opt_grepcmd "$@" 2>&1 | tr -d '\r'
} %arg{@}
} -- %arg{@}
set-option buffer filetype grep
set-option buffer jump_current_line 0
}

View File

@ -16,7 +16,7 @@ define-command -params .. -docstring %{
fifo -scroll -name *make* -script %{
trap - INT QUIT
$kak_opt_makecmd "$@"
} %arg{@} # pass arguments for "$@" above, exit to avoid evaluating them
} -- %arg{@}
set-option buffer filetype make
set-option buffer jump_current_line 0
}

View File

@ -1102,13 +1102,14 @@ 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
{
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"
"{}\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}; })
| gather<Vector<String>>();
if (contains(params, "--help"_sv))
return show_usage();
ParametersParser parser{params, param_desc};
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{}));
}
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"))
{
@ -1222,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);

View File

@ -589,13 +589,13 @@ void pipe(Context& context, NormalParams params)
return;
Buffer& buffer = context.buffer();
SelectionList selections = context.selections();
if (replace)
{
buffer.throw_if_read_only();
ScopedEdition edition(context);
ForwardChangesTracker changes_tracker;
size_t timestamp = buffer.timestamp();
Vector<Selection> new_sels;
SelectionList selections = context.selections();
for (auto& sel : selections)
{
const auto beg = changes_tracker.get_new_coord_tolerant(sel.min());
@ -614,20 +614,27 @@ void pipe(Context& context, NormalParams params)
auto new_end = apply_diff(buffer, beg, in, out);
if (new_end != beg)
new_sels.push_back(keep_direction({beg, buffer.char_prev(new_end), std::move(sel.captures())}, sel));
{
auto& min = sel.min();
auto& max = sel.max();
min = beg;
max = buffer.char_prev(new_end);
}
else
{
if (new_end != BufferCoord{})
new_end = buffer.char_prev(new_end);
new_sels.push_back({new_end, new_end, std::move(sel.captures())});
sel.set(new_end);
}
changes_tracker.update(buffer, timestamp);
}
context.selections_write_only().set(std::move(new_sels), selections.main_index());
selections.force_timestamp(timestamp);
context.selections_write_only() = std::move(selections);
}
else
{
SelectionList& selections = context.selections();
const auto old_main = selections.main_index();
for (int i = 0; i < selections.size(); ++i)
{

View File

@ -31,6 +31,7 @@ ParametersParser::ParametersParser(ParameterList params, const ParameterDesc& de
const bool switches_only_at_start = desc.flags & ParameterDesc::Flags::SwitchesOnlyAtStart;
const bool ignore_unknown_switches = desc.flags & ParameterDesc::Flags::IgnoreUnknownSwitches;
bool only_pos = desc.flags & ParameterDesc::Flags::SwitchesAsPositional;
bool with_coord = desc.flags & ParameterDesc::Flags::WithCoord;
Vector<bool> switch_seen(desc.switches.size(), false);
for (size_t i = 0; i < params.size(); ++i)
@ -40,6 +41,25 @@ ParametersParser::ParametersParser(ParameterList params, const ParameterDesc& de
m_state = State::Switch;
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] == '-')
{
StringView switch_name = params[i].substr(1_byte);

View File

@ -5,6 +5,7 @@
#include "hash_map.hh"
#include "meta.hh"
#include "array_view.hh"
#include "coord.hh"
#include "optional.hh"
#include "flags.hh"
#include "string.hh"
@ -62,7 +63,8 @@ struct ParameterDesc
None = 0,
SwitchesOnlyAtStart = 0b0001,
SwitchesAsPositional = 0b0010,
IgnoreUnknownSwitches = 0b0100
IgnoreUnknownSwitches = 0b0100,
WithCoord = 0b1000,
};
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()); }
State state() const { return *m_state; }
Optional<BufferCoord> get_coord() const { return m_coord; }
private:
ParameterList m_params;
Vector<size_t, MemoryDomain::Commands> m_positional_indices;
HashMap<String, StringView> m_switches;
Optional<State> m_state;
Optional<BufferCoord> m_coord;
};
}

View File

@ -753,7 +753,10 @@ private:
{
auto node = compile_node<direction>(child);
if (child != index+1)
m_program.instructions[--split_pos].param.split = CompiledRegex::Param::Split{.offset = offset(node, split_pos), .prioritize_parent = true};
{
--split_pos;
m_program.instructions[split_pos].param.split = {.offset = offset(node, split_pos), .prioritize_parent = true};
}
if (get_node(child).children_end != end)
{
auto jump = push_inst(CompiledRegex::Jump);