diff --git a/src/builtin_complete.cpp b/src/builtin_complete.cpp index 6fd4349f3..ee7f235ad 100644 --- a/src/builtin_complete.cpp +++ b/src/builtin_complete.cpp @@ -163,114 +163,54 @@ static void builtin_complete_add(const wcstring_list_t &cmd, } } -/** - Silly function -*/ -static void builtin_complete_remove3(const wchar_t *cmd, - int cmd_type, - wchar_t short_opt, - const wcstring_list_t &long_opt, - int long_mode) +static void builtin_complete_remove_cmd(const wcstring &cmd, + int cmd_type, + const wchar_t *short_opt, + const wcstring_list_t &gnu_opt, + const wcstring_list_t &old_opt) { - for (size_t i=0; ioptions.begin(); + while (iter != this->options.end()) { - this->options.clear(); - } - else - { - for (option_list_t::iterator iter = this->options.begin(); iter != this->options.end();) + if (iter->option == option && iter->type == type) { - complete_entry_opt_t &o = *iter; - if (o.option.empty()) - { - // Just arguments, no match possible - continue; - } - bool matches = false; - bool mode_is_single = (o.type == option_type_single_long); - if (o.type == option_type_short) - { - matches = (short_opt && o.option.at(0) == short_opt); - } - else - { - matches = (mode_is_single == old_mode && long_opt && o.option == long_opt); - } - - if (matches) - { - /* fwprintf( stderr, - L"remove option -%lc --%ls\n", - o->short_opt?o->short_opt:L' ', - o->long_opt ); - */ - /* Destroy this option and go to the next one */ - iter = this->options.erase(iter); - } - else - { - /* Just go to the next one */ - ++iter; - } + iter = this->options.erase(iter); + } + else + { + /* Just go to the next one */ + ++iter; } } return this->options.empty(); } - -void complete_remove(const wchar_t *cmd, - bool cmd_is_path, - wchar_t short_opt, - const wchar_t *long_opt, - int old_mode) +void completion_entry_t::remove_all_options() +{ + ASSERT_IS_LOCKED(completion_lock); + this->options.clear(); +} + + +void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &option, complete_option_type_t type) { - CHECK(cmd,); scoped_lock lock(completion_lock); completion_entry_t tmp_entry(cmd, cmd_is_path, false); @@ -622,7 +595,7 @@ void complete_remove(const wchar_t *cmd, if (iter != completion_set.end()) { completion_entry_t *entry = *iter; - bool delete_it = entry->remove_option(short_opt, long_opt, old_mode); + bool delete_it = entry->remove_option(option, type); if (delete_it) { /* Delete this entry */ @@ -632,6 +605,22 @@ void complete_remove(const wchar_t *cmd, } } +void complete_remove_all(const wcstring &cmd, bool cmd_is_path) +{ + scoped_lock lock(completion_lock); + + completion_entry_t tmp_entry(cmd, cmd_is_path, false); + completion_entry_set_t::iterator iter = completion_set.find(&tmp_entry); + if (iter != completion_set.end()) + { + completion_entry_t *entry = *iter; + entry->remove_all_options(); + completion_set.erase(iter); + delete entry; + } +} + + /** Find the full path and commandname from a command string 'str'. */ diff --git a/src/complete.h b/src/complete.h index 38b56bc0e..4972981f3 100644 --- a/src/complete.h +++ b/src/complete.h @@ -205,12 +205,13 @@ void complete_set_authoritative(const wchar_t *cmd, bool cmd_type, bool authorit /** Remove a previously defined completion */ -void complete_remove(const wchar_t *cmd, +void complete_remove(const wcstring &cmd, bool cmd_is_path, - wchar_t short_opt, - const wchar_t *long_opt, - int long_mode); + const wcstring &option, + complete_option_type_t type); +/** Removes all completions for a given command */ +void complete_remove_all(const wcstring &cmd, bool cmd_is_path); /** Find all completions of the command cmd, insert them into out. */