From 9cbe9675ea8a8efb01dcc5f267e6d5853b2cd58f Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Apr 2020 07:25:33 +0000 Subject: [PATCH] Change so that the appropriate hooks for windows and panes belong to pane/window options rather than all being session options. This is useful for example to create a pane that is automatically closed on some condition. From Anindya Mukherjee. --- cmd-set-option.c | 6 +++--- cmd-show-options.c | 6 +++--- notify.c | 8 ++++++++ options-table.c | 42 ++++++++++++++++++++++++++++++------------ tmux.1 | 29 ++++++++++------------------- 5 files changed, 54 insertions(+), 37 deletions(-) diff --git a/cmd-set-option.c b/cmd-set-option.c index 2709dcdc..d466093e 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -69,10 +69,10 @@ const struct cmd_entry cmd_set_hook_entry = { .name = "set-hook", .alias = NULL, - .args = { "agRt:u", 1, 2 }, - .usage = "[-agRu] " CMD_TARGET_SESSION_USAGE " hook [command]", + .args = { "agpRt:uw", 1, 2 }, + .usage = "[-agpRuw] " CMD_TARGET_PANE_USAGE " hook [command]", - .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, + .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, .flags = CMD_AFTERHOOK, .exec = cmd_set_option_exec diff --git a/cmd-show-options.c b/cmd-show-options.c index b5c5f59d..fe3cddc5 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -65,10 +65,10 @@ const struct cmd_entry cmd_show_hooks_entry = { .name = "show-hooks", .alias = NULL, - .args = { "gt:", 0, 1 }, - .usage = "[-g] " CMD_TARGET_SESSION_USAGE, + .args = { "gpt:w", 0, 1 }, + .usage = "[-gpw] " CMD_TARGET_PANE_USAGE, - .target = { 't', CMD_FIND_SESSION, 0 }, + .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, .flags = CMD_AFTERHOOK, .exec = cmd_show_options_exec diff --git a/notify.c b/notify.c index c91a4399..772b3e1f 100644 --- a/notify.c +++ b/notify.c @@ -76,6 +76,14 @@ notify_insert_hook(struct cmdq_item *item, struct notify_entry *ne) else oo = fs.s->options; o = options_get(oo, ne->name); + if (o == NULL && fs.wp != NULL) { + oo = fs.wp->options; + o = options_get(oo, ne->name); + } + if (o == NULL && fs.wl != NULL) { + oo = fs.wl->window->options; + o = options_get(oo, ne->name); + } if (o == NULL) return; diff --git a/options-table.c b/options-table.c index d8612ff2..33ee4402 100644 --- a/options-table.c +++ b/options-table.c @@ -140,7 +140,7 @@ static const char *options_table_status_format_default[] = { OPTIONS_TABLE_STATUS_FORMAT1, OPTIONS_TABLE_STATUS_FORMAT2, NULL }; -/* Helper for hook options. */ +/* Helpers for hook options. */ #define OPTIONS_TABLE_HOOK(hook_name, default_value) \ { .name = hook_name, \ .type = OPTIONS_TABLE_COMMAND, \ @@ -150,6 +150,24 @@ static const char *options_table_status_format_default[] = { .separator = "" \ } +#define OPTIONS_TABLE_PANE_HOOK(hook_name, default_value) \ + { .name = hook_name, \ + .type = OPTIONS_TABLE_COMMAND, \ + .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE, \ + .flags = OPTIONS_TABLE_IS_ARRAY|OPTIONS_TABLE_IS_HOOK, \ + .default_str = default_value, \ + .separator = "" \ + } + +#define OPTIONS_TABLE_WINDOW_HOOK(hook_name, default_value) \ + { .name = hook_name, \ + .type = OPTIONS_TABLE_COMMAND, \ + .scope = OPTIONS_TABLE_WINDOW, \ + .flags = OPTIONS_TABLE_IS_ARRAY|OPTIONS_TABLE_IS_HOOK, \ + .default_str = default_value, \ + .separator = "" \ + } + /* Top-level options. */ const struct options_table_entry options_table[] = { /* Server options. */ @@ -851,21 +869,21 @@ const struct options_table_entry options_table[] = { OPTIONS_TABLE_HOOK("client-detached", ""), OPTIONS_TABLE_HOOK("client-resized", ""), OPTIONS_TABLE_HOOK("client-session-changed", ""), - OPTIONS_TABLE_HOOK("pane-died", ""), - OPTIONS_TABLE_HOOK("pane-exited", ""), - OPTIONS_TABLE_HOOK("pane-focus-in", ""), - OPTIONS_TABLE_HOOK("pane-focus-out", ""), - OPTIONS_TABLE_HOOK("pane-mode-changed", ""), - OPTIONS_TABLE_HOOK("pane-set-clipboard", ""), + OPTIONS_TABLE_PANE_HOOK("pane-died", ""), + OPTIONS_TABLE_PANE_HOOK("pane-exited", ""), + OPTIONS_TABLE_PANE_HOOK("pane-focus-in", ""), + OPTIONS_TABLE_PANE_HOOK("pane-focus-out", ""), + OPTIONS_TABLE_PANE_HOOK("pane-mode-changed", ""), + OPTIONS_TABLE_PANE_HOOK("pane-set-clipboard", ""), OPTIONS_TABLE_HOOK("session-closed", ""), OPTIONS_TABLE_HOOK("session-created", ""), OPTIONS_TABLE_HOOK("session-renamed", ""), OPTIONS_TABLE_HOOK("session-window-changed", ""), - OPTIONS_TABLE_HOOK("window-layout-changed", ""), - OPTIONS_TABLE_HOOK("window-linked", ""), - OPTIONS_TABLE_HOOK("window-pane-changed", ""), - OPTIONS_TABLE_HOOK("window-renamed", ""), - OPTIONS_TABLE_HOOK("window-unlinked", ""), + OPTIONS_TABLE_WINDOW_HOOK("window-layout-changed", ""), + OPTIONS_TABLE_WINDOW_HOOK("window-linked", ""), + OPTIONS_TABLE_WINDOW_HOOK("window-pane-changed", ""), + OPTIONS_TABLE_WINDOW_HOOK("window-renamed", ""), + OPTIONS_TABLE_WINDOW_HOOK("window-unlinked", ""), { .name = NULL } }; diff --git a/tmux.1 b/tmux.1 index 956a3911..81a5c613 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3897,6 +3897,7 @@ hook and there are a number of hooks not associated with commands. .Pp Hooks are stored as array options, members of the array are executed in order when the hook is triggered. +Like options different hooks may be global or belong to a session, window or pane. Hooks may be configured with the .Ic set-hook or @@ -3989,8 +3990,8 @@ Run when a window is unlinked from a session. Hooks are managed with these commands: .Bl -tag -width Ds .It Xo Ic set-hook -.Op Fl agRu -.Op Fl t Ar target-session +.Op Fl agpRuw +.Op Fl t Ar target-pane .Ar hook-name .Ar command .Xc @@ -4002,18 +4003,8 @@ unsets) hook .Ar hook-name to .Ar command . -If -.Fl g -is given, -.Em hook-name -is added to the global list of hooks, otherwise it is added to the session -hooks (for -.Ar target-session -with -.Fl t ) . -.Fl a -appends to a hook. -Like options, session hooks inherit from the global ones. +The flags are the same as for +.Ic set-option . .Pp With .Fl R , @@ -4021,12 +4012,12 @@ run .Ar hook-name immediately. .It Xo Ic show-hooks -.Op Fl g -.Op Fl t Ar target-session +.Op Fl gpw +.Op Fl t Ar target-pane .Xc -Shows the global list of hooks with -.Fl g , -otherwise the session hooks. +Shows hooks. +The flags are the same as for +.Ic show-options . .El .Sh MOUSE SUPPORT If the