diff options
-rw-r--r-- | src/core/wee-hook.c | 15 | ||||
-rw-r--r-- | src/gui/gui-bar-item.c | 16 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 4 | ||||
-rw-r--r-- | src/gui/gui-completion.c | 154 | ||||
-rw-r--r-- | src/gui/gui-completion.h | 20 |
5 files changed, 125 insertions, 84 deletions
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index a18883c06..e36b46f40 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -483,6 +483,7 @@ hook_command_build_completion (struct t_hook_command *hook_command) } } } + weelist_free (list); } } @@ -2176,8 +2177,22 @@ unhook (struct t_hook *hook) } free (HOOK_COMMAND(hook, cplt_templates)); } + if (HOOK_COMMAND(hook, cplt_templates_static)) + free (HOOK_COMMAND(hook, cplt_templates_static)); if (HOOK_COMMAND(hook, cplt_template_num_args)) free (HOOK_COMMAND(hook, cplt_template_num_args)); + if (HOOK_COMMAND(hook, cplt_template_args)) + free (HOOK_COMMAND(hook, cplt_template_args)); + if (HOOK_COMMAND(hook, cplt_template_args_concat)) + { + for (i = 0; + i < HOOK_COMMAND(hook, cplt_template_num_args_concat); + i++) + { + free (HOOK_COMMAND(hook, cplt_template_args_concat[i])); + } + free (HOOK_COMMAND(hook, cplt_template_args_concat)); + } break; case HOOK_TYPE_COMMAND_RUN: if (HOOK_COMMAND_RUN(hook, command)) diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index d50a20de4..aa9890234 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -1044,11 +1044,17 @@ gui_bar_item_default_completion (void *data, struct t_gui_bar_item *item, /* make C compiler happy */ (void) data; (void) item; - (void) window; + + if (!window) + window = gui_current_window; + + if (!window->buffer->completion + || !window->buffer->completion->partial_completion_list) + return NULL; length = 1; - for (ptr_item = gui_completion_partial_list; ptr_item; - ptr_item = ptr_item->next_item) + for (ptr_item = window->buffer->completion->partial_completion_list; + ptr_item; ptr_item = ptr_item->next_item) { length += strlen (ptr_item->word) + 32; } @@ -1057,8 +1063,8 @@ gui_bar_item_default_completion (void *data, struct t_gui_bar_item *item, if (buf) { buf[0] = '\0'; - for (ptr_item = gui_completion_partial_list; ptr_item; - ptr_item = ptr_item->next_item) + for (ptr_item = window->buffer->completion->partial_completion_list; + ptr_item; ptr_item = ptr_item->next_item) { strcat (buf, GUI_COLOR_CUSTOM_BAR_FG); strcat (buf, ptr_item->word); diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index e304dd82d..5abff70d1 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -1515,6 +1515,10 @@ gui_buffer_close (struct t_gui_buffer *buffer) /* free all lines */ gui_line_free_all (buffer); + if (buffer->own_lines) + free (buffer->own_lines); + if (buffer->mixed_lines) + free (buffer->mixed_lines); /* free some data */ if (buffer->title) diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index d25ba9834..8d11da52e 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -49,10 +49,6 @@ #include "gui-nicklist.h" -struct t_gui_completion_partial *gui_completion_partial_list = NULL; -struct t_gui_completion_partial *last_gui_completion_partial = NULL; - - /* * gui_completion_buffer_init: init completion for a buffer */ @@ -80,47 +76,9 @@ gui_completion_buffer_init (struct t_gui_completion *completion, completion->position_replace = 0; completion->diff_size = 0; completion->diff_length = 0; -} - -/* - * gui_completion_free_data: free data in completion - */ - -void -gui_completion_free_data (struct t_gui_completion *completion) -{ - if (completion->base_command) - free (completion->base_command); - completion->base_command = NULL; - - if (completion->base_word) - free (completion->base_word); - completion->base_word = NULL; - - if (completion->args) - free (completion->args); - completion->args = NULL; - - if (completion->completion_list) - { - weelist_free (completion->completion_list); - completion->completion_list = NULL; - } - if (completion->word_found) - free (completion->word_found); - completion->word_found = NULL; -} - -/* - * gui_completion_free: free completion - */ - -void -gui_completion_free (struct t_gui_completion *completion) -{ - gui_completion_free_data (completion); - free (completion); + completion->partial_completion_list = NULL; + completion->last_partial_completion = NULL; } /* @@ -128,7 +86,8 @@ gui_completion_free (struct t_gui_completion *completion) */ struct t_gui_completion_partial * -gui_completion_partial_list_add (const char *word, int count) +gui_completion_partial_list_add (struct t_gui_completion *completion, + const char *word, int count) { struct t_gui_completion_partial *new_item; @@ -138,12 +97,12 @@ gui_completion_partial_list_add (const char *word, int count) new_item->word = strdup (word); new_item->count = count; - new_item->prev_item = last_gui_completion_partial; - if (gui_completion_partial_list) - last_gui_completion_partial->next_item = new_item; + new_item->prev_item = completion->last_partial_completion; + if (completion->partial_completion_list) + (completion->last_partial_completion)->next_item = new_item; else - gui_completion_partial_list = new_item; - last_gui_completion_partial = new_item; + completion->partial_completion_list = new_item; + completion->last_partial_completion = new_item; new_item->next_item = NULL; } return new_item; @@ -154,21 +113,23 @@ gui_completion_partial_list_add (const char *word, int count) */ void -gui_completion_partial_list_free (struct t_gui_completion_partial *item) +gui_completion_partial_list_free (struct t_gui_completion *completion, + struct t_gui_completion_partial *item) { /* remove partial completion item from list */ if (item->prev_item) (item->prev_item)->next_item = item->next_item; if (item->next_item) (item->next_item)->prev_item = item->prev_item; - if (gui_completion_partial_list == item) - gui_completion_partial_list = item->next_item; - if (last_gui_completion_partial == item) - last_gui_completion_partial = item->prev_item; + if (completion->partial_completion_list == item) + completion->partial_completion_list = item->next_item; + if (completion->last_partial_completion == item) + completion->last_partial_completion = item->prev_item; /* free data */ if (item->word) free (item->word); + free (item); } @@ -177,15 +138,59 @@ gui_completion_partial_list_free (struct t_gui_completion_partial *item) */ void -gui_completion_partial_list_free_all () +gui_completion_partial_list_free_all (struct t_gui_completion *completion) { - while (gui_completion_partial_list) + while (completion->partial_completion_list) { - gui_completion_partial_list_free (gui_completion_partial_list); + gui_completion_partial_list_free (completion, + completion->partial_completion_list); } } /* + * gui_completion_free_data: free data in completion + */ + +void +gui_completion_free_data (struct t_gui_completion *completion) +{ + if (completion->base_command) + free (completion->base_command); + completion->base_command = NULL; + + if (completion->base_word) + free (completion->base_word); + completion->base_word = NULL; + + if (completion->args) + free (completion->args); + completion->args = NULL; + + if (completion->completion_list) + { + weelist_free (completion->completion_list); + completion->completion_list = NULL; + } + + if (completion->word_found) + free (completion->word_found); + completion->word_found = NULL; + + gui_completion_partial_list_free_all (completion); +} + +/* + * gui_completion_free: free completion + */ + +void +gui_completion_free (struct t_gui_completion *completion) +{ + gui_completion_free_data (completion); + free (completion); +} + +/* * gui_completion_stop: stop completion (for example after 1 arg of command * with 1 arg) */ @@ -198,7 +203,7 @@ gui_completion_stop (struct t_gui_completion *completion, completion->position = -1; if (remove_partial_completion_list) { - gui_completion_partial_list_free_all (); + gui_completion_partial_list_free_all (completion); hook_signal_send ("partial_completion", WEECHAT_HOOK_SIGNAL_STRING, NULL); } @@ -1699,10 +1704,10 @@ gui_completion_partial_build_list (struct t_gui_completion *completion, { int char_size, items_count; char utf_char[16], *word; - struct t_weelist *weelist_temp, *weelist_words; + struct t_weelist *weelist_temp; struct t_weelist_item *ptr_item, *next_item; - gui_completion_partial_list_free_all (); + gui_completion_partial_list_free_all (completion); if (!completion->completion_list || !completion->completion_list->items) return; @@ -1711,13 +1716,6 @@ gui_completion_partial_build_list (struct t_gui_completion *completion, if (!weelist_temp) return; - weelist_words = weelist_new (); - if (!weelist_words) - { - weelist_free (weelist_temp); - return; - } - for (ptr_item = completion->completion_list->items; ptr_item; ptr_item = ptr_item->next_item) { @@ -1754,7 +1752,8 @@ gui_completion_partial_build_list (struct t_gui_completion *completion, } if (word) { - gui_completion_partial_list_add (word, + gui_completion_partial_list_add (completion, + word, CONFIG_BOOLEAN(config_completion_partial_completion_count) ? items_count : -1); free (word); @@ -1900,7 +1899,7 @@ gui_completion_complete (struct t_gui_completion *completion) return; } - gui_completion_partial_list_free_all (); + gui_completion_partial_list_free_all (completion); return; } @@ -2057,6 +2056,8 @@ gui_completion_search (struct t_gui_completion *completion, int direction, void gui_completion_print_log (struct t_gui_completion *completion) { + struct t_gui_completion_partial *ptr_item; + log_printf ("[completion (addr:0x%lx)]", completion); log_printf (" buffer. . . . . . . . . : 0x%lx", completion->buffer); log_printf (" context . . . . . . . . : %d", completion->context); @@ -2081,6 +2082,19 @@ gui_completion_print_log (struct t_gui_completion *completion) weelist_print_log (completion->completion_list, "completion list element"); } + if (completion->partial_completion_list) + { + log_printf (""); + for (ptr_item = completion->partial_completion_list; + ptr_item; ptr_item = ptr_item->next_item) + { + log_printf ("[partial completion item (addr:0x%lx)]", ptr_item); + log_printf (" word. . . . . . . . . . : '%s'", ptr_item->word); + log_printf (" count . . . . . . . . . : %d", ptr_item->count); + log_printf (" prev_item . . . . . . . : 0x%lx", ptr_item->prev_item); + log_printf (" next_item . . . . . . . : 0x%lx", ptr_item->next_item); + } + } } /* diff --git a/src/gui/gui-completion.h b/src/gui/gui-completion.h index b5b43654d..4570d26bf 100644 --- a/src/gui/gui-completion.h +++ b/src/gui/gui-completion.h @@ -25,6 +25,14 @@ #define GUI_COMPLETION_COMMAND_ARG 2 #define GUI_COMPLETION_AUTO 3 +struct t_gui_completion_partial +{ + char *word; /* (partial) word matching completion */ + int count; /* number of matching items with this word */ + struct t_gui_completion_partial *prev_item; + struct t_gui_completion_partial *next_item; +}; + struct t_gui_completion { /* completion context */ @@ -49,18 +57,12 @@ struct t_gui_completion 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) */ -}; -struct t_gui_completion_partial -{ - char *word; /* (partial) word matching completion */ - int count; /* number of matching items with this word */ - struct t_gui_completion_partial *prev_item; - struct t_gui_completion_partial *next_item; + /* partial completion */ + struct t_gui_completion_partial *partial_completion_list; + struct t_gui_completion_partial *last_partial_completion; }; -extern struct t_gui_completion_partial *gui_completion_partial_list; - /* completion functions */ extern void gui_completion_buffer_init (struct t_gui_completion *completion, |