From 5cadea0173a90e314f6d71285d19653fbcaf5dd3 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 26 Sep 2020 13:55:46 -0700 Subject: [PATCH] Migrate the complete_custom transient command line pop to cleanup_t This ensures that it gets cleaned up even if there is a mid-function return. --- src/complete.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/complete.cpp b/src/complete.cpp index 7de4638ae..feafd1822 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -1336,10 +1336,13 @@ void completer_t::complete_custom(const wcstring &cmd, const wcstring &cmdline, // Perhaps set a transient commandline so that custom completions // buitin_commandline will refer to the wrapped command. But not if // we're doing autosuggestions. + maybe_t remove_transient{}; bool wants_transient = depth > 0 && !is_autosuggest; if (wants_transient) { ctx.parser->libdata().transient_commandlines.push_back(cmdline); + remove_transient.emplace([&] { ctx.parser->libdata().transient_commandlines.pop_back(); }); } + maybe_t equals_pos = variable_assignment_equals_pos(cmd); bool is_variable_assignment = bool(equals_pos); if (is_variable_assignment && !is_autosuggest) { @@ -1385,9 +1388,6 @@ void completer_t::complete_custom(const wcstring &cmd, const wcstring &cmdline, !had_ddash)) { // Invoke any custom completions for this command. *do_file = false; } - if (wants_transient) { - ctx.parser->libdata().transient_commandlines.pop_back(); - } } // Given a command line \p command_line and the range of the command itself within the