diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/alias/alias.c | 37 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.c | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc-command.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 11 | ||||
-rw-r--r-- | src/plugins/plugin.c | 1 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 4 |
6 files changed, 49 insertions, 9 deletions
diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index 1c1a80c56..3fbf012e0 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -213,6 +213,23 @@ alias_replace_args (const char *alias_args, const char *user_args) } /* + * alias_run_command: replace local buffer variables in string, then run + * command on buffer + */ + +void +alias_run_command (struct t_gui_buffer *buffer, const char *command) +{ + char *string; + + string = weechat_buffer_string_replace_local_var (buffer, command); + weechat_command (buffer, + (string) ? string : command); + if (string) + free (string); +} + +/* * alias_cb: callback for alias (called when user uses an alias) */ @@ -226,7 +243,6 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, int some_args_replaced, length1, length2; /* make C compiler happy */ - (void) buffer; (void) argc; (void) argv; @@ -260,7 +276,7 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, { some_args_replaced = 1; if (*ptr_cmd[0] == '/') - weechat_command (weechat_current_buffer, args_replaced); + alias_run_command (buffer, args_replaced); else { alias_command = malloc (1 + strlen(args_replaced) + 1); @@ -268,7 +284,7 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, { strcpy (alias_command, "/"); strcat (alias_command, args_replaced); - weechat_command (weechat_current_buffer, alias_command); + alias_run_command (buffer, alias_command); free (alias_command); } } @@ -295,16 +311,14 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, strcat (alias_command, " "); strcat (alias_command, argv_eol[1]); - weechat_command (weechat_current_buffer, - alias_command); + alias_run_command (buffer, alias_command); free (alias_command); } } else { if (*ptr_cmd[0] == '/') - (void) weechat_command(weechat_current_buffer, - *ptr_cmd); + alias_run_command (buffer, *ptr_cmd); else { alias_command = malloc (1 + strlen (*ptr_cmd) + 1); @@ -312,8 +326,7 @@ alias_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, { strcpy (alias_command, "/"); strcat (alias_command, *ptr_cmd); - weechat_command (weechat_current_buffer, - alias_command); + alias_run_command (buffer, alias_command); free (alias_command); } } @@ -706,6 +719,7 @@ alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc, { char *alias_name; struct t_alias *ptr_alias; + struct t_config_option *ptr_option; /* make C compiler happy */ (void) data; @@ -728,6 +742,11 @@ alias_command_cb (void *data, struct t_gui_buffer *buffer, int argc, } /* create config option */ + ptr_option = weechat_config_search_option (alias_config_file, + alias_config_section_cmd, + alias_name); + if (ptr_option) + weechat_config_option_free (ptr_option); weechat_config_new_option ( alias_config_file, alias_config_section_cmd, alias_name, "string", NULL, diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index 2c015ed57..0d2debba5 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -97,6 +97,9 @@ irc_channel_new (struct t_irc_server *server, int channel_type, } weechat_buffer_set (new_buffer, "short_name", channel_name); + weechat_buffer_set (new_buffer, "localvar_set_nick", server->nick); + weechat_buffer_set (new_buffer, "localvar_set_server", server->name); + weechat_buffer_set (new_buffer, "localvar_set_channel", channel_name); weechat_hook_signal_send ("logger_backlog", WEECHAT_HOOK_SIGNAL_POINTER, new_buffer); diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index c962ba206..a8892592f 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -3138,6 +3138,8 @@ irc_command_server (void *data, struct t_gui_buffer *buffer, int argc, } weechat_buffer_set (irc_current_server->buffer, "short_name", irc_current_server->name); + weechat_buffer_set (irc_current_server->buffer, "localvar_set_server", + irc_current_server->name); weechat_bar_item_update ("buffer_name"); weechat_bar_item_update ("input_prompt"); return WEECHAT_RC_OK; diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 998856a5e..4f9ea7916 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -300,12 +300,22 @@ irc_server_set_with_option (struct t_irc_server *server, void irc_server_set_nick (struct t_irc_server *server, const char *nick) { + struct t_irc_channel *ptr_channel; + if (server->nick) free (server->nick); server->nick = (nick) ? strdup (nick) : NULL; weechat_buffer_set (server->buffer, "highlight_words", nick); + /* set local variable "nick" for server and all channels/pv */ + weechat_buffer_set (server->buffer, "localvar_set_nick", nick); + for (ptr_channel = server->channels; ptr_channel; + ptr_channel = ptr_channel->next_channel) + { + weechat_buffer_set (ptr_channel->buffer, "localvar_set_nick", nick); + } + weechat_bar_item_update ("input_prompt"); } @@ -2180,6 +2190,7 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) } weechat_buffer_set (server->buffer, "short_name", server->name); + weechat_buffer_set (server->buffer, "localvar_set_server", server->name); weechat_buffer_set (server->buffer, "display", "1"); diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 0afd2192d..81ef8375c 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -415,6 +415,7 @@ plugin_load (const char *filename) new_plugin->buffer_get_pointer = &gui_buffer_get_pointer; new_plugin->buffer_set = &gui_buffer_set; new_plugin->buffer_set_pointer = &gui_buffer_set_pointer; + new_plugin->buffer_string_replace_local_var = &gui_buffer_string_replace_local_var; new_plugin->window_get_integer = &gui_window_get_integer; new_plugin->window_get_string = &gui_window_get_string; diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 4536acf2d..f39e04216 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -423,6 +423,8 @@ struct t_weechat_plugin const char *value); void (*buffer_set_pointer) (struct t_gui_buffer *buffer, const char *property, void *pointer); + char *(*buffer_string_replace_local_var) (struct t_gui_buffer *buffer, + const char *string); /* windows */ int (*window_get_integer) (struct t_gui_window *window, @@ -912,6 +914,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->buffer_set(__buffer, __property, __value) #define weechat_buffer_set_pointer(__buffer, __property, __pointer) \ weechat_plugin->buffer_set_pointer(__buffer, __property, __pointer) +#define weechat_buffer_string_replace_local_var(__buffer, __string) \ + weechat_plugin->buffer_string_replace_local_var(__buffer, __string) /* windows */ #define weechat_window_get_integer(__window, __property) \ |