From 3915faf3820ad25f326c98c1f7042f9e2670202c Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 7 Jul 2014 10:45:26 -0700 Subject: [PATCH] bind should not show -k for bindings that are escape sequences, not keys --- builtin.cpp | 29 ++++++++++++++++++++--------- input.cpp | 4 ++-- input.h | 4 ++-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/builtin.cpp b/builtin.cpp index 5e5fc32c5..bf61b40b5 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -423,19 +423,30 @@ static void builtin_bind_list(const wchar_t *bind_mode) { continue; } - + + // Append the initial 'bind' command and the name wcstring tname; - - const wcstring eseq = input_terminfo_get_name(seq, tname) ? tname : escape_string(seq, 1); - append_format(stdout_buffer, L"bind -k %ls -M %ls -m %ls", eseq.c_str(), mode.c_str(), sets_mode.c_str()); + if (input_terminfo_get_name(seq, &tname)) + { + // Note that we show -k here because we have an input key name + append_format(stdout_buffer, L"bind -k %ls", tname.c_str()); + } + else + { + // No key name, so no -k; we show the escape sequence directly + const wcstring eseq = escape_string(seq, 1); + append_format(stdout_buffer, L"bind %ls", eseq.c_str()); + } + + // Now show the list of commands for (size_t i = 0; i < ecmds.size(); i++) { - wcstring ecmd = ecmds.at(i); - wchar_t *escaped = escape(ecmd.c_str(), 1); - append_format(stdout_buffer, L" %ls", escaped); - free(escaped); + const wcstring &ecmd = ecmds.at(i); + const wcstring escaped_ecmd = escape_string(ecmd, ESCAPE_ALL); + stdout_buffer.push_back(' '); + stdout_buffer.append(escaped_ecmd); } - append_format(stdout_buffer, L"\n"); + stdout_buffer.push_back(L'\n'); } } diff --git a/input.cpp b/input.cpp index 1367c88ea..128fe0fb8 100644 --- a/input.cpp +++ b/input.cpp @@ -1004,7 +1004,7 @@ bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq) } -bool input_terminfo_get_name(const wcstring &seq, wcstring &name) +bool input_terminfo_get_name(const wcstring &seq, wcstring *out_name) { input_init(); @@ -1020,7 +1020,7 @@ bool input_terminfo_get_name(const wcstring &seq, wcstring &name) const wcstring map_buf = format_string(L"%s", m.seq); if (map_buf == seq) { - name = m.name; + out_name->assign(m.name); return true; } } diff --git a/input.h b/input.h index b0afe081c..1ab43c03f 100644 --- a/input.h +++ b/input.h @@ -169,8 +169,8 @@ void input_function_set_status(bool status); */ bool input_terminfo_get_sequence(const wchar_t *name, wcstring *out_seq); -/** Return the name of the terminfo variable with the specified sequence */ -bool input_terminfo_get_name(const wcstring &seq, wcstring &name); +/** Return the name of the terminfo variable with the specified sequence, in out_name. Returns true if found, false if not found. */ +bool input_terminfo_get_name(const wcstring &seq, wcstring *out_name); /** Return a list of all known terminfo names */ wcstring_list_t input_terminfo_get_names(bool skip_null);