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

core: add option weechat.completion.partial_completion_templates

This option is used to force partial completion on specific templates
(for now only "config_options").
This commit is contained in:
Sébastien Helleu
2017-12-09 11:40:14 +01:00
parent a7522d8e89
commit 40749afced
31 changed files with 399 additions and 141 deletions
+64
View File
@@ -273,6 +273,7 @@ struct t_config_option *config_completion_partial_completion_command;
struct t_config_option *config_completion_partial_completion_command_arg;
struct t_config_option *config_completion_partial_completion_count;
struct t_config_option *config_completion_partial_completion_other;
struct t_config_option *config_completion_partial_completion_templates;
/* config, history section */
@@ -318,6 +319,7 @@ char **config_nick_colors = NULL;
int config_num_nick_colors = 0;
struct t_hashtable *config_hashtable_nick_color_force = NULL;
char *config_item_time_evaluated = NULL;
struct t_hashtable *config_hashtable_completion_partial_templates = NULL;
/*
@@ -1174,6 +1176,51 @@ config_change_nick_colors (const void *pointer, void *data,
gui_color_buffer_display ();
}
/*
* Callback for changes on option
* "weechat.completion.partial_completion_templates".
*/
void
config_change_completion_partial_completion_templates (const void *pointer,
void *data,
struct t_config_option *option)
{
char **items;
int num_items, i;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) option;
if (!config_hashtable_completion_partial_templates)
{
config_hashtable_completion_partial_templates = hashtable_new (
32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_POINTER,
NULL, NULL);
}
else
{
hashtable_remove_all (config_hashtable_completion_partial_templates);
}
items = string_split (
CONFIG_STRING(config_completion_partial_completion_templates),
",", 0, 0, &num_items);
if (items)
{
for (i = 0; i < num_items; i++)
{
hashtable_set (config_hashtable_completion_partial_templates,
items[i], NULL);
}
string_free_split (items);
}
}
/*
* Callback for changes on option "weechat.network.gnutls_ca_file".
*/
@@ -4179,6 +4226,15 @@ config_weechat_init_options ()
"begin with same letters)"),
NULL, 0, 0, "off", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
config_completion_partial_completion_templates = config_file_new_option (
weechat_config_file, ptr_section,
"partial_completion_templates", "string",
N_("comma-separated list of templates for which partial completion is "
"enabled by default (with Tab key instead of shift-Tab)"),
NULL, 0, 0, "config_options", NULL, 0,
NULL, NULL, NULL,
&config_change_completion_partial_completion_templates, NULL, NULL,
NULL, NULL, NULL);
/* history */
ptr_section = config_file_new_section (weechat_config_file, "history",
@@ -4488,6 +4544,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_partial_templates)
config_change_completion_partial_completion_templates (NULL, NULL, NULL);
return rc;
}
@@ -4596,4 +4654,10 @@ config_weechat_free ()
free (config_item_time_evaluated);
config_item_time_evaluated = NULL;
}
if (config_hashtable_completion_partial_templates)
{
hashtable_free (config_hashtable_completion_partial_templates);
config_hashtable_completion_partial_templates = NULL;
}
}
+2
View File
@@ -320,6 +320,7 @@ extern struct t_config_option *config_completion_partial_completion_command;
extern struct t_config_option *config_completion_partial_completion_command_arg;
extern struct t_config_option *config_completion_partial_completion_count;
extern struct t_config_option *config_completion_partial_completion_other;
extern struct t_config_option *config_completion_partial_completion_templates;
extern struct t_config_option *config_history_display_default;
extern struct t_config_option *config_history_max_buffer_lines_minutes;
@@ -354,6 +355,7 @@ extern int config_word_chars_input_count;
extern char **config_nick_colors;
extern int config_num_nick_colors;
extern struct t_hashtable *config_hashtable_nick_color_force;
extern struct t_hashtable *config_hashtable_completion_partial_templates;
extern void config_set_nick_colors ();
extern struct t_config_option *config_weechat_debug_get (const char *plugin_name);
+30 -17
View File
@@ -36,6 +36,7 @@
#include "../core/wee-arraylist.h"
#include "../core/wee-completion.h"
#include "../core/wee-config.h"
#include "../core/wee-hashtable.h"
#include "../core/wee-hdata.h"
#include "../core/wee-hook.h"
#include "../core/wee-list.h"
@@ -114,6 +115,7 @@ gui_completion_buffer_init (struct t_gui_completion *completion,
completion->direction = 0;
completion->add_space = 1;
completion->force_partial_completion = 0;
completion->reverse_partial_completion = 0;
completion->list = arraylist_new (
32, 1, 0,
@@ -509,6 +511,12 @@ gui_completion_build_list_template (struct t_gui_completion *completion,
pos_end - pos);
if (custom_completion)
{
if (hashtable_has_key (
config_hashtable_completion_partial_templates,
custom_completion))
{
completion->reverse_partial_completion = 1;
}
gui_completion_custom (completion,
custom_completion,
plugin);
@@ -1073,6 +1081,9 @@ gui_completion_complete (struct t_gui_completion *completion)
partial_completion = CONFIG_BOOLEAN(config_completion_partial_completion_other);
}
if (completion->reverse_partial_completion)
partial_completion ^= 1;
common_prefix_size = 0;
if (partial_completion
&& completion->list && (completion->list->size > 0))
@@ -1387,6 +1398,7 @@ gui_completion_hdata_completion_cb (const void *pointer, void *data,
HDATA_VAR(struct t_gui_completion, direction, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_completion, add_space, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_completion, force_partial_completion, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_completion, reverse_partial_completion, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_completion, list, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_completion, word_found, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_gui_completion, word_found_is_nick, INTEGER, 0, NULL, NULL);
@@ -1427,23 +1439,24 @@ void
gui_completion_print_log (struct t_gui_completion *completion)
{
log_printf ("[completion (addr:0x%lx)]", completion);
log_printf (" buffer. . . . . . . . . : 0x%lx", completion->buffer);
log_printf (" context . . . . . . . . : %d", completion->context);
log_printf (" base_command. . . . . . : '%s'", completion->base_command);
log_printf (" base_command_arg_index. : %d", completion->base_command_arg_index);
log_printf (" base_word . . . . . . . : '%s'", completion->base_word);
log_printf (" base_word_pos . . . . . : %d", completion->base_word_pos);
log_printf (" position. . . . . . . . : %d", completion->position);
log_printf (" args. . . . . . . . . . : '%s'", completion->args);
log_printf (" direction . . . . . . . : %d", completion->direction);
log_printf (" add_space . . . . . . . : %d", completion->add_space);
log_printf (" force_partial_completion: %d", completion->force_partial_completion);
log_printf (" list. . . . . . . . . . : 0x%lx", completion->list);
log_printf (" word_found. . . . . . . : '%s'", completion->word_found);
log_printf (" word_found_is_nick. . . : %d", completion->word_found_is_nick);
log_printf (" position_replace. . . . : %d", completion->position_replace);
log_printf (" diff_size . . . . . . . : %d", completion->diff_size);
log_printf (" diff_length . . . . . . : %d", completion->diff_length);
log_printf (" buffer. . . . . . . . . . : 0x%lx", completion->buffer);
log_printf (" context . . . . . . . . . : %d", completion->context);
log_printf (" base_command. . . . . . . : '%s'", completion->base_command);
log_printf (" base_command_arg_index. . : %d", completion->base_command_arg_index);
log_printf (" base_word . . . . . . . . : '%s'", completion->base_word);
log_printf (" base_word_pos . . . . . . : %d", completion->base_word_pos);
log_printf (" position. . . . . . . . . : %d", completion->position);
log_printf (" args. . . . . . . . . . . : '%s'", completion->args);
log_printf (" direction . . . . . . . . : %d", completion->direction);
log_printf (" add_space . . . . . . . . : %d", completion->add_space);
log_printf (" force_partial_completion. : %d", completion->force_partial_completion);
log_printf (" reverse_partial_completion: %d", completion->reverse_partial_completion);
log_printf (" list. . . . . . . . . . . : 0x%lx", completion->list);
log_printf (" word_found. . . . . . . . : '%s'", completion->word_found);
log_printf (" word_found_is_nick. . . . : %d", completion->word_found_is_nick);
log_printf (" position_replace. . . . . : %d", completion->position_replace);
log_printf (" diff_size . . . . . . . . : %d", completion->diff_size);
log_printf (" diff_length . . . . . . . : %d", completion->diff_length);
if (completion->list)
{
log_printf ("");
+2 -1
View File
@@ -46,7 +46,8 @@ struct t_gui_completion
char *args; /* command line args (including base word) */
int direction; /* +1=search next word, -1=previous word */
int add_space; /* add space after completion? */
int force_partial_completion; /* force partial completion? */
int force_partial_completion; /* force partial completion? */
int reverse_partial_completion; /* reverse partial completion? */
/* for command argument completion */
struct t_arraylist *list; /* data list for completion */