Allow restricting earsing and listing of bindings to specific mode;

implement force repaint and multi-char bindings;
This commit is contained in:
Julian Aron Prenner 2013-12-31 14:53:29 +01:00
parent d1faac58dd
commit 2587649ca2
5 changed files with 69 additions and 15 deletions

View file

@ -403,7 +403,7 @@ int builtin_test(parser_t &parser, wchar_t **argv);
/**
List all current key bindings
*/
static void builtin_bind_list()
static void builtin_bind_list(const wchar_t *bind_mode)
{
size_t i;
wcstring_list_t lst;
@ -417,6 +417,12 @@ static void builtin_bind_list()
wcstring mode;
input_mapping_get(seq, ecmd, mode);
if(bind_mode != NULL && wcscmp(mode.c_str(), bind_mode))
{
continue;
}
ecmd = escape_string(ecmd, 1);
wcstring tname;
@ -522,7 +528,7 @@ static int builtin_bind_add(const wchar_t *seq, const wchar_t *cmd, const wchar_
\param seq an array of all key bindings to erase
\param all if specified, _all_ key bindings will be erased
*/
static void builtin_bind_erase(wchar_t **seq, int all)
static void builtin_bind_erase(wchar_t **seq, int all, const wchar_t *mode)
{
if (all)
{
@ -532,7 +538,7 @@ static void builtin_bind_erase(wchar_t **seq, int all)
for (i=0; i<lst.size(); i++)
{
input_mapping_erase(lst.at(i).c_str());
input_mapping_erase(lst.at(i).c_str(), mode);
}
}
@ -540,7 +546,7 @@ static void builtin_bind_erase(wchar_t **seq, int all)
{
while (*seq)
{
input_mapping_erase(*seq++);
input_mapping_erase(*seq++, mode);
}
}
@ -569,7 +575,9 @@ static int builtin_bind(parser_t &parser, wchar_t **argv)
int all = 0;
const wchar_t *bind_mode = DEFAULT_BIND_MODE;
bool bind_mode_given = false;
const wchar_t *new_bind_mode = DEFAULT_BIND_MODE;
bool new_bind_mode_given = false;
int use_terminfo = 0;
@ -667,10 +675,12 @@ static int builtin_bind(parser_t &parser, wchar_t **argv)
case 'M':
bind_mode = woptarg;
bind_mode_given = true;
break;
case 'm':
new_bind_mode = woptarg;
new_bind_mode_given = true;
break;
case '?':
@ -679,7 +689,14 @@ static int builtin_bind(parser_t &parser, wchar_t **argv)
}
}
/*
* if mode is given, but not new mode, default to new mode to mode
*/
if(bind_mode_given && !new_bind_mode_given)
{
new_bind_mode = bind_mode;
}
switch (mode)
@ -687,7 +704,7 @@ static int builtin_bind(parser_t &parser, wchar_t **argv)
case BIND_ERASE:
{
builtin_bind_erase(&argv[woptind], all);
builtin_bind_erase(&argv[woptind], all, bind_mode_given ? bind_mode : NULL);
break;
}
@ -697,7 +714,7 @@ static int builtin_bind(parser_t &parser, wchar_t **argv)
{
case 0:
{
builtin_bind_list();
builtin_bind_list(bind_mode_given ? bind_mode : NULL);
break;
}

View file

@ -129,6 +129,7 @@ static const wchar_t * const name_arr[] =
L"beginning-of-buffer",
L"end-of-buffer",
L"repaint",
L"force-repaint",
L"up-line",
L"down-line",
L"suppress-autosuggestion",
@ -218,6 +219,7 @@ static const wchar_t code_arr[] =
R_BEGINNING_OF_BUFFER,
R_END_OF_BUFFER,
R_REPAINT,
R_FORCE_REPAINT,
R_UP_LINE,
R_DOWN_LINE,
R_SUPPRESS_AUTOSUGGESTION,
@ -514,11 +516,22 @@ static wint_t input_try_mapping(const input_mapping_t &m)
const wchar_t *str = m.seq.c_str();
for (j=0; str[j] != L'\0'; j++)
{
bool timed = (j > 0);
bool timed;
if(iswalnum(str[j]))
{
timed = false;
}
else
{
timed = (j > 0);
}
c = input_common_readch(timed);
if (str[j] != c)
{
break;
}
}
if (str[j] == L'\0')
{
@ -548,7 +561,6 @@ void input_unreadch(wint_t ch)
wint_t input_readch()
{
size_t i;
CHECK_BLOCK(R_NULL);
@ -569,8 +581,12 @@ wint_t input_readch()
{
const input_mapping_t &m = mapping_list.at(i);
// debug(0, L"trying mapping (%ls,%ls,%ls,%ls)\n", escape(m.seq.c_str(), 1),
// m.command.c_str(), m.mode.c_str(), m.new_mode.c_str());
if(wcscmp(m.mode.c_str(), input_get_bind_mode()))
{
// debug(0, L"skipping mapping because mode %ls != %ls\n", m.mode.c_str(), input_get_bind_mode());
continue;
}
@ -641,7 +657,7 @@ bool input_mapping_erase(const wchar_t *sequence, const wchar_t *mode)
for (i=0; i<sz; i++)
{
const input_mapping_t &m = mapping_list.at(i);
if (sequence == m.seq && mode == m.mode)
if (sequence == m.seq && (mode == NULL || mode == m.mode))
{
if (i != (sz-1))
{

View file

@ -56,6 +56,7 @@ enum
R_BEGINNING_OF_BUFFER,
R_END_OF_BUFFER,
R_REPAINT,
R_FORCE_REPAINT,
R_UP_LINE,
R_DOWN_LINE,
R_SUPPRESS_AUTOSUGGESTION,

View file

@ -3164,6 +3164,7 @@ const wchar_t *reader_readline(void)
break;
}
case R_FORCE_REPAINT:
case R_REPAINT:
{
if (! coalescing_repaints)

View file

@ -1,6 +1,3 @@
function nothing
end
function fish_vi_key_bindings -d "vi-like key bindings for fish"
bind --erase --all
@ -19,7 +16,7 @@ function fish_vi_key_bindings -d "vi-like key bindings for fish"
bind -k right forward-char
bind -k left backward-char
bind \n execute
bind -m insert i nothing
bind -m insert i force-repaint
bind -m insert a forward-char
bind \x24 end-of-line
@ -27,6 +24,15 @@ function fish_vi_key_bindings -d "vi-like key bindings for fish"
bind \e\[H beginning-of-line
bind \e\[F end-of-line
# NOTE: history-search-backward and history-search-forward
# must both be bound for `commandline -f ...' to work, and thus for up-or-search
# and down-or-search to work, since those are actually
# simple shell functions that use `commandline -f ...'.
# Generally, commandline -f can only invoke functions that have been bound previously
bind u history-search-backward
bind \cr history-search-forward
bind k up-or-search
bind j down-or-search
bind \e\[A up-or-search
@ -39,6 +45,8 @@ function fish_vi_key_bindings -d "vi-like key bindings for fish"
bind w forward-word
bind W backward-word
bind dd kill-line
bind y yank
bind p yank-pop
@ -51,6 +59,17 @@ function fish_vi_key_bindings -d "vi-like key bindings for fish"
bind -M insert -k dc delete-char
bind -M insert -k backspace backward-delete-char
bind -M insert -m default \e nothing
bind -M insert -m default \e force-repaint
bind -M insert -m default q force-repaint
bind -M insert \t complete
bind -M insert \e\[A up-or-search
bind -M insert \e\[B down-or-search
bind -M insert -k down down-or-search
bind -M insert -k up up-or-search
bind -M insert \e\[C forward-char
bind -M insert \e\[D backward-char
bind -M insert -k right forward-char
bind -M insert -k left backward-char
end