diff --git a/builtin_complete.c b/builtin_complete.c index 517751150..9912e2f1f 100644 --- a/builtin_complete.c +++ b/builtin_complete.c @@ -48,7 +48,6 @@ static void builtin_complete_add2( const wchar_t *cmd, array_list_t *gnu_opt, array_list_t *old_opt, int result_mode, - int authorative, const wchar_t *condition, const wchar_t *comp, const wchar_t *desc ) @@ -64,7 +63,6 @@ static void builtin_complete_add2( const wchar_t *cmd, 0, 0, result_mode, - authorative, condition, comp, desc ); @@ -78,7 +76,6 @@ static void builtin_complete_add2( const wchar_t *cmd, (wchar_t *)al_get(gnu_opt, i ), 0, result_mode, - authorative, condition, comp, desc ); @@ -92,7 +89,6 @@ static void builtin_complete_add2( const wchar_t *cmd, (wchar_t *)al_get(old_opt, i ), 1, result_mode, - authorative, condition, comp, desc ); @@ -106,7 +102,6 @@ static void builtin_complete_add2( const wchar_t *cmd, 0, 0, result_mode, - authorative, condition, comp, desc ); @@ -128,72 +123,47 @@ static void builtin_complete_add( array_list_t *cmd, const wchar_t *desc ) { int i; - int has_content =( wcslen( short_opt ) || - al_get_count( gnu_opt ) || - al_get_count( old_opt ) || - comp ); for( i=0; ishort_opt_str = wcsdup(L""); } + return c; +} + + +void complete_set_authorative( const wchar_t *cmd, + int cmd_type, + int authorative ) +{ + complete_entry_t *c; + + CHECK( cmd, ); + c = complete_get_exact_entry( cmd, cmd_type ); c->authorative = authorative; +} - if( short_opt != L'\0' || long_opt ) + +void complete_add( const wchar_t *cmd, + int cmd_type, + wchar_t short_opt, + const wchar_t *long_opt, + int old_mode, + int result_mode, + const wchar_t *condition, + const wchar_t *comp, + const wchar_t *desc ) +{ + complete_entry_t *c; + complete_entry_opt_t *opt; + + CHECK( cmd, ); + + c = complete_get_exact_entry( cmd, cmd_type ); + + opt = halloc( 0, sizeof( complete_entry_opt_t ) ); + + opt->next = c->first_option; + c->first_option = opt; + if( short_opt != L'\0' ) { - - opt = halloc( 0, sizeof( complete_entry_opt_t ) ); - - opt->next = c->first_option; - c->first_option = opt; - if( short_opt != L'\0' ) + int len = 1 + ((result_mode & NO_COMMON) != 0); + c->short_opt_str = + realloc( c->short_opt_str, + sizeof(wchar_t)*(wcslen( c->short_opt_str ) + 1 + len) ); + wcsncat( c->short_opt_str, + &short_opt, 1 ); + if( len == 2 ) { - int len = 1 + ((result_mode & NO_COMMON) != 0); - c->short_opt_str = - realloc( c->short_opt_str, - sizeof(wchar_t)*(wcslen( c->short_opt_str ) + 1 + len) ); - wcsncat( c->short_opt_str, - &short_opt, 1 ); - if( len == 2 ) - { - wcscat( c->short_opt_str, L":" ); - } + wcscat( c->short_opt_str, L":" ); } + } - opt->short_opt = short_opt; - opt->result_mode = result_mode; - opt->old_mode=old_mode; + opt->short_opt = short_opt; + opt->result_mode = result_mode; + opt->old_mode=old_mode; - opt->comp = comp?halloc_wcsdup(opt, comp):L""; - opt->condition = condition?halloc_wcsdup(opt, condition):L""; - opt->long_opt = long_opt?halloc_wcsdup(opt, long_opt):L"" ; + opt->comp = comp?halloc_wcsdup(opt, comp):L""; + opt->condition = condition?halloc_wcsdup(opt, condition):L""; + opt->long_opt = long_opt?halloc_wcsdup(opt, long_opt):L"" ; - if( desc && wcslen( desc ) ) - { - opt->desc = halloc_wcsdup( opt, desc ); - } - else - { - opt->desc = L""; - } - + if( desc && wcslen( desc ) ) + { + opt->desc = halloc_wcsdup( opt, desc ); + } + else + { + opt->desc = L""; } } diff --git a/complete.h b/complete.h index 9461cfc76..e04d0e5ff 100644 --- a/complete.h +++ b/complete.h @@ -105,7 +105,6 @@ file completion is not performed. \param comp A space separated list of completions which may contain subshells. \param desc A description of the completion. - \param authorative Whether there list of completions for this command is complete. If true, any options not matching one of the provided options will be flagged as an error by syntax highlighting. \param condition a command to be run to check it this completion should be used. If \c condition is empty, the completion is always used. */ @@ -115,10 +114,17 @@ void complete_add( const wchar_t *cmd, const wchar_t *long_opt, int long_mode, int result_mode, - int authorative, const wchar_t *condition, const wchar_t *comp, const wchar_t *desc ); +/** + Sets whether the completion list for this command is complete. If + true, any options not matching one of the provided options will be + flagged as an error by syntax highlighting. +*/ +void complete_set_authorative( const wchar_t *cmd, + int cmd_type, + int authorative ); /** Remove a previously defined completion diff --git a/doc_src/complete.txt b/doc_src/complete.txt index ab1b326be..20a0ad34a 100644 --- a/doc_src/complete.txt +++ b/doc_src/complete.txt @@ -22,6 +22,7 @@ the fish manual. - -p or --path implies that the string COMMAND is the full path of the command - -r or --require-parameter specifies that the option specified by this completion always must have an option argument, i.e. may not be followed by another option - -u or --unauthorative implies that there may be more options than the ones specified, and that fish should not assume that options not listed are spelling errors +- -A or --authorative implies that there may be no more options than the ones specified, and that fish should assume that options not listed are spelling errors - -x or --exclusive implies both -r and -f Command specific tab-completions in \c fish are based on the notion