1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 03:03:12 +02:00

Nick completion enabled again, plugins can now override default nick completion (IRC plugin uses that feature)

This commit is contained in:
Sebastien Helleu
2008-01-30 17:38:09 +01:00
parent adab75c345
commit b52690d119
6 changed files with 100 additions and 112 deletions
+1 -1
View File
@@ -427,7 +427,7 @@ gui_buffer_search_by_category_name (char *category, char *name)
struct t_gui_buffer *ptr_buffer;
if (!category && !name)
return NULL;
return gui_current_window->buffer;
for (ptr_buffer = gui_buffers; ptr_buffer;
ptr_buffer = ptr_buffer->next_buffer)
+72 -89
View File
@@ -43,6 +43,7 @@
#include "gui-buffer.h"
#include "gui-color.h"
#include "gui-keyboard.h"
#include "gui-nicklist.h"
/*
@@ -440,6 +441,49 @@ gui_completion_list_add_self_nick (struct t_gui_completion *completion)
0, WEECHAT_LIST_POS_SORT);
}
/*
* gui_completion_list_add_nicks: add nicks to completion list
*/
void
gui_completion_list_add_nicks (struct t_gui_completion *completion)
{
struct t_gui_nick_group *ptr_group;
struct t_gui_nick *ptr_nick;
int count_before;
count_before = weelist_size (completion->completion_list);
hook_completion_exec (completion->buffer->plugin,
"nick",
completion->buffer,
completion->completion_list);
if (weelist_size (completion->completion_list) == count_before)
{
/* no plugin overrides nick completion, then we use default nick */
/* completion, wich nicks of nicklist, in order of nicklist */
if (completion->buffer->nicklist)
{
ptr_group = NULL;
ptr_nick = NULL;
gui_nicklist_get_next_item (completion->buffer,
&ptr_group, &ptr_nick);
while (ptr_group || ptr_nick)
{
if (ptr_nick && ptr_nick->visible)
{
gui_completion_list_add (completion,
ptr_nick->name,
1, WEECHAT_LIST_POS_END);
}
gui_nicklist_get_next_item (completion->buffer,
&ptr_group, &ptr_nick);
}
}
}
completion->arg_is_nick = 1;
}
/*
* gui_completion_list_add_option: add config option to completion list
*/
@@ -702,6 +746,9 @@ gui_completion_build_list_template (struct t_gui_completion *completion,
case 'm': /* self nickname */
gui_completion_list_add_self_nick (completion);
break;
case 'n': /* nick */
gui_completion_list_add_nicks (completion);
break;
case 'o': /* config option */
gui_completion_list_add_option (completion);
break;
@@ -1036,7 +1083,8 @@ gui_completion_command (struct t_gui_completion *completion)
*/
void
gui_completion_command_arg (struct t_gui_completion *completion, int nick_completion)
gui_completion_command_arg (struct t_gui_completion *completion,
int nick_completion)
{
int length, word_found_seen, other_completion;
struct t_weelist_item *ptr_item, *ptr_item2;
@@ -1051,8 +1099,12 @@ gui_completion_command_arg (struct t_gui_completion *completion, int nick_comple
while (ptr_item)
{
if ((nick_completion && (gui_completion_nickncmp (completion->base_word, ptr_item->data, length) == 0))
|| ((!nick_completion) && (string_strncasecmp (completion->base_word, ptr_item->data, length) == 0)))
if ((nick_completion
&& (gui_completion_nickncmp (completion->base_word, ptr_item->data,
length) == 0))
|| ((!nick_completion)
&& (string_strncasecmp (completion->base_word, ptr_item->data,
length) == 0)))
{
if ((!completion->word_found) || word_found_seen)
{
@@ -1068,9 +1120,13 @@ gui_completion_command_arg (struct t_gui_completion *completion, int nick_comple
while (ptr_item2)
{
if ((nick_completion
&& (gui_completion_nickncmp (completion->base_word, ptr_item2->data, length) == 0))
&& (gui_completion_nickncmp (completion->base_word,
ptr_item2->data,
length) == 0))
|| ((!nick_completion)
&& (string_strncasecmp (completion->base_word, ptr_item2->data, length) == 0)))
&& (string_strncasecmp (completion->base_word,
ptr_item2->data,
length) == 0)))
other_completion++;
if (completion->direction < 0)
@@ -1112,76 +1168,14 @@ gui_completion_command_arg (struct t_gui_completion *completion, int nick_comple
void
gui_completion_nick (struct t_gui_completion *completion)
{
(void) completion;
/*int length, word_found_seen, other_completion;
t_irc_nick *ptr_nick;
int length, word_found_seen, other_completion;
struct t_weelist_item *ptr_item, *ptr_item2;
if (!completion->channel)
return;
if (!completion->completion_list->items)
gui_completion_list_add_nicks (completion);
completion->context = GUI_COMPLETION_NICK;
if ((((t_irc_channel *)(completion->channel))->type == IRC_CHANNEL_TYPE_PRIVATE)
|| (((t_irc_channel *)(completion->channel))->type == IRC_CHANNEL_TYPE_DCC_CHAT))
{
if (!(completion->completion_list->items))
{
weelist_add (completion->completion_list,
((t_irc_channel *)(completion->channel))->name,
WEECHAT_LIST_POS_SORT);
weelist_add (completion->completion_list,
((t_irc_server *)(completion->server))->nick,
WEECHAT_LIST_POS_SORT);
}
gui_completion_command_arg (completion, 1);
return;
}
// rebuild nick list for completion, with nicks speaking at beginning of list
if ((((t_irc_channel *)(completion->channel))->nick_completion_reset)
|| (!(completion->completion_list->items)))
{
// empty completion list
if (completion->completion_list)
{
weelist_free (completion->completion_list);
completion->completion_list = NULL;
completion->last_completion = NULL;
}
// add channel nicks
for (ptr_nick = ((t_irc_channel *)(completion->channel))->nicks;
ptr_nick; ptr_nick = ptr_nick->next_nick)
{
weelist_add (completion->completion_list,
ptr_nick->nick,
WEECHAT_LIST_POS_SORT);
}
// add nicks speaking recently on this channel
if (CONFIG_BOOLEAN(config_look_nick_completion_smart))
{
for (ptr_item = ((t_irc_channel *)(completion->channel))->nicks_speaking->items;
ptr_item; ptr_item = ptr_item->next_item)
{
if (irc_nick_search ((t_irc_channel *)(completion->channel),
ptr_item->data))
weelist_add (completion->completion_list,
ptr_item->data,
WEECHAT_LIST_POS_BEGINNING);
}
}
// add self nick at the end
if (completion->server)
weelist_add (completion->completion_list,
((t_irc_server *)(completion->server))->nick,
WEECHAT_LIST_POS_END);
((t_irc_channel *)(completion->channel))->nick_completion_reset = 0;
}
length = strlen (completion->base_word);
word_found_seen = 0;
other_completion = 0;
@@ -1193,7 +1187,8 @@ gui_completion_nick (struct t_gui_completion *completion)
while (ptr_item)
{
if (gui_completion_nickncmp (completion->base_word, ptr_item->data, length) == 0)
if (gui_completion_nickncmp (completion->base_word, ptr_item->data,
length) == 0)
{
if ((!completion->word_found) || word_found_seen)
{
@@ -1205,7 +1200,7 @@ gui_completion_nick (struct t_gui_completion *completion)
completion->position = -1;
return;
}
if (completion->direction < 0)
ptr_item2 = ptr_item->prev_item;
else
@@ -1249,7 +1244,7 @@ gui_completion_nick (struct t_gui_completion *completion)
free (completion->word_found);
completion->word_found = NULL;
gui_completion_nick (completion);
}*/
}
}
/*
@@ -1259,9 +1254,7 @@ gui_completion_nick (struct t_gui_completion *completion)
void
gui_completion_auto (struct t_gui_completion *completion)
{
(void) completion;
/*
// filename completion
/* filename completion */
if ((completion->base_word[0] == '/')
|| (completion->base_word[0] == '~'))
{
@@ -1271,21 +1264,11 @@ gui_completion_auto (struct t_gui_completion *completion)
return;
}
// channel completion
if (irc_channel_is_channel (completion->base_word))
{
if (!completion->completion_list->items)
gui_completion_list_add_channels (completion);
gui_completion_command_arg (completion, 0);
return;
}
// default: nick completion (if channel)
if (completion->channel)
/* default: nick completion (if there's a nicklist) */
if (completion->buffer->nicklist)
gui_completion_nick (completion);
else
completion->context = GUI_COMPLETION_NULL;
*/
}
/*
+10 -10
View File
@@ -3590,7 +3590,7 @@ irc_command_init ()
" type: CTCP type (examples: \"version\", "
"\"ping\", ..)\n"
"arguments: arguments for CTCP"),
"%(irc_channel)|%(irc_channel_nicks) action|ping|version",
"%(irc_channel)|%n action|ping|version",
&irc_command_ctcp, NULL);
weechat_hook_command ("cycle",
N_("leave and rejoin a channel"),
@@ -3606,7 +3606,7 @@ irc_command_init ()
"(chat)\n"
"nickname: nickname to send file or chat\n"
" file: filename (on local host)"),
"chat|send|close %(irc_channel_nicks) %f",
"chat|send|close %n %f",
&irc_command_dcc, NULL);
weechat_hook_command ("dehalfop",
N_("removes half channel operator status from "
@@ -3652,7 +3652,7 @@ irc_command_init ()
N_("nickname channel"),
N_("nickname: nick to invite\n"
" channel: channel to invite"),
"%(irc_channel_nicks) %(irc_channel)", &irc_command_invite, NULL);
"%n %(irc_channel)", &irc_command_invite, NULL);
weechat_hook_command ("ison",
N_("check if a nickname is currently on IRC"),
N_("nickname [nickname ...]"),
@@ -3670,20 +3670,20 @@ irc_command_init ()
N_(" channel: channel where user is\n"
"nickname: nickname to kick\n"
" comment: comment for kick"),
"%(irc_channel_nicks) %-", &irc_command_kick, NULL);
"%n %-", &irc_command_kick, NULL);
weechat_hook_command ("kickban",
N_("kicks and bans a nick from a channel"),
N_("[channel] nickname [comment]"),
N_(" channel: channel where user is\n"
"nickname: nickname to kick and ban\n"
" comment: comment for kick"),
"%(irc_channel_nicks) %-", &irc_command_kickban, NULL);
"%n %-", &irc_command_kickban, NULL);
weechat_hook_command ("kill",
N_("close client-server connection"),
N_("nickname comment"),
N_("nickname: nickname\n"
" comment: comment for kill"),
"%(irc_channel_nicks) %-", &irc_command_kill, NULL);
"%n %-", &irc_command_kill, NULL);
weechat_hook_command ("links",
N_("list all servernames which are known by the "
"server answering the query"),
@@ -3769,7 +3769,7 @@ irc_command_init ()
N_("nickname text"),
N_("nickname: user to send notice to\n"
" text: text to send"),
"%(irc_channel_nicks) %-", &irc_command_notice, NULL);
"%n %-", &irc_command_notice, NULL);
weechat_hook_command ("op",
N_("gives channel operator status to nickname(s)"),
N_("nickname [nickname]"),
@@ -3806,7 +3806,7 @@ irc_command_init ()
N_("nickname [text]"),
N_("nickname: nickname for private conversation\n"
" text: text to send"),
"%(irc_channel_nicks) %-", &irc_command_query, NULL);
"%n %-", &irc_command_query, NULL);
weechat_hook_command ("quote",
N_("send raw data to server without parsing"),
N_("data"),
@@ -3946,7 +3946,7 @@ irc_command_init ()
N_("return a list of information about nicknames"),
N_("nickname [nickname ...]"),
N_("nickname: nickname"),
"%(irc_channel_nicks)", &irc_command_userhost, NULL);
"%n", &irc_command_userhost, NULL);
weechat_hook_command ("users",
N_("list of users logged into the server"),
N_("[target]"),
@@ -3958,7 +3958,7 @@ irc_command_init ()
N_("[server | nickname]"),
N_(" server: server name\n"
"nickname: nickname"),
"%(irc_channel_nicks)", &irc_command_version, NULL);
"%n", &irc_command_version, NULL);
weechat_hook_command ("voice",
N_("gives voice to nickname(s)"),
N_("[nickname [nickname]]"),
+3 -1
View File
@@ -214,6 +214,8 @@ irc_completion_channel_nicks_cb (void *data, char *completion,
{
weechat_list_add (list, ptr_channel->name, WEECHAT_LIST_POS_SORT);
}
ptr_channel->nick_completion_reset = 0;
}
return WEECHAT_RC_OK;
@@ -362,7 +364,7 @@ irc_completion_init ()
&irc_completion_server_nicks_cb, NULL);
weechat_hook_completion ("irc_servers", &irc_completion_servers_cb, NULL);
weechat_hook_completion ("irc_channel", &irc_completion_channel_cb, NULL);
weechat_hook_completion ("irc_channel_nicks",
weechat_hook_completion ("nick",
&irc_completion_channel_nicks_cb, NULL);
weechat_hook_completion ("irc_channel_nicks_hosts",
&irc_completion_channel_nicks_hosts_cb, NULL);
+13 -10
View File
@@ -60,11 +60,12 @@ gnutls_certificate_credentials gnutls_xcred; /* gnutls client credentials */
/*
* irc_dump_data_cb: dump IRC data in WeeChat log file
* irc_signal_dump_data_cb: dump IRC data in WeeChat log file
*/
int
irc_dump_data_cb (void *data, char *signal, char *type_data, void *signal_data)
irc_signal_dump_data_cb (void *data, char *signal, char *type_data,
void *signal_data)
{
/* make C compiler happy */
(void) data;
@@ -113,11 +114,12 @@ irc_create_directories ()
}
/*
* irc_quit_cb: callback for "quit" signal
* irc_siangl_quit_cb: callback for "quit" signal
*/
int
irc_quit_cb (void *data, char *signal, char *type_data, void *signal_data)
irc_signal_quit_cb (void *data, char *signal, char *type_data,
void *signal_data)
{
struct t_irc_server *ptr_server;
@@ -138,11 +140,12 @@ irc_quit_cb (void *data, char *signal, char *type_data, void *signal_data)
}
/*
* irc_debug_cb: callback for "debug" signal
* irc_signal_debug_cb: callback for "debug" signal
*/
int
irc_debug_cb (void *data, char *signal, char *type_data, void *signal_data)
irc_signal_debug_cb (void *data, char *signal, char *type_data,
void *signal_data)
{
/* make C compiler happy */
(void) data;
@@ -183,10 +186,10 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
irc_command_init ();
/* hook signals */
weechat_hook_signal ("dump_data", &irc_dump_data_cb, NULL);
weechat_hook_signal ("quit", &irc_quit_cb, NULL);
weechat_hook_signal ("debug", &irc_debug_cb, NULL);
/* hook some signals */
weechat_hook_signal ("dump_data", &irc_signal_dump_data_cb, NULL);
weechat_hook_signal ("quit", &irc_signal_quit_cb, NULL);
weechat_hook_signal ("debug", &irc_signal_debug_cb, NULL);
/* hook completions */
irc_completion_init ();
+1 -1
View File
@@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* plugin-api.c: WeeChat <--> plugin API */
/* plugin-api.c: WeeChat <--> plugin API (extra functions) */
#ifdef HAVE_CONFIG_H