Skip to content

Commit

Permalink
Change so that the appropriate hooks for windows and panes belong to
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nicm committed Apr 13, 2020
1 parent ad38ef6 commit 9cbe967
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 37 deletions.
6 changes: 3 additions & 3 deletions cmd-set-option.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmd-show-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
42 changes: 30 additions & 12 deletions options-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand All @@ -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. */
Expand Down Expand Up @@ -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 }
};
29 changes: 10 additions & 19 deletions tmux.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -4002,31 +4003,21 @@ 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 ,
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
Expand Down

0 comments on commit 9cbe967

Please sign in to comment.