diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2006-11-29 08:28:26 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2006-11-29 08:28:26 +0000 |
commit | 59a0d276688714f5e4801e55e822191da1ac4a1c (patch) | |
tree | 6b2df2634f80c41de1ceb55ce04b6e818a9b014b /src | |
parent | f1dbe04c20a53a3718084cacfc5c519f60e16ee1 (diff) | |
download | weechat-59a0d276688714f5e4801e55e822191da1ac4a1c.zip |
Added auto completion with channels and filenames
Diffstat (limited to 'src')
-rw-r--r-- | src/common/completion.c | 74 | ||||
-rw-r--r-- | src/common/completion.h | 1 |
2 files changed, 47 insertions, 28 deletions
diff --git a/src/common/completion.c b/src/common/completion.c index c995f6ef6..e5298b0ab 100644 --- a/src/common/completion.c +++ b/src/common/completion.c @@ -1000,12 +1000,7 @@ completion_find_context (t_completion *completion, char *buffer, int size, int p } } else - { - if (completion->channel) - completion->context = COMPLETION_NICK; - else - completion->context = COMPLETION_NULL; - } + completion->context = COMPLETION_AUTO; /* look for word to complete (base word) */ completion->base_word_pos = 0; @@ -1078,29 +1073,14 @@ completion_find_context (t_completion *completion, char *buffer, int size, int p } } - /* nick completion with nothing as base word is disabled, + /* auto completion with nothing as base word is disabled, in order to prevent completion when pasting messages with [tab] inside */ - if ((completion->context == COMPLETION_NICK) + if ((completion->context == COMPLETION_AUTO) && ((!completion->base_word) || (!completion->base_word[0]))) { completion->context = COMPLETION_NULL; return; } - - if (!completion->completion_list && completion->channel && - ((((t_irc_channel *)(completion->channel))->type == CHANNEL_TYPE_PRIVATE) - || (((t_irc_channel *)(completion->channel))->type == CHANNEL_TYPE_DCC_CHAT)) - && (completion->context == COMPLETION_NICK)) - { - /* nick completion in private (only other nick and self) */ - completion->context = COMPLETION_NICK; - weelist_add (&completion->completion_list, - &completion->last_completion, - ((t_irc_channel *)(completion->channel))->name); - weelist_add (&completion->completion_list, - &completion->last_completion, - ((t_irc_server *)(completion->server))->nick); - } } /* @@ -1323,6 +1303,8 @@ completion_nick (t_completion *completion) if (!completion->channel) return; + completion->context = COMPLETION_NICK; + if ((((t_irc_channel *)(completion->channel))->type == CHANNEL_TYPE_PRIVATE) || (((t_irc_channel *)(completion->channel))->type == CHANNEL_TYPE_DCC_CHAT)) { @@ -1407,6 +1389,39 @@ completion_nick (t_completion *completion) } /* + * completion_auto: auto complete: nick, filename or channel + */ + +void +completion_auto (t_completion *completion) +{ + /* filename completion */ + if ((completion->base_word[0] == '/') + || (completion->base_word[0] == '~')) + { + if (!completion->completion_list) + completion_list_add_filename (completion); + completion_command_arg (completion, 0); + return; + } + + /* channel completion */ + if (string_is_channel (completion->base_word)) + { + if (!completion->completion_list) + completion_list_add_server_channels (completion); + completion_command_arg (completion, 0); + return; + } + + /* default: nick completion (if channel) */ + if (completion->channel) + completion_nick (completion); + else + completion->context = COMPLETION_NULL; +} + +/* * completion_search: complete word according to context */ @@ -1433,10 +1448,7 @@ completion_search (t_completion *completion, int direction, /* should never be executed */ return; case COMPLETION_NICK: - if (completion->channel) - completion_nick (completion); - else - return; + completion_nick (completion); break; case COMPLETION_COMMAND: completion_command (completion); @@ -1445,7 +1457,13 @@ completion_search (t_completion *completion, int direction, if (completion->completion_list) completion_command_arg (completion, completion->arg_is_nick); else - completion_nick (completion); + { + completion->context = COMPLETION_AUTO; + completion_auto (completion); + } + break; + case COMPLETION_AUTO: + completion_auto (completion); break; } if (completion->word_found) diff --git a/src/common/completion.h b/src/common/completion.h index b6e4e735e..18f91f8af 100644 --- a/src/common/completion.h +++ b/src/common/completion.h @@ -27,6 +27,7 @@ #define COMPLETION_NICK 1 #define COMPLETION_COMMAND 2 #define COMPLETION_COMMAND_ARG 3 +#define COMPLETION_AUTO 4 typedef struct t_completion t_completion; |