mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 12:23:09 +00:00
Don't erase old-style options with complete -l foo -e
When erasing long option completions, distinguish between gnu-style and old-style options, just like we do when adding and printing completions.
This commit is contained in:
parent
aa7fe3b132
commit
edd4f3d5ad
3 changed files with 22 additions and 13 deletions
|
@ -173,14 +173,16 @@ static void builtin_complete_add(const wcstring_list_t &cmd,
|
|||
static void builtin_complete_remove3(const wchar_t *cmd,
|
||||
int cmd_type,
|
||||
wchar_t short_opt,
|
||||
const wcstring_list_t &long_opt)
|
||||
const wcstring_list_t &long_opt,
|
||||
int long_mode)
|
||||
{
|
||||
for (size_t i=0; i<long_opt.size(); i++)
|
||||
{
|
||||
complete_remove(cmd,
|
||||
cmd_type,
|
||||
short_opt,
|
||||
long_opt.at(i).c_str());
|
||||
long_opt.at(i).c_str(),
|
||||
long_mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,6 +205,7 @@ static void builtin_complete_remove2(const wchar_t *cmd,
|
|||
complete_remove(cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
0,
|
||||
0);
|
||||
|
||||
}
|
||||
|
@ -211,11 +214,13 @@ static void builtin_complete_remove2(const wchar_t *cmd,
|
|||
builtin_complete_remove3(cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
gnu_opt);
|
||||
gnu_opt,
|
||||
0);
|
||||
builtin_complete_remove3(cmd,
|
||||
cmd_type,
|
||||
*s,
|
||||
old_opt);
|
||||
old_opt,
|
||||
1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,11 +229,13 @@ static void builtin_complete_remove2(const wchar_t *cmd,
|
|||
builtin_complete_remove3(cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
gnu_opt);
|
||||
gnu_opt,
|
||||
0);
|
||||
builtin_complete_remove3(cmd,
|
||||
cmd_type,
|
||||
0,
|
||||
old_opt);
|
||||
old_opt,
|
||||
1);
|
||||
|
||||
}
|
||||
|
||||
|
|
13
complete.cpp
13
complete.cpp
|
@ -200,7 +200,7 @@ public:
|
|||
|
||||
/** Adds or removes an option. */
|
||||
void add_option(const complete_entry_opt_t &opt);
|
||||
bool remove_option(wchar_t short_opt, const wchar_t *long_opt);
|
||||
bool remove_option(wchar_t short_opt, const wchar_t *long_opt, int old_mode);
|
||||
|
||||
/** Getter for short_opt_str. */
|
||||
wcstring &get_short_opt_str();
|
||||
|
@ -464,7 +464,7 @@ completion_autoload_t::completion_autoload_t() : autoload_t(L"fish_complete_path
|
|||
/** Callback when an autoloaded completion is removed */
|
||||
void completion_autoload_t::command_removed(const wcstring &cmd)
|
||||
{
|
||||
complete_remove(cmd.c_str(), COMMAND, 0, 0);
|
||||
complete_remove(cmd.c_str(), COMMAND, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -617,7 +617,7 @@ void complete_add(const wchar_t *cmd,
|
|||
specified short / long option strings. Returns true if it is now
|
||||
empty and should be deleted, false if it's not empty. Must be called while locked.
|
||||
*/
|
||||
bool completion_entry_t::remove_option(wchar_t short_opt, const wchar_t *long_opt)
|
||||
bool completion_entry_t::remove_option(wchar_t short_opt, const wchar_t *long_opt, int old_mode)
|
||||
{
|
||||
ASSERT_IS_LOCKED(completion_lock);
|
||||
ASSERT_IS_LOCKED(completion_entry_lock);
|
||||
|
@ -631,7 +631,7 @@ bool completion_entry_t::remove_option(wchar_t short_opt, const wchar_t *long_op
|
|||
{
|
||||
complete_entry_opt_t &o = *iter;
|
||||
if ((short_opt && short_opt == o.short_opt) ||
|
||||
(long_opt && long_opt == o.long_opt))
|
||||
(long_opt && long_opt == o.long_opt && old_mode == o.old_mode))
|
||||
{
|
||||
/* fwprintf( stderr,
|
||||
L"remove option -%lc --%ls\n",
|
||||
|
@ -669,7 +669,8 @@ bool completion_entry_t::remove_option(wchar_t short_opt, const wchar_t *long_op
|
|||
void complete_remove(const wchar_t *cmd,
|
||||
bool cmd_is_path,
|
||||
wchar_t short_opt,
|
||||
const wchar_t *long_opt)
|
||||
const wchar_t *long_opt,
|
||||
int old_mode)
|
||||
{
|
||||
CHECK(cmd,);
|
||||
scoped_lock lock(completion_lock);
|
||||
|
@ -680,7 +681,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);
|
||||
bool delete_it = entry->remove_option(short_opt, long_opt, old_mode);
|
||||
if (delete_it)
|
||||
{
|
||||
/* Delete this entry */
|
||||
|
|
|
@ -207,7 +207,8 @@ void complete_set_authoritative(const wchar_t *cmd, bool cmd_type, bool authorit
|
|||
void complete_remove(const wchar_t *cmd,
|
||||
bool cmd_is_path,
|
||||
wchar_t short_opt,
|
||||
const wchar_t *long_opt);
|
||||
const wchar_t *long_opt,
|
||||
int long_mode);
|
||||
|
||||
|
||||
/** Find all completions of the command cmd, insert them into out.
|
||||
|
|
Loading…
Reference in a new issue