diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-04-01 19:03:05 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-04-01 19:03:05 +0200 |
commit | ff83985ef4f4073f9430ee065b1d8982fb7c6318 (patch) | |
tree | 2b94f2cd1e36de9bb54a02153e1d30be8145bc21 /src | |
parent | 51af351c15c0277d0c6f060624b67b04e77710df (diff) | |
download | weechat-ff83985ef4f4073f9430ee065b1d8982fb7c6318.zip |
Add default template completion (by default: nick or IRC channel)
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-config.c | 8 | ||||
-rw-r--r-- | src/core/wee-config.h | 1 | ||||
-rw-r--r-- | src/core/wee-list.c | 4 | ||||
-rw-r--r-- | src/core/wee-list.h | 4 | ||||
-rw-r--r-- | src/gui/gui-completion.c | 36 | ||||
-rw-r--r-- | src/gui/gui-completion.h | 1 | ||||
-rw-r--r-- | src/gui/gui-input.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.c | 2 | ||||
-rw-r--r-- | src/plugins/jabber/jabber-muc.c | 2 | ||||
-rw-r--r-- | src/plugins/plugin.c | 2 | ||||
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua-api.c | 15 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl-api.c | 8 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python-api.c | 8 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby-api.c | 15 | ||||
-rw-r--r-- | src/plugins/scripts/tcl/weechat-tcl-api.c | 8 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 7 |
16 files changed, 81 insertions, 42 deletions
diff --git a/src/core/wee-config.c b/src/core/wee-config.c index b5fd829e4..536a59424 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -144,6 +144,7 @@ struct t_config_option *config_color_nicklist_separator; /* config, completion section */ +struct t_config_option *config_completion_default_template; struct t_config_option *config_completion_nick_completor; struct t_config_option *config_completion_nick_first_only; struct t_config_option *config_completion_nick_ignore_chars; @@ -1597,6 +1598,13 @@ config_weechat_init_options () return 0; } + config_completion_default_template = config_file_new_option ( + weechat_config_file, ptr_section, + "default_template", "string", + N_("default completion template (please see documentation for template " + "codes and values)"), + NULL, 0, 0, "%n|%(irc_channels)", NULL, 0, + NULL, NULL, NULL, NULL, NULL, NULL); config_completion_nick_completor = config_file_new_option ( weechat_config_file, ptr_section, "nick_completor", "string", diff --git a/src/core/wee-config.h b/src/core/wee-config.h index bcefc2143..8739b0fa7 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -146,6 +146,7 @@ extern struct t_config_option *config_color_nicklist_prefix5; extern struct t_config_option *config_color_nicklist_more; extern struct t_config_option *config_color_nicklist_separator; +extern struct t_config_option *config_completion_default_template; extern struct t_config_option *config_completion_nick_completor; extern struct t_config_option *config_completion_nick_first_only; extern struct t_config_option *config_completion_nick_ignore_chars; diff --git a/src/core/wee-list.c b/src/core/wee-list.c index 13429cc53..428a5cd20 100644 --- a/src/core/wee-list.c +++ b/src/core/wee-list.c @@ -139,7 +139,8 @@ weelist_insert (struct t_weelist *weelist, struct t_weelist_item *item, */ struct t_weelist_item * -weelist_add (struct t_weelist *weelist, const char *data, const char *where) +weelist_add (struct t_weelist *weelist, const char *data, const char *where, + void *user_data) { struct t_weelist_item *new_item; @@ -150,6 +151,7 @@ weelist_add (struct t_weelist *weelist, const char *data, const char *where) if (new_item) { new_item->data = strdup (data); + new_item->user_data = user_data; weelist_insert (weelist, new_item, where); weelist->size++; } diff --git a/src/core/wee-list.h b/src/core/wee-list.h index 5aa0ff8d2..0cfd18a28 100644 --- a/src/core/wee-list.h +++ b/src/core/wee-list.h @@ -23,6 +23,7 @@ struct t_weelist_item { char *data; /* item data */ + void *user_data; /* pointer to user data */ struct t_weelist_item *prev_item; /* link to previous item */ struct t_weelist_item *next_item; /* link to next item */ }; @@ -36,7 +37,8 @@ struct t_weelist extern struct t_weelist *weelist_new (); extern struct t_weelist_item *weelist_add (struct t_weelist *weelist, - const char *data, const char *where); + const char *data, const char *where, + void *user_data); extern struct t_weelist_item *weelist_search (struct t_weelist *weelist, const char *data); extern struct t_weelist_item *weelist_casesearch (struct t_weelist *weelist, diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index b64a326fe..fe1d05545 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -77,6 +77,7 @@ gui_completion_init (struct t_gui_completion *completion, completion->completion_list = weelist_new (); completion->word_found = NULL; + completion->word_found_is_nick = 0; completion->position_replace = 0; completion->diff_size = 0; completion->diff_length = 0; @@ -316,7 +317,8 @@ gui_completion_list_add (struct t_gui_completion *completion, const char *word, || (!nick_completion && (string_strncasecmp (completion->base_word, word, strlen (completion->base_word)) == 0))) { - weelist_add (completion->completion_list, word, where); + weelist_add (completion->completion_list, word, where, + (nick_completion) ? (void *)1 : (void *)0); } } @@ -1381,7 +1383,7 @@ gui_completion_partial_build_list (struct t_gui_completion *completion, ptr_item = ptr_item->next_item) { weelist_add (weelist_temp, ptr_item->data + common_prefix_size, - WEECHAT_LIST_POS_END); + WEECHAT_LIST_POS_END, NULL); } while (weelist_temp->items) @@ -1432,7 +1434,7 @@ gui_completion_complete (struct t_gui_completion *completion, int nick_completion) { int length, word_found_seen, other_completion, partial_completion; - int common_prefix_size; + int common_prefix_size, item_is_nick; struct t_weelist_item *ptr_item, *ptr_item2; length = strlen (completion->base_word); @@ -1482,10 +1484,11 @@ gui_completion_complete (struct t_gui_completion *completion, while (ptr_item) { - if ((nick_completion + item_is_nick = ((int)(ptr_item->user_data) == 1); + if ((item_is_nick && (gui_completion_nickncmp (completion->base_word, ptr_item->data, length) == 0)) - || ((!nick_completion) + || ((!item_is_nick) && (string_strncasecmp (completion->base_word, ptr_item->data, length) == 0))) { @@ -1494,9 +1497,10 @@ gui_completion_complete (struct t_gui_completion *completion, if (completion->word_found) free (completion->word_found); completion->word_found = strdup (ptr_item->data); + completion->word_found_is_nick = item_is_nick; /* stop after first nick if user asked that */ - if (nick_completion + if (item_is_nick && CONFIG_BOOLEAN(config_completion_nick_first_only)) { gui_completion_stop (completion, 1); @@ -1510,11 +1514,11 @@ gui_completion_complete (struct t_gui_completion *completion, while (ptr_item2) { - if ((nick_completion + if ((item_is_nick && (gui_completion_nickncmp (completion->base_word, ptr_item2->data, length) == 0)) - || ((!nick_completion) + || ((!item_is_nick) && (string_strncasecmp (completion->base_word, ptr_item2->data, length) == 0))) @@ -1540,6 +1544,7 @@ gui_completion_complete (struct t_gui_completion *completion, && (other_completion > 0)) { completion->word_found[common_prefix_size] = '\0'; + completion->word_found_is_nick = 0; completion->add_space = 0; completion->position = -1; string_tolower (completion->word_found); @@ -1579,6 +1584,7 @@ gui_completion_complete (struct t_gui_completion *completion, { free (completion->word_found); completion->word_found = NULL; + completion->word_found_is_nick = 0; gui_completion_complete (completion, nick_completion); } } @@ -1643,11 +1649,14 @@ gui_completion_auto (struct t_gui_completion *completion) return; } - /* default: nick completion (if there's a nicklist) */ - if (completion->buffer->nicklist_root) - gui_completion_nick (completion); - else - completion->context = GUI_COMPLETION_NULL; + /* use default template completion */ + if (!completion->completion_list->items) + { + gui_completion_build_list_template (completion, + CONFIG_STRING(config_completion_default_template), + NULL); + } + gui_completion_complete (completion, 0); } /* @@ -1668,6 +1677,7 @@ gui_completion_search (struct t_gui_completion *completion, int direction, if (completion->word_found) free (completion->word_found); completion->word_found = NULL; + completion->word_found_is_nick = 0; gui_completion_find_context (completion, data, size, pos); completion->force_partial_completion = (direction < 0); } diff --git a/src/gui/gui-completion.h b/src/gui/gui-completion.h index d95cdf021..324534e1b 100644 --- a/src/gui/gui-completion.h +++ b/src/gui/gui-completion.h @@ -47,6 +47,7 @@ struct t_gui_completion /* completion found */ char *word_found; /* word found (to replace base word) */ + int word_found_is_nick; /* word found is nick? */ int position_replace; /* position where word has to be replaced */ int diff_size; /* size difference (< 0 = char(s) deleted) */ int diff_length; /* length difference (<= diff_size) */ diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index e423caea4..c049c5b6d 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -365,7 +365,7 @@ gui_input_complete (struct t_gui_buffer *buffer) /* add nick completor if position 0 and completing nick */ if ((buffer->completion->base_word_pos == 0) - && (buffer->completion->context == GUI_COMPLETION_NICK)) + && buffer->completion->word_found_is_nick) { if (buffer->completion->add_space) { diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index 734a4274b..537d18bf7 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -334,7 +334,7 @@ irc_channel_nick_speaking_add (struct t_irc_channel *channel, /* add nick in list */ weechat_list_add (channel->nicks_speaking[highlight], nick_name, - WEECHAT_LIST_POS_END); + WEECHAT_LIST_POS_END, NULL); /* reduce list size if it's too big */ size = weechat_list_size (channel->nicks_speaking[highlight]); diff --git a/src/plugins/jabber/jabber-muc.c b/src/plugins/jabber/jabber-muc.c index eece05b9e..64e658577 100644 --- a/src/plugins/jabber/jabber-muc.c +++ b/src/plugins/jabber/jabber-muc.c @@ -278,7 +278,7 @@ jabber_muc_buddy_speaking_add (struct t_jabber_muc *muc, const char *buddy_name, /* add buddy in list */ weechat_list_add (muc->buddies_speaking[highlight], buddy_name, - WEECHAT_LIST_POS_END); + WEECHAT_LIST_POS_END, NULL); /* reduce list size if it's too big */ size = weechat_list_size (muc->buddies_speaking[highlight]); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 92a2b98b9..adfa72f6c 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -910,7 +910,7 @@ plugin_display_short_list () ptr_plugin = ptr_plugin->next_plugin) { length += strlen (ptr_plugin->name) + 2; - weelist_add (list, ptr_plugin->name, WEECHAT_LIST_POS_SORT); + weelist_add (list, ptr_plugin->name, WEECHAT_LIST_POS_SORT, NULL); } length++; diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 7808cdc74..e2d510acf 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -550,7 +550,7 @@ weechat_lua_api_list_new (lua_State *L) static int weechat_lua_api_list_add (lua_State *L) { - const char *weelist, *data, *where; + const char *weelist, *data, *where, *user_data; char *result; int n; @@ -566,22 +566,25 @@ weechat_lua_api_list_add (lua_State *L) weelist = NULL; data = NULL; where = NULL; + user_data = NULL; n = lua_gettop (lua_current_interpreter); - if (n < 3) + if (n < 4) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_add"); LUA_RETURN_EMPTY; } - weelist = lua_tostring (lua_current_interpreter, -3); - data = lua_tostring (lua_current_interpreter, -2); - where = lua_tostring (lua_current_interpreter, -1); + weelist = lua_tostring (lua_current_interpreter, -4); + data = lua_tostring (lua_current_interpreter, -3); + where = lua_tostring (lua_current_interpreter, -2); + user_data = lua_tostring (lua_current_interpreter, -1); result = script_ptr2str (weechat_list_add (script_str2ptr (weelist), data, - where)); + where, + script_str2ptr (user_data))); LUA_RETURN_STRING_FREE(result); } diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index dfeb36686..6b9db3e23 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -462,7 +462,7 @@ static XS (XS_weechat_api_list_new) static XS (XS_weechat_api_list_add) { - char *result, *weelist, *data, *where; + char *result, *weelist, *data, *where, *user_data; dXSARGS; /* make C compiler happy */ @@ -474,7 +474,7 @@ static XS (XS_weechat_api_list_add) PERL_RETURN_EMPTY; } - if (items < 3) + if (items < 4) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_add"); PERL_RETURN_EMPTY; @@ -483,9 +483,11 @@ static XS (XS_weechat_api_list_add) weelist = SvPV (ST (0), PL_na); data = SvPV (ST (1), PL_na); where = SvPV (ST (2), PL_na); + user_data = SvPV (ST (3), PL_na); result = script_ptr2str (weechat_list_add (script_str2ptr (weelist), data, - where)); + where, + script_str2ptr (user_data))); PERL_RETURN_STRING_FREE(result); } diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index e42cbbbb4..d66291586 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -485,7 +485,7 @@ weechat_python_api_list_new (PyObject *self, PyObject *args) static PyObject * weechat_python_api_list_add (PyObject *self, PyObject *args) { - char *weelist, *data, *where, *result; + char *weelist, *data, *where, *user_data, *result; PyObject *object; /* make C compiler happy */ @@ -500,8 +500,9 @@ weechat_python_api_list_add (PyObject *self, PyObject *args) weelist = NULL; data = NULL; where = NULL; + user_data = NULL; - if (!PyArg_ParseTuple (args, "sss", &weelist, &data, &where)) + if (!PyArg_ParseTuple (args, "ssss", &weelist, &data, &where, &user_data)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_add"); PYTHON_RETURN_EMPTY; @@ -509,7 +510,8 @@ weechat_python_api_list_add (PyObject *self, PyObject *args) result = script_ptr2str (weechat_list_add (script_str2ptr (weelist), data, - where)); + where, + script_str2ptr (user_data))); PYTHON_RETURN_STRING_FREE(result); } diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index dd6b5fe6a..99e46bf46 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -556,9 +556,10 @@ weechat_ruby_api_list_new (VALUE class) */ static VALUE -weechat_ruby_api_list_add (VALUE class, VALUE weelist, VALUE data, VALUE where) +weechat_ruby_api_list_add (VALUE class, VALUE weelist, VALUE data, VALUE where, + VALUE user_data) { - char *c_weelist, *c_data, *c_where, *result; + char *c_weelist, *c_data, *c_where, *c_user_data, *result; /* make C compiler happy */ (void) class; @@ -572,8 +573,9 @@ weechat_ruby_api_list_add (VALUE class, VALUE weelist, VALUE data, VALUE where) c_weelist = NULL; c_data = NULL; c_where = NULL; + c_user_data = NULL; - if (NIL_P (weelist) || NIL_P (data) || NIL_P (where)) + if (NIL_P (weelist) || NIL_P (data) || NIL_P (where) || NIL_P (user_data)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_add"); RUBY_RETURN_EMPTY; @@ -582,14 +584,17 @@ weechat_ruby_api_list_add (VALUE class, VALUE weelist, VALUE data, VALUE where) Check_Type (weelist, T_STRING); Check_Type (data, T_STRING); Check_Type (where, T_STRING); + Check_Type (user_data, T_STRING); c_weelist = STR2CSTR (weelist); c_data = STR2CSTR (data); c_where = STR2CSTR (where); + c_user_data = STR2CSTR (user_data); result = script_ptr2str (weechat_list_add (script_str2ptr(c_weelist), c_data, - c_where)); + c_where, + script_str2ptr (c_user_data))); RUBY_RETURN_STRING(result); } @@ -6590,7 +6595,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "mkdir", &weechat_ruby_api_mkdir, 2); rb_define_module_function (ruby_mWeechat, "mkdir_parents", &weechat_ruby_api_mkdir_parents, 2); rb_define_module_function (ruby_mWeechat, "list_new", &weechat_ruby_api_list_new, 0); - rb_define_module_function (ruby_mWeechat, "list_add", &weechat_ruby_api_list_add, 3); + rb_define_module_function (ruby_mWeechat, "list_add", &weechat_ruby_api_list_add, 4); rb_define_module_function (ruby_mWeechat, "list_search", &weechat_ruby_api_list_search, 2); rb_define_module_function (ruby_mWeechat, "list_casesearch", &weechat_ruby_api_list_casesearch, 2); rb_define_module_function (ruby_mWeechat, "list_get", &weechat_ruby_api_list_get, 2); diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index 99fb5282a..fc59def73 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -622,7 +622,7 @@ weechat_tcl_api_list_add (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { Tcl_Obj* objp; - char *result, *weelist, *data, *where; + char *result, *weelist, *data, *where, *user_data; int i; /* make C compiler happy */ @@ -635,7 +635,7 @@ weechat_tcl_api_list_add (ClientData clientData, Tcl_Interp *interp, TCL_RETURN_EMPTY; } - if (objc < 4) + if (objc < 5) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_add"); TCL_RETURN_EMPTY; @@ -644,9 +644,11 @@ weechat_tcl_api_list_add (ClientData clientData, Tcl_Interp *interp, weelist = Tcl_GetStringFromObj (objv[1], &i); data = Tcl_GetStringFromObj (objv[2], &i); where = Tcl_GetStringFromObj (objv[3], &i); + user_data = Tcl_GetStringFromObj (objv[4], &i); result = script_ptr2str (weechat_list_add (script_str2ptr (weelist), data, - where)); + where, + script_str2ptr (user_data))); TCL_RETURN_STRING_FREE(result); } diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 92885cd45..fa246f757 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -203,7 +203,8 @@ struct t_weechat_plugin struct t_weelist *(*list_new) (); struct t_weelist_item *(*list_add) (struct t_weelist *weelist, const char *data, - const char *where); + const char *where, + void *user_data); struct t_weelist_item *(*list_search) (struct t_weelist *weelist, const char *data); struct t_weelist_item *(*list_casesearch) (struct t_weelist *weelist, @@ -752,8 +753,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); /* sorted list */ #define weechat_list_new() \ weechat_plugin->list_new() -#define weechat_list_add(__list, __string, __where) \ - weechat_plugin->list_add(__list, __string, __where) +#define weechat_list_add(__list, __string, __where, __user_data) \ + weechat_plugin->list_add(__list, __string, __where, __user_data) #define weechat_list_search(__list, __string) \ weechat_plugin->list_search(__list, __string) #define weechat_list_casesearch(__list, __string) \ |