Add or keybind input function

This commit is contained in:
Olivier FAURE
2020-07-22 19:18:24 +02:00
committed by Johannes Altmanninger
parent b990bb1f7a
commit 6778d04aa5
4 changed files with 16 additions and 3 deletions

View File

@@ -162,6 +162,8 @@ The following special input functions are available:
- ``kill-word``, move the next word to the killring
- ``or``, only execute the next function if the previous succeeded (note: only some functions report success)
- ``pager-toggle-search``, toggles the search field if the completions pager is visible.
- ``repaint``, reexecutes the prompt functions and redraws the prompt. Multiple successive repaints are coalesced.

View File

@@ -146,6 +146,7 @@ static const input_function_metadata_t input_function_metadata[] = {
{readline_cmd_t::repeat_jump, L"repeat-jump"},
{readline_cmd_t::reverse_repeat_jump, L"repeat-jump-reverse"},
{readline_cmd_t::func_and, L"and"},
{readline_cmd_t::func_or, L"or"},
{readline_cmd_t::expand_abbr, L"expand-abbr"},
{readline_cmd_t::delete_or_exit, L"delete-or-exit"},
{readline_cmd_t::cancel_commandline, L"cancel-commandline"},
@@ -524,10 +525,18 @@ char_event_t inputter_t::readch(bool allow_commands) {
: char_input_style_t::normal;
return res;
}
case readline_cmd_t::func_and: {
if (function_status_) {
return readch();
case readline_cmd_t::func_and:
case readline_cmd_t::func_or: {
// If previous function has right status, we keep reading tokens
if (evt.get_readline() == readline_cmd_t::func_and) {
if (function_status_)
return readch();
} else {
assert(evt.get_readline() == readline_cmd_t::func_or);
if (!function_status_)
return readch();
}
// Else we flush remaining tokens
do {
evt = event_queue_.readch();
} while (evt.is_readline());

View File

@@ -69,6 +69,7 @@ enum class readline_cmd_t {
forward_jump_till,
backward_jump_till,
func_and,
func_or,
expand_abbr,
delete_or_exit,
cancel_commandline,

View File

@@ -3532,6 +3532,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
// Some commands should have been handled internally by inputter_t::readch().
case rl::self_insert:
case rl::self_insert_notfirst:
case rl::func_or:
case rl::func_and: {
DIE("should have been handled by inputter_t::readch");
}