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

core: add option weechat.completion.nick_ignore_words (closes #1143)

This commit is contained in:
Sébastien Helleu
2025-03-03 08:27:22 +01:00
parent 8280a3b65b
commit 2e570c599b
18 changed files with 563 additions and 348 deletions
+72
View File
@@ -309,6 +309,7 @@ struct t_config_option *config_completion_nick_case_sensitive = NULL;
struct t_config_option *config_completion_nick_completer = NULL;
struct t_config_option *config_completion_nick_first_only = NULL;
struct t_config_option *config_completion_nick_ignore_chars = NULL;
struct t_config_option *config_completion_nick_ignore_words = NULL;
struct t_config_option *config_completion_partial_completion_alert = NULL;
struct t_config_option *config_completion_partial_completion_command = NULL;
struct t_config_option *config_completion_partial_completion_command_arg = NULL;
@@ -375,6 +376,7 @@ char **config_eval_syntax_colors = NULL;
int config_num_eval_syntax_colors = 0;
char *config_item_time_evaluated = NULL;
char *config_buffer_time_same_evaluated = NULL;
struct t_hashtable *config_hashtable_completion_nick_ignore_words = NULL;
struct t_hashtable *config_hashtable_completion_partial_templates = NULL;
char **config_hotlist_sort_fields = NULL;
int config_num_hotlist_sort_fields = 0;
@@ -1420,6 +1422,56 @@ config_change_eval_syntax_colors (const void *pointer, void *data,
gui_color_buffer_display ();
}
/*
* Callback for changes on option "weechat.completion.nick_ignore_words".
*/
void
config_change_completion_nick_ignore_words (const void *pointer,
void *data,
struct t_config_option *option)
{
char **words;
int num_words, i;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) option;
if (!config_hashtable_completion_nick_ignore_words)
{
config_hashtable_completion_nick_ignore_words = hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_POINTER,
NULL, NULL);
}
else
{
hashtable_remove_all (config_hashtable_completion_nick_ignore_words);
}
words = string_split (
CONFIG_STRING(config_completion_nick_ignore_words),
",",
NULL,
WEECHAT_STRING_SPLIT_STRIP_LEFT
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
0,
&num_words);
if (words)
{
for (i = 0; i < num_words; i++)
{
hashtable_set (config_hashtable_completion_nick_ignore_words,
words[i], NULL);
}
string_free_split (words);
}
}
/*
* Callback for changes on option
* "weechat.completion.partial_completion_templates".
@@ -5174,6 +5226,18 @@ config_weechat_init_options ()
N_("chars ignored for nick completion"),
NULL, 0, 0, "[]`_-^", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
config_completion_nick_ignore_words = config_file_new_option (
weechat_config_file, weechat_config_section_completion,
"nick_ignore_words", "string",
N_("comma-separated list of nicks to ignore (not completed); "
"each nick in list must include ignored chars (by option "
"weechat.completion.nick_ignore_chars); look up for nicks is with "
"exact case then lower case, so it's possible to use only lower "
"case for nicks in this option"),
NULL, 0, 0, "", NULL, 0,
NULL, NULL, NULL,
&config_change_completion_nick_ignore_words, NULL, NULL,
NULL, NULL, NULL);
config_completion_partial_completion_alert = config_file_new_option (
weechat_config_file, weechat_config_section_completion,
"partial_completion_alert", "boolean",
@@ -5572,6 +5636,8 @@ config_weechat_init ()
config_change_word_chars_highlight (NULL, NULL, NULL);
if (!config_word_chars_input)
config_change_word_chars_input (NULL, NULL, NULL);
if (!config_hashtable_completion_nick_ignore_words)
config_change_completion_nick_ignore_words (NULL, NULL, NULL);
if (!config_hashtable_completion_partial_templates)
config_change_completion_partial_completion_templates (NULL, NULL, NULL);
@@ -5699,6 +5765,12 @@ config_weechat_free ()
config_buffer_time_same_evaluated = NULL;
}
if (config_hashtable_completion_nick_ignore_words)
{
hashtable_free (config_hashtable_completion_nick_ignore_words);
config_hashtable_completion_nick_ignore_words = NULL;
}
if (config_hashtable_completion_partial_templates)
{
hashtable_free (config_hashtable_completion_partial_templates);
+2
View File
@@ -358,6 +358,7 @@ extern struct t_config_option *config_completion_nick_case_sensitive;
extern struct t_config_option *config_completion_nick_completer;
extern struct t_config_option *config_completion_nick_first_only;
extern struct t_config_option *config_completion_nick_ignore_chars;
extern struct t_config_option *config_completion_nick_ignore_words;
extern struct t_config_option *config_completion_partial_completion_alert;
extern struct t_config_option *config_completion_partial_completion_command;
extern struct t_config_option *config_completion_partial_completion_command_arg;
@@ -410,6 +411,7 @@ extern struct t_hashtable *config_hashtable_nick_color_force;
extern char **config_eval_syntax_colors;
extern int config_num_eval_syntax_colors;
extern char *config_buffer_time_same_evaluated;
extern struct t_hashtable *config_hashtable_completion_nick_ignore_words;
extern struct t_hashtable *config_hashtable_completion_partial_templates;
extern char **config_hotlist_sort_fields;
extern int config_num_hotlist_sort_fields;
+40 -1
View File
@@ -452,6 +452,44 @@ gui_completion_strncmp (struct t_gui_completion *completion,
string_strncasecmp (string1, string2, max);
}
/*
* Checks if a nick is ignored from completion (no completion with this nick).
*
* Returns:
* 1: nick ignored
* 0: nick NOT ignored (can be used in completion)
*/
int
gui_completion_nick_ignored (const char *nick)
{
char *nick_lower;
int rc;
if (!config_hashtable_completion_nick_ignore_words
|| (config_hashtable_completion_nick_ignore_words->items_count == 0))
{
return 0;
}
if (hashtable_has_key (config_hashtable_completion_nick_ignore_words, nick))
return 1;
rc = 0;
nick_lower = string_tolower (nick);
if (nick_lower)
{
if (hashtable_has_key (config_hashtable_completion_nick_ignore_words,
nick_lower))
{
rc = 1;
}
free (nick_lower);
}
return rc;
}
/*
* Adds a word to completion list.
*/
@@ -470,7 +508,8 @@ gui_completion_list_add (struct t_gui_completion *completion, const char *word,
if (!completion->base_word || !completion->base_word[0]
|| (nick_completion
&& (gui_completion_nickncmp (completion->base_word, word,
utf8_strlen (completion->base_word)) == 0))
utf8_strlen (completion->base_word)) == 0)
&& !gui_completion_nick_ignored (word))
|| (!nick_completion
&& (gui_completion_strncmp (completion,
completion->base_word, word,