From 5fa4e0d2eeaba11fd933c10dcabf9138ef213b9f Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 10 Oct 2018 16:25:21 -0700 Subject: [PATCH] Highlight %self as an operator --- src/fish_tests.cpp | 8 +++++++- src/highlight.cpp | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 80e997e8e..91d9e0554 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -2472,7 +2472,6 @@ static void test_complete() { do_test(completions.at(1).completion == L"zero"); do_test((completions.at(1).flags & COMPLETE_NO_SPACE) != 0); - // Test wraps. do_test(comma_join(complete_get_wrap_targets(L"wrapper1")) == L""); complete_add_wrapper(L"wrapper1", L"wrapper2"); @@ -4086,6 +4085,13 @@ static void test_highlighting() { {L"end", highlight_spec_command}, }); + highlight_tests.push_back({ + {L"echo", highlight_spec_command}, + {L"%self", highlight_spec_operator}, + {L"not%self", highlight_spec_param}, + {L"self%not", highlight_spec_param}, + }); + // Verify variables and wildcards in commands using /bin/cat. env_set(L"VARIABLE_IN_COMMAND", ENV_LOCAL, {L"a"}); env_set(L"VARIABLE_IN_COMMAND2", ENV_LOCAL, {L"at"}); diff --git a/src/highlight.cpp b/src/highlight.cpp index ac988d42b..321ce9874 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -444,6 +444,12 @@ static void color_string_internal(const wcstring &buffstr, highlight_spec_t base const size_t buff_len = buffstr.size(); std::fill(colors, colors + buff_len, base_color); + // Hacky support for %self which must be an unquoted literal argument. + if (buffstr == PROCESS_EXPAND_SELF_STR) { + std::fill_n(colors, wcslen(PROCESS_EXPAND_SELF_STR), highlight_spec_operator); + return; + } + enum { e_unquoted, e_single_quoted, e_double_quoted } mode = e_unquoted; int bracket_count = 0; for (size_t in_pos = 0; in_pos < buff_len; in_pos++) { @@ -692,8 +698,8 @@ class highlighter_t { public: // Constructor - highlighter_t(const wcstring &str, size_t pos, const env_vars_snapshot_t &ev, - wcstring wd, bool can_do_io) + highlighter_t(const wcstring &str, size_t pos, const env_vars_snapshot_t &ev, wcstring wd, + bool can_do_io) : buff(str), cursor_pos(pos), vars(ev),