From 39099ceb10834dd0646f09f93f33322bbd8e16ed Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 29 May 2019 20:36:01 +0200 Subject: [PATCH] Remove R_BEGIN_INPUT_FUNCTIONS The enum starts at 0 (defined to be!), so we can eliminate this one. That allows us to remove a reliance on the position of beginning_of_line, and it would trigger a "type-limits" warning. Also leave a comment because I actually hit that. --- src/input.cpp | 7 +++---- src/input_common.h | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index e9fb2b5cd..cb151ce7b 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -63,7 +63,7 @@ struct terminfo_mapping_t { const char *seq; // character sequence generated on keypress }; -static constexpr size_t input_function_count = R_END_INPUT_FUNCTIONS - R_BEGIN_INPUT_FUNCTIONS; +static constexpr size_t input_function_count = R_END_INPUT_FUNCTIONS; /// Input function metadata. This list should be kept in sync with the key code list in /// input_common.h. @@ -140,9 +140,8 @@ static_assert(sizeof(input_function_metadata) / sizeof(input_function_metadata[0 "input_function_metadata?"); wcstring describe_char(wint_t c) { - if (c >= R_BEGIN_INPUT_FUNCTIONS && c < R_END_INPUT_FUNCTIONS) { - size_t idx = c - R_BEGIN_INPUT_FUNCTIONS; - return format_string(L"%02x (%ls)", c, input_function_metadata[idx].name); + if (c < R_END_INPUT_FUNCTIONS) { + return format_string(L"%02x (%ls)", c, input_function_metadata[c].name); } return format_string(L"%02x", c); } diff --git a/src/input_common.h b/src/input_common.h index 62a31d72a..2f00c7148 100644 --- a/src/input_common.h +++ b/src/input_common.h @@ -67,12 +67,12 @@ enum class readline_cmd_t { expand_abbr, cancel, repeat_jump, - reverse_repeat_jump, + // NOTE: This one has to be last. + reverse_repeat_jump }; // The range of key codes for inputrc-style keyboard functions. enum { - R_BEGIN_INPUT_FUNCTIONS = static_cast(readline_cmd_t::beginning_of_line), R_END_INPUT_FUNCTIONS = static_cast(readline_cmd_t::reverse_repeat_jump) + 1 };