mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 21:03:12 +00:00
More stylefixes
This commit is contained in:
parent
eb7601d116
commit
2e33633698
2 changed files with 77 additions and 63 deletions
53
complete.cpp
53
complete.cpp
|
@ -227,7 +227,11 @@ static bool compare_completions_by_order(const completion_entry_t *p1, const com
|
||||||
/** The lock that guards the list of completion entries */
|
/** The lock that guards the list of completion entries */
|
||||||
static pthread_mutex_t completion_lock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t completion_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
/** The lock that guards the options list of individual completion entries. If both completion_lock and completion_entry_lock are to be taken, completion_lock must be taken first. */
|
/**
|
||||||
|
* The lock that guards the options list of individual completion entries.
|
||||||
|
* If both completion_lock and completion_entry_lock are to be taken,
|
||||||
|
* completion_lock must be taken first.
|
||||||
|
*/
|
||||||
static pthread_mutex_t completion_entry_lock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t completion_entry_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
|
||||||
|
@ -488,38 +492,37 @@ void complete_set_authoritative( const wchar_t *cmd, bool cmd_is_path, bool auth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void complete_add( const wchar_t *cmd,
|
void complete_add(const wchar_t *cmd,
|
||||||
bool cmd_is_path,
|
bool cmd_is_path,
|
||||||
wchar_t short_opt,
|
wchar_t short_opt,
|
||||||
const wchar_t *long_opt,
|
const wchar_t *long_opt,
|
||||||
int old_mode,
|
int old_mode,
|
||||||
int result_mode,
|
int result_mode,
|
||||||
const wchar_t *condition,
|
const wchar_t *condition,
|
||||||
const wchar_t *comp,
|
const wchar_t *comp,
|
||||||
const wchar_t *desc,
|
const wchar_t *desc,
|
||||||
complete_flags_t flags )
|
complete_flags_t flags) {
|
||||||
{
|
|
||||||
CHECK( cmd, );
|
CHECK( cmd, );
|
||||||
|
|
||||||
/* Lock the lock that allows us to edit the completion entry list */
|
/* Lock the lock that allows us to edit the completion entry list */
|
||||||
scoped_lock lock(completion_lock);
|
scoped_lock lock(completion_lock);
|
||||||
|
|
||||||
/* Lock the lock that allows us to edit individual completion entries */
|
/* Lock the lock that allows us to edit individual completion entries */
|
||||||
scoped_lock lock2(completion_entry_lock);
|
scoped_lock lock2(completion_entry_lock);
|
||||||
|
|
||||||
completion_entry_t *c;
|
completion_entry_t *c;
|
||||||
c = complete_get_exact_entry( cmd, cmd_is_path );
|
c = complete_get_exact_entry( cmd, cmd_is_path );
|
||||||
|
|
||||||
/* Create our new option */
|
/* Create our new option */
|
||||||
complete_entry_opt_t opt;
|
complete_entry_opt_t opt;
|
||||||
if( short_opt != L'\0' )
|
if( short_opt != L'\0' )
|
||||||
{
|
{
|
||||||
int len = 1 + ((result_mode & NO_COMMON) != 0);
|
int len = 1 + ((result_mode & NO_COMMON) != 0);
|
||||||
|
|
||||||
c->get_short_opt_str().push_back(short_opt);
|
c->get_short_opt_str().push_back(short_opt);
|
||||||
if( len == 2 )
|
if( len == 2 )
|
||||||
{
|
{
|
||||||
c->get_short_opt_str().push_back(L':');
|
c->get_short_opt_str().push_back(L':');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,13 +530,13 @@ void complete_add( const wchar_t *cmd,
|
||||||
opt.result_mode = result_mode;
|
opt.result_mode = result_mode;
|
||||||
opt.old_mode=old_mode;
|
opt.old_mode=old_mode;
|
||||||
|
|
||||||
if (comp) opt.comp = comp;
|
if (comp) opt.comp = comp;
|
||||||
if (condition) opt.condition = condition;
|
if (condition) opt.condition = condition;
|
||||||
if (long_opt) opt.long_opt = long_opt;
|
if (long_opt) opt.long_opt = long_opt;
|
||||||
if (desc) opt.desc = desc;
|
if (desc) opt.desc = desc;
|
||||||
opt.flags = flags;
|
opt.flags = flags;
|
||||||
|
|
||||||
c->add_option(opt);
|
c->add_option(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
87
complete.h
87
complete.h
|
@ -18,53 +18,53 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
/**
|
/**
|
||||||
Use all completions
|
* Use all completions
|
||||||
*/
|
*/
|
||||||
#define SHARED 0
|
#define SHARED 0
|
||||||
/**
|
/**
|
||||||
Do not use file completion
|
* Do not use file completion
|
||||||
*/
|
*/
|
||||||
#define NO_FILES 1
|
#define NO_FILES 1
|
||||||
/**
|
/**
|
||||||
Require a parameter after completion
|
* Require a parameter after completion
|
||||||
*/
|
*/
|
||||||
#define NO_COMMON 2
|
#define NO_COMMON 2
|
||||||
/**
|
/**
|
||||||
Only use the argument list specifies with completion after
|
* Only use the argument list specifies with completion after
|
||||||
option. This is the same as (NO_FILES & NO_COMMON)
|
* option. This is the same as (NO_FILES & NO_COMMON)
|
||||||
*/
|
*/
|
||||||
#define EXCLUSIVE 3
|
#define EXCLUSIVE 3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Command is a path
|
* Command is a path
|
||||||
*/
|
*/
|
||||||
#define PATH 1
|
#define PATH 1
|
||||||
/**
|
/**
|
||||||
Command is not a path
|
* Command is not a path
|
||||||
*/
|
*/
|
||||||
#define COMMAND 0
|
#define COMMAND 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Separator between completion and description
|
* Separator between completion and description
|
||||||
*/
|
*/
|
||||||
#define COMPLETE_SEP L'\004'
|
#define COMPLETE_SEP L'\004'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Separator between completion and description
|
* Separator between completion and description
|
||||||
*/
|
*/
|
||||||
#define COMPLETE_SEP_STR L"\004"
|
#define COMPLETE_SEP_STR L"\004"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Separator between completion items in fish_pager. This is used for
|
* Separator between completion items in fish_pager. This is used for
|
||||||
completion grouping, e.g. when putting completions with the same
|
* completion grouping, e.g. when putting completions with the same
|
||||||
descriptions on the same line.
|
* descriptions on the same line.
|
||||||
*/
|
*/
|
||||||
#define COMPLETE_ITEM_SEP L'\uf500'
|
#define COMPLETE_ITEM_SEP L'\uf500'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Character that separates the completion and description on
|
* Character that separates the completion and description on
|
||||||
programmable completions
|
* programmable completions
|
||||||
*/
|
*/
|
||||||
#define PROG_COMPLETE_SEP L'\t'
|
#define PROG_COMPLETE_SEP L'\t'
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -183,21 +183,24 @@ void sort_completions( std::vector<completion_t> &completions);
|
||||||
|
|
||||||
\param cmd Command to complete.
|
\param cmd Command to complete.
|
||||||
\param cmd_type If cmd_type is PATH, cmd will be interpreted as the absolute
|
\param cmd_type If cmd_type is PATH, cmd will be interpreted as the absolute
|
||||||
path of the program (optionally containing wildcards), otherwise it
|
path of the program (optionally containing wildcards), otherwise it
|
||||||
will be interpreted as the command name.
|
will be interpreted as the command name.
|
||||||
\param short_opt The single character name of an option. (-a is a short option, --all and -funroll are long options)
|
\param short_opt The single character name of an option. (-a is a short option,
|
||||||
\param long_opt The multi character name of an option. (-a is a short option, --all and -funroll are long options)
|
--all and -funroll are long options)
|
||||||
|
\param long_opt The multi character name of an option. (-a is a short option,
|
||||||
|
--all and -funroll are long options)
|
||||||
\param long_mode Whether to use old style, single dash long options.
|
\param long_mode Whether to use old style, single dash long options.
|
||||||
\param result_mode Whether to search further completions when this
|
\param result_mode Whether to search further completions when this
|
||||||
completion has been succesfully matched. If result_mode is SHARED,
|
completion has been succesfully matched. If result_mode is SHARED,
|
||||||
any other completions may also be used. If result_mode is NO_FILES,
|
any other completions may also be used. If result_mode is NO_FILES,
|
||||||
file completion should not be used, but other completions may be
|
file completion should not be used, but other completions may be
|
||||||
used. If result_mode is NO_COMMON, on option may follow it - only a
|
used. If result_mode is NO_COMMON, on option may follow it - only a
|
||||||
parameter. If result_mode is EXCLUSIVE, no option may follow it, and
|
parameter. If result_mode is EXCLUSIVE, no option may follow it, and
|
||||||
file completion is not performed.
|
file completion is not performed.
|
||||||
\param comp A space separated list of completions which may contain subshells.
|
\param comp A space separated list of completions which may contain subshells.
|
||||||
\param desc A description of the completion.
|
\param desc A description of the completion.
|
||||||
\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.
|
\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.
|
||||||
\param flags A set of completion flags
|
\param flags A set of completion flags
|
||||||
*/
|
*/
|
||||||
void complete_add( const wchar_t *cmd,
|
void complete_add( const wchar_t *cmd,
|
||||||
|
@ -226,8 +229,14 @@ void complete_remove( const wchar_t *cmd,
|
||||||
const wchar_t *long_opt );
|
const wchar_t *long_opt );
|
||||||
|
|
||||||
|
|
||||||
/** Find all completions of the command cmd, insert them into out. If to_load is not NULL, append all commands that we would autoload, but did not (presumably because this is not the main thread) */
|
/** Find all completions of the command cmd, insert them into out. If to_load is
|
||||||
void complete( const wcstring &cmd, std::vector<completion_t> &comp, complete_type_t type, wcstring_list_t *to_load = NULL );
|
* not NULL, append all commands that we would autoload, but did not (presumably
|
||||||
|
* because this is not the main thread)
|
||||||
|
*/
|
||||||
|
void complete(const wcstring &cmd,
|
||||||
|
std::vector<completion_t> &comp,
|
||||||
|
complete_type_t type,
|
||||||
|
wcstring_list_t *to_load = NULL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Print a list of all current completions into the string.
|
Print a list of all current completions into the string.
|
||||||
|
@ -260,7 +269,9 @@ bool complete_is_valid_argument( const wcstring &str,
|
||||||
with internal dependencies.
|
with internal dependencies.
|
||||||
|
|
||||||
\param cmd the command for which to load command-specific completions
|
\param cmd the command for which to load command-specific completions
|
||||||
\param reload should the commands completions be reloaded, even if they where previously loaded. (This is set to true on actual completions, so that changed completion are updated in running shells)
|
\param reload should the commands completions be reloaded, even if they where
|
||||||
|
previously loaded. (This is set to true on actual completions, so that
|
||||||
|
changed completion are updated in running shells)
|
||||||
*/
|
*/
|
||||||
void complete_load( const wcstring &cmd, bool reload );
|
void complete_load( const wcstring &cmd, bool reload );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue