From 3f86d6d46014ca55e42cecd570d7f269b1d386b3 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Apr 2020 15:55:51 +0000 Subject: When adding a list of commands to the queue, instead of automatically creating a new state for each group of commands, require the caller to create one and use it for all the commands in the list. This means the current target works even with list with multiple groups (which can happen if they are defined with newlines). --- notify.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'notify.c') diff --git a/notify.c b/notify.c index 1f48fb6e..3147c4e0 100644 --- a/notify.c +++ b/notify.c @@ -36,19 +36,19 @@ struct notify_entry { }; static void -notify_hook_formats(struct cmdq_item *item, struct session *s, struct window *w, - int pane) +notify_hook_formats(struct cmdq_state *state, struct session *s, + struct window *w, int pane) { if (s != NULL) { - cmdq_format(item, "hook_session", "$%u", s->id); - cmdq_format(item, "hook_session_name", "%s", s->name); + cmdq_add_format(state, "hook_session", "$%u", s->id); + cmdq_add_format(state, "hook_session_name", "%s", s->name); } if (w != NULL) { - cmdq_format(item, "hook_window", "@%u", w->id); - cmdq_format(item, "hook_window_name", "%s", w->name); + cmdq_add_format(state, "hook_window", "@%u", w->id); + cmdq_add_format(state, "hook_window_name", "%s", w->name); } if (pane != -1) - cmdq_format(item, "hook_pane", "%%%d", pane); + cmdq_add_format(state, "hook_pane", "%%%d", pane); } static void @@ -57,6 +57,7 @@ notify_insert_hook(struct cmdq_item *item, struct notify_entry *ne) struct cmd_find_state fs; struct options *oo; struct cmdq_item *new_item; + struct cmdq_state *new_state; struct session *s = ne->session; struct window *w = ne->window; struct options_entry *o; @@ -87,22 +88,21 @@ notify_insert_hook(struct cmdq_item *item, struct notify_entry *ne) if (o == NULL) return; + new_state = cmdq_new_state(&fs, NULL, CMDQ_STATE_NOHOOKS); + cmdq_add_format(new_state, "hook", "%s", ne->name); + notify_hook_formats(new_state, s, w, ne->pane); + a = options_array_first(o); while (a != NULL) { cmdlist = options_array_item_value(a)->cmdlist; - if (cmdlist == NULL) { - a = options_array_next(a); - continue; + if (cmdlist != NULL) { + new_item = cmdq_get_command(cmdlist, new_state); + item = cmdq_insert_after(item, new_item); } - - new_item = cmdq_get_command(cmdlist, &fs, NULL, - CMDQ_STATE_NOHOOKS); - cmdq_format(new_item, "hook", "%s", ne->name); - notify_hook_formats(new_item, s, w, ne->pane); - item = cmdq_insert_after(item, new_item); - a = options_array_next(a); } + + cmdq_free_state(new_state); } static enum cmd_retval -- cgit v1.2.3