Hi This seems a reasonable idea to me but I think it should go in cmd_ctx - it is context for THIS invocation of the command, not for all invocations. I'd just add it as members in there personally.
Also I'd maybe call the function prepare() or parse() not context()? Also of course exec() can assume that the function has already been called. Cheers On Mon, Nov 19, 2012 at 01:45:06PM +0000, Thomas Adam wrote: > On Mon, Nov 19, 2012 at 10:32:00AM +0000, Nicholas Marriott wrote: > > Hi > > > > Not sure I follow, can you show me your code? > > See "hook-context.diff" attached. Please ignore any whitespace errors, as > well as any logging since I'm still in the throws of messing with things. > > You should look (in that diff) at the changes to: > > tmux.h > cmd.c > cmd-new-window.c > cmd-split-window.c > > The changes to cmd-{new,split}-window.c just show the intent of what setting > a context may mean. > > > I think check() was meant for parse time so that eg bind-key could > > reject stuff when a key was bound rather when it was pressed, but since > > it is hardly used I'm fine with removing it. Note that bind/unbind use > > it as well as new-session. > > It just means that if we went with this idea of having a context to bind > to, that we can just reuse the original check() field in the struct, without > having to define a new one. > > So before I go ahead and clean check() up, I'll wait for a decision on this > first. > > I am still thinking that augmenting struct cmd_ctx might be a little easier > rather than having a separate struct for this. > > Hope it's clear enough. > > Kindly, > > -- Thomas Adam > diff --git a/autogen.sh b/autogen.sh > index a3cc937..7d39f07 100755 > --- a/autogen.sh > +++ b/autogen.sh > @@ -1,8 +1,8 @@ > #!/bin/sh > # $Id$ > > -[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.10 > -[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.65 > +#[ -z "$AUTOMAKE_VERSION" ] && export AUTOMAKE_VERSION=1.10 > +#[ -z "$AUTOCONF_VERSION" ] && export AUTOCONF_VERSION=2.65 > > die() > { > diff --git a/cmd-attach-session.c b/cmd-attach-session.c > index 18a2024..b4e64cb 100644 > --- a/cmd-attach-session.c > +++ b/cmd-attach-session.c > @@ -35,7 +35,8 @@ > CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, > NULL, > NULL, > - cmd_attach_session_exec > + cmd_attach_session_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-bind-key.c b/cmd-bind-key.c > index 28e94e2..55042d6 100644 > --- a/cmd-bind-key.c > +++ b/cmd-bind-key.c > @@ -39,7 +39,8 @@ > 0, > NULL, > cmd_bind_key_check, > - cmd_bind_key_exec > + cmd_bind_key_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-break-pane.c b/cmd-break-pane.c > index 637105a..9377e03 100644 > --- a/cmd-break-pane.c > +++ b/cmd-break-pane.c > @@ -35,7 +35,8 @@ > 0, > NULL, > NULL, > - cmd_break_pane_exec > + cmd_break_pane_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c > index a94c717..6f4e642 100644 > --- a/cmd-capture-pane.c > +++ b/cmd-capture-pane.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_capture_pane_exec > + cmd_capture_pane_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-choose-buffer.c b/cmd-choose-buffer.c > index 50505ea..e071c78 100644 > --- a/cmd-choose-buffer.c > +++ b/cmd-choose-buffer.c > @@ -39,7 +39,8 @@ > 0, > NULL, > NULL, > - cmd_choose_buffer_exec > + cmd_choose_buffer_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-choose-client.c b/cmd-choose-client.c > index 7c3b926..a15eda9 100644 > --- a/cmd-choose-client.c > +++ b/cmd-choose-client.c > @@ -39,7 +39,8 @@ > 0, > NULL, > NULL, > - cmd_choose_client_exec > + cmd_choose_client_exec, > + NULL > }; > > struct cmd_choose_client_data { > diff --git a/cmd-choose-list.c b/cmd-choose-list.c > index 4c32e69..6cc2e4c 100644 > --- a/cmd-choose-list.c > +++ b/cmd-choose-list.c > @@ -43,7 +43,8 @@ > 0, > NULL, > NULL, > - cmd_choose_list_exec > + cmd_choose_list_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c > index e8da7a4..5b25da8 100644 > --- a/cmd-choose-tree.c > +++ b/cmd-choose-tree.c > @@ -45,7 +45,8 @@ > 0, > NULL, > NULL, > - cmd_choose_tree_exec > + cmd_choose_tree_exec, > + NULL > }; > > const struct cmd_entry cmd_choose_session_entry = { > @@ -55,7 +56,8 @@ > 0, > NULL, > NULL, > - cmd_choose_tree_exec > + cmd_choose_tree_exec, > + NULL > }; > > const struct cmd_entry cmd_choose_window_entry = { > @@ -65,7 +67,8 @@ > 0, > NULL, > NULL, > - cmd_choose_tree_exec > + cmd_choose_tree_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-clear-history.c b/cmd-clear-history.c > index 27f73db..9f06b73 100644 > --- a/cmd-clear-history.c > +++ b/cmd-clear-history.c > @@ -33,7 +33,8 @@ > 0, > NULL, > NULL, > - cmd_clear_history_exec > + cmd_clear_history_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-clock-mode.c b/cmd-clock-mode.c > index 139e715..c9e2091 100644 > --- a/cmd-clock-mode.c > +++ b/cmd-clock-mode.c > @@ -33,7 +33,8 @@ > 0, > NULL, > NULL, > - cmd_clock_mode_exec > + cmd_clock_mode_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c > index ea38035..3352f64 100644 > --- a/cmd-command-prompt.c > +++ b/cmd-command-prompt.c > @@ -43,7 +43,8 @@ > 0, > cmd_command_prompt_key_binding, > NULL, > - cmd_command_prompt_exec > + cmd_command_prompt_exec, > + NULL > }; > > struct cmd_command_prompt_cdata { > diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c > index 329027c..146b1c0 100644 > --- a/cmd-confirm-before.c > +++ b/cmd-confirm-before.c > @@ -39,7 +39,8 @@ > 0, > cmd_confirm_before_key_binding, > NULL, > - cmd_confirm_before_exec > + cmd_confirm_before_exec, > + NULL > }; > > struct cmd_confirm_before_data { > diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c > index 8a5b5fc..470d678 100644 > --- a/cmd-copy-mode.c > +++ b/cmd-copy-mode.c > @@ -34,7 +34,8 @@ > 0, > cmd_copy_mode_key_binding, > NULL, > - cmd_copy_mode_exec > + cmd_copy_mode_exec, > + NULL > }; > > void > diff --git a/cmd-delete-buffer.c b/cmd-delete-buffer.c > index f9d2587..4ebcde9 100644 > --- a/cmd-delete-buffer.c > +++ b/cmd-delete-buffer.c > @@ -35,7 +35,8 @@ > 0, > NULL, > NULL, > - cmd_delete_buffer_exec > + cmd_delete_buffer_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-detach-client.c b/cmd-detach-client.c > index f75b37a..fe3bc67 100644 > --- a/cmd-detach-client.c > +++ b/cmd-detach-client.c > @@ -33,7 +33,8 @@ > CMD_READONLY, > NULL, > NULL, > - cmd_detach_client_exec > + cmd_detach_client_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-display-message.c b/cmd-display-message.c > index e31c110..56a7990 100644 > --- a/cmd-display-message.c > +++ b/cmd-display-message.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_display_message_exec > + cmd_display_message_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-display-panes.c b/cmd-display-panes.c > index 2745ac5..beab873 100644 > --- a/cmd-display-panes.c > +++ b/cmd-display-panes.c > @@ -33,7 +33,8 @@ > 0, > NULL, > NULL, > - cmd_display_panes_exec > + cmd_display_panes_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-find-window.c b/cmd-find-window.c > index 9a0a8a4..509f9da 100644 > --- a/cmd-find-window.c > +++ b/cmd-find-window.c > @@ -50,7 +50,8 @@ > 0, > NULL, > NULL, > - cmd_find_window_exec > + cmd_find_window_exec, > + NULL > }; > > struct cmd_find_window_data { > diff --git a/cmd-has-session.c b/cmd-has-session.c > index 9f19c4d..651c2c1 100644 > --- a/cmd-has-session.c > +++ b/cmd-has-session.c > @@ -33,7 +33,8 @@ > 0, > NULL, > NULL, > - cmd_has_session_exec > + cmd_has_session_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-if-shell.c b/cmd-if-shell.c > index 636cf80..20998b3 100644 > --- a/cmd-if-shell.c > +++ b/cmd-if-shell.c > @@ -41,7 +41,8 @@ > 0, > NULL, > NULL, > - cmd_if_shell_exec > + cmd_if_shell_exec, > + NULL > }; > > struct cmd_if_shell_data { > diff --git a/cmd-join-pane.c b/cmd-join-pane.c > index a2e7a2d..c9d93d2 100644 > --- a/cmd-join-pane.c > +++ b/cmd-join-pane.c > @@ -40,7 +40,8 @@ > 0, > cmd_join_pane_key_binding, > NULL, > - cmd_join_pane_exec > + cmd_join_pane_exec, > + NULL > }; > > const struct cmd_entry cmd_move_pane_entry = { > @@ -50,7 +51,8 @@ > 0, > NULL, > NULL, > - cmd_join_pane_exec > + cmd_join_pane_exec, > + NULL > }; > > void > diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c > index 4f7af2e..86179e7 100644 > --- a/cmd-kill-pane.c > +++ b/cmd-kill-pane.c > @@ -35,7 +35,8 @@ > 0, > NULL, > NULL, > - cmd_kill_pane_exec > + cmd_kill_pane_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-kill-server.c b/cmd-kill-server.c > index 6eb39c4..79bab23 100644 > --- a/cmd-kill-server.c > +++ b/cmd-kill-server.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_kill_server_exec > + cmd_kill_server_exec, > + NULL > }; > > /* ARGSUSED */ > diff --git a/cmd-kill-session.c b/cmd-kill-session.c > index 145f77e..1a280b3 100644 > --- a/cmd-kill-session.c > +++ b/cmd-kill-session.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_kill_session_exec > + cmd_kill_session_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-kill-window.c b/cmd-kill-window.c > index 88f8dd5..72cf6a4 100644 > --- a/cmd-kill-window.c > +++ b/cmd-kill-window.c > @@ -33,7 +33,8 @@ > 0, > NULL, > NULL, > - cmd_kill_window_exec > + cmd_kill_window_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-link-window.c b/cmd-link-window.c > index 0e9c55e..611c510 100644 > --- a/cmd-link-window.c > +++ b/cmd-link-window.c > @@ -35,7 +35,8 @@ > 0, > NULL, > NULL, > - cmd_link_window_exec > + cmd_link_window_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c > index f0d1787..b787249 100644 > --- a/cmd-list-buffers.c > +++ b/cmd-list-buffers.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_list_buffers_exec > + cmd_list_buffers_exec, > + NULL > }; > > /* ARGSUSED */ > diff --git a/cmd-list-clients.c b/cmd-list-clients.c > index 19976cf..45b8fe0 100644 > --- a/cmd-list-clients.c > +++ b/cmd-list-clients.c > @@ -37,7 +37,8 @@ > CMD_READONLY, > NULL, > NULL, > - cmd_list_clients_exec > + cmd_list_clients_exec, > + NULL > }; > > /* ARGSUSED */ > diff --git a/cmd-list-commands.c b/cmd-list-commands.c > index 68e0e80..62c4fcb 100644 > --- a/cmd-list-commands.c > +++ b/cmd-list-commands.c > @@ -33,7 +33,8 @@ > 0, > NULL, > NULL, > - cmd_list_commands_exec > + cmd_list_commands_exec, > + NULL > }; > > /* ARGSUSED */ > diff --git a/cmd-list-keys.c b/cmd-list-keys.c > index 51eeb67..6ee5224 100644 > --- a/cmd-list-keys.c > +++ b/cmd-list-keys.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_list_keys_exec > + cmd_list_keys_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-list-panes.c b/cmd-list-panes.c > index 0934645..4002124 100644 > --- a/cmd-list-panes.c > +++ b/cmd-list-panes.c > @@ -42,7 +42,8 @@ void cmd_list_panes_window(struct cmd *, > 0, > NULL, > NULL, > - cmd_list_panes_exec > + cmd_list_panes_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c > index e8db83e..76b4077 100644 > --- a/cmd-list-sessions.c > +++ b/cmd-list-sessions.c > @@ -37,7 +37,8 @@ > 0, > NULL, > NULL, > - cmd_list_sessions_exec > + cmd_list_sessions_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-list-windows.c b/cmd-list-windows.c > index b36b5ee..76e37ba 100644 > --- a/cmd-list-windows.c > +++ b/cmd-list-windows.c > @@ -40,7 +40,8 @@ void cmd_list_windows_session( > 0, > NULL, > NULL, > - cmd_list_windows_exec > + cmd_list_windows_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c > index aaf23d9..bf50833 100644 > --- a/cmd-load-buffer.c > +++ b/cmd-load-buffer.c > @@ -40,7 +40,8 @@ > 0, > NULL, > NULL, > - cmd_load_buffer_exec > + cmd_load_buffer_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-lock-server.c b/cmd-lock-server.c > index 9d65027..75c625d 100644 > --- a/cmd-lock-server.c > +++ b/cmd-lock-server.c > @@ -37,7 +37,8 @@ > 0, > NULL, > NULL, > - cmd_lock_server_exec > + cmd_lock_server_exec, > + NULL > }; > > const struct cmd_entry cmd_lock_session_entry = { > @@ -47,7 +48,8 @@ > 0, > NULL, > NULL, > - cmd_lock_server_exec > + cmd_lock_server_exec, > + NULL > }; > > const struct cmd_entry cmd_lock_client_entry = { > @@ -57,7 +59,8 @@ > 0, > NULL, > NULL, > - cmd_lock_server_exec > + cmd_lock_server_exec, > + NULL > }; > > /* ARGSUSED */ > diff --git a/cmd-move-window.c b/cmd-move-window.c > index 8bd9ffe..5a0daa7 100644 > --- a/cmd-move-window.c > +++ b/cmd-move-window.c > @@ -35,7 +35,8 @@ > 0, > NULL, > NULL, > - cmd_move_window_exec > + cmd_move_window_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-new-session.c b/cmd-new-session.c > index 8477d9b..cf9f2df 100644 > --- a/cmd-new-session.c > +++ b/cmd-new-session.c > @@ -41,7 +41,8 @@ > CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON, > NULL, > cmd_new_session_check, > - cmd_new_session_exec > + cmd_new_session_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-new-window.c b/cmd-new-window.c > index f8a7612..780238d 100644 > --- a/cmd-new-window.c > +++ b/cmd-new-window.c > @@ -27,6 +27,7 @@ > */ > > enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_ctx *); > +void cmd_new_window_context(struct cmd *, struct cmd_ctx *); > > const struct cmd_entry cmd_new_window_entry = { > "new-window", "neww", > @@ -36,9 +37,29 @@ > 0, > NULL, > NULL, > - cmd_new_window_exec > + cmd_new_window_exec, > + cmd_new_window_context > }; > > +void > +cmd_new_window_context(struct cmd *self, struct cmd_ctx *ctx) > +{ > + struct args *args = self->args; > + struct session *s; > + struct winlink *wl; > + int idx; > + > + if (args_has(args, 'a')) { > + wl = cmd_find_window(ctx, args_get(args, 't'), &s); > + > + self->context->ctx_session = s; > + self->context->ctx_wl = wl; > + } else { > + cmd_find_index(ctx, args_get(args, 't'), &s); > + self->context->ctx_session = s; > + } > +} > + > enum cmd_retval > cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) > { > diff --git a/cmd-paste-buffer.c b/cmd-paste-buffer.c > index ff92783..b93b409 100644 > --- a/cmd-paste-buffer.c > +++ b/cmd-paste-buffer.c > @@ -39,7 +39,8 @@ void cmd_paste_buffer_filter(struct window_pane *, > 0, > NULL, > NULL, > - cmd_paste_buffer_exec > + cmd_paste_buffer_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c > index d2d8500..65c13a6 100644 > --- a/cmd-pipe-pane.c > +++ b/cmd-pipe-pane.c > @@ -42,7 +42,8 @@ > 0, > NULL, > NULL, > - cmd_pipe_pane_exec > + cmd_pipe_pane_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-refresh-client.c b/cmd-refresh-client.c > index 5251812..6cae57d 100644 > --- a/cmd-refresh-client.c > +++ b/cmd-refresh-client.c > @@ -33,7 +33,8 @@ > 0, > NULL, > NULL, > - cmd_refresh_client_exec > + cmd_refresh_client_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-rename-session.c b/cmd-rename-session.c > index 74443bc..c4bca9b 100644 > --- a/cmd-rename-session.c > +++ b/cmd-rename-session.c > @@ -35,7 +35,8 @@ > 0, > NULL, > NULL, > - cmd_rename_session_exec > + cmd_rename_session_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-rename-window.c b/cmd-rename-window.c > index e42dd52..a001aaa 100644 > --- a/cmd-rename-window.c > +++ b/cmd-rename-window.c > @@ -35,7 +35,8 @@ > 0, > NULL, > NULL, > - cmd_rename_window_exec > + cmd_rename_window_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c > index 19ff0e9..dd3a00b 100644 > --- a/cmd-resize-pane.c > +++ b/cmd-resize-pane.c > @@ -36,7 +36,8 @@ > 0, > cmd_resize_pane_key_binding, > NULL, > - cmd_resize_pane_exec > + cmd_resize_pane_exec, > + NULL > }; > > void > diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c > index cf3d930..42e95cf 100644 > --- a/cmd-respawn-pane.c > +++ b/cmd-respawn-pane.c > @@ -37,7 +37,8 @@ > 0, > NULL, > NULL, > - cmd_respawn_pane_exec > + cmd_respawn_pane_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c > index 46d6b0d..482ba46 100644 > --- a/cmd-respawn-window.c > +++ b/cmd-respawn-window.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_respawn_window_exec > + cmd_respawn_window_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-rotate-window.c b/cmd-rotate-window.c > index 74f4c06..a963405 100644 > --- a/cmd-rotate-window.c > +++ b/cmd-rotate-window.c > @@ -34,7 +34,8 @@ > 0, > cmd_rotate_window_key_binding, > NULL, > - cmd_rotate_window_exec > + cmd_rotate_window_exec, > + NULL > }; > > void > diff --git a/cmd-run-shell.c b/cmd-run-shell.c > index 130a541..cd29f4b 100644 > --- a/cmd-run-shell.c > +++ b/cmd-run-shell.c > @@ -40,7 +40,8 @@ > 0, > NULL, > NULL, > - cmd_run_shell_exec > + cmd_run_shell_exec, > + NULL > }; > > struct cmd_run_shell_data { > diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c > index 638c574..2c07997 100644 > --- a/cmd-save-buffer.c > +++ b/cmd-save-buffer.c > @@ -38,7 +38,8 @@ > 0, > NULL, > NULL, > - cmd_save_buffer_exec > + cmd_save_buffer_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-select-layout.c b/cmd-select-layout.c > index 5b234ab..bfbfe44 100644 > --- a/cmd-select-layout.c > +++ b/cmd-select-layout.c > @@ -34,7 +34,8 @@ > 0, > cmd_select_layout_key_binding, > NULL, > - cmd_select_layout_exec > + cmd_select_layout_exec, > + NULL > }; > > const struct cmd_entry cmd_next_layout_entry = { > @@ -44,7 +45,8 @@ > 0, > NULL, > NULL, > - cmd_select_layout_exec > + cmd_select_layout_exec, > + NULL > }; > > const struct cmd_entry cmd_previous_layout_entry = { > @@ -54,7 +56,8 @@ > 0, > NULL, > NULL, > - cmd_select_layout_exec > + cmd_select_layout_exec, > + NULL > }; > > void > diff --git a/cmd-select-pane.c b/cmd-select-pane.c > index 8ebae5f..42e91b6 100644 > --- a/cmd-select-pane.c > +++ b/cmd-select-pane.c > @@ -34,7 +34,8 @@ > 0, > cmd_select_pane_key_binding, > NULL, > - cmd_select_pane_exec > + cmd_select_pane_exec, > + NULL > }; > > const struct cmd_entry cmd_last_pane_entry = { > @@ -44,7 +45,8 @@ > 0, > NULL, > NULL, > - cmd_select_pane_exec > + cmd_select_pane_exec, > + NULL > }; > > void > diff --git a/cmd-select-window.c b/cmd-select-window.c > index 5d87e59..8f601b2 100644 > --- a/cmd-select-window.c > +++ b/cmd-select-window.c > @@ -36,7 +36,8 @@ > 0, > cmd_select_window_key_binding, > NULL, > - cmd_select_window_exec > + cmd_select_window_exec, > + NULL > }; > > const struct cmd_entry cmd_next_window_entry = { > @@ -46,7 +47,8 @@ > 0, > cmd_select_window_key_binding, > NULL, > - cmd_select_window_exec > + cmd_select_window_exec, > + NULL > }; > > const struct cmd_entry cmd_previous_window_entry = { > @@ -56,7 +58,8 @@ > 0, > cmd_select_window_key_binding, > NULL, > - cmd_select_window_exec > + cmd_select_window_exec, > + NULL > }; > > const struct cmd_entry cmd_last_window_entry = { > @@ -66,7 +69,8 @@ > 0, > NULL, > NULL, > - cmd_select_window_exec > + cmd_select_window_exec, > + NULL > }; > > void > diff --git a/cmd-send-keys.c b/cmd-send-keys.c > index ec1007b..1335080 100644 > --- a/cmd-send-keys.c > +++ b/cmd-send-keys.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_send_keys_exec > + cmd_send_keys_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-send-prefix.c b/cmd-send-prefix.c > index 5dded95..0d19922 100644 > --- a/cmd-send-prefix.c > +++ b/cmd-send-prefix.c > @@ -33,7 +33,8 @@ > 0, > NULL, > NULL, > - cmd_send_prefix_exec > + cmd_send_prefix_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-server-info.c b/cmd-server-info.c > index e2e3364..9950a0f 100644 > --- a/cmd-server-info.c > +++ b/cmd-server-info.c > @@ -39,7 +39,8 @@ > 0, > NULL, > NULL, > - cmd_server_info_exec > + cmd_server_info_exec, > + NULL > }; > > /* ARGSUSED */ > diff --git a/cmd-set-buffer.c b/cmd-set-buffer.c > index 1eeaead..a32799f 100644 > --- a/cmd-set-buffer.c > +++ b/cmd-set-buffer.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_set_buffer_exec > + cmd_set_buffer_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-set-environment.c b/cmd-set-environment.c > index 9533626..7906436 100644 > --- a/cmd-set-environment.c > +++ b/cmd-set-environment.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_set_environment_exec > + cmd_set_environment_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-set-hook.c b/cmd-set-hook.c > index d42ead7..9f27c64 100644 > --- a/cmd-set-hook.c > +++ b/cmd-set-hook.c > @@ -34,7 +34,8 @@ > 0, > NULL, > NULL, > - cmd_set_hook_exec > + cmd_set_hook_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-set-option.c b/cmd-set-option.c > index ca99a97..5501b77 100644 > --- a/cmd-set-option.c > +++ b/cmd-set-option.c > @@ -65,7 +65,8 @@ struct options_entry *cmd_set_option_choice(struct cmd *, > struct cmd_ctx *, > 0, > NULL, > NULL, > - cmd_set_option_exec > + cmd_set_option_exec, > + NULL > }; > > const struct cmd_entry cmd_set_window_option_entry = { > @@ -75,7 +76,8 @@ struct options_entry *cmd_set_option_choice(struct cmd *, > struct cmd_ctx *, > 0, > NULL, > NULL, > - cmd_set_option_exec > + cmd_set_option_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-show-buffer.c b/cmd-show-buffer.c > index b345ebc..aad29a6 100644 > --- a/cmd-show-buffer.c > +++ b/cmd-show-buffer.c > @@ -35,7 +35,8 @@ > 0, > NULL, > NULL, > - cmd_show_buffer_exec > + cmd_show_buffer_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-show-environment.c b/cmd-show-environment.c > index 679d5d4..2cdd2bf 100644 > --- a/cmd-show-environment.c > +++ b/cmd-show-environment.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_show_environment_exec > + cmd_show_environment_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-show-hooks.c b/cmd-show-hooks.c > index 08e646e..ea17fa3 100644 > --- a/cmd-show-hooks.c > +++ b/cmd-show-hooks.c > @@ -34,7 +34,8 @@ > 0, > NULL, > NULL, > - cmd_show_hooks_exec > + cmd_show_hooks_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-show-messages.c b/cmd-show-messages.c > index d8c1851..8815878 100644 > --- a/cmd-show-messages.c > +++ b/cmd-show-messages.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_show_messages_exec > + cmd_show_messages_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-show-options.c b/cmd-show-options.c > index d37b791..a063096 100644 > --- a/cmd-show-options.c > +++ b/cmd-show-options.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_show_options_exec > + cmd_show_options_exec, > + NULL > }; > > const struct cmd_entry cmd_show_window_options_entry = { > @@ -46,7 +47,8 @@ > 0, > NULL, > NULL, > - cmd_show_options_exec > + cmd_show_options_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-source-file.c b/cmd-source-file.c > index 12ed3de..bc6ae7d 100644 > --- a/cmd-source-file.c > +++ b/cmd-source-file.c > @@ -35,7 +35,8 @@ > 0, > NULL, > NULL, > - cmd_source_file_exec > + cmd_source_file_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-split-window.c b/cmd-split-window.c > index b40b574..d466015 100644 > --- a/cmd-split-window.c > +++ b/cmd-split-window.c > @@ -27,8 +27,9 @@ > * Split a window (add a new pane). > */ > > -void cmd_split_window_key_binding(struct cmd *, int); > -enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_ctx *); > +void cmd_split_window_key_binding(struct cmd *, int); > +void cmd_split_window_context(struct cmd *, struct cmd_ctx *); > +enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_ctx *); > > const struct cmd_entry cmd_split_window_entry = { > "split-window", "splitw", > @@ -38,10 +39,26 @@ > 0, > cmd_split_window_key_binding, > NULL, > - cmd_split_window_exec > + cmd_split_window_exec, > + cmd_split_window_context > }; > > void > +cmd_split_window_context(struct cmd *self, struct cmd_ctx *ctx) > +{ > + struct session *s; > + struct window_pane *wp; > + struct winlink *wl; > + struct args *args = self->args; > + > + wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp); > + log_debug("I GOT HERE"); > + self->context->ctx_session = s; > + self->context->ctx_window_pane = wp; > + self->context->ctx_wl = wl; > +} > + > +void > cmd_split_window_key_binding(struct cmd *self, int key) > { > self->args = args_create(0); > diff --git a/cmd-start-server.c b/cmd-start-server.c > index 7da1337..39767d6 100644 > --- a/cmd-start-server.c > +++ b/cmd-start-server.c > @@ -33,7 +33,8 @@ > CMD_STARTSERVER, > NULL, > NULL, > - cmd_start_server_exec > + cmd_start_server_exec, > + NULL > }; > > /* ARGSUSED */ > diff --git a/cmd-suspend-client.c b/cmd-suspend-client.c > index 95278f9..82f91e9 100644 > --- a/cmd-suspend-client.c > +++ b/cmd-suspend-client.c > @@ -36,7 +36,8 @@ > 0, > NULL, > NULL, > - cmd_suspend_client_exec > + cmd_suspend_client_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-swap-pane.c b/cmd-swap-pane.c > index 42fe2fc..971db52 100644 > --- a/cmd-swap-pane.c > +++ b/cmd-swap-pane.c > @@ -36,7 +36,8 @@ > 0, > cmd_swap_pane_key_binding, > NULL, > - cmd_swap_pane_exec > + cmd_swap_pane_exec, > + NULL > }; > > void > diff --git a/cmd-swap-window.c b/cmd-swap-window.c > index f0c9ffe..61509c5 100644 > --- a/cmd-swap-window.c > +++ b/cmd-swap-window.c > @@ -35,7 +35,8 @@ > 0, > NULL, > NULL, > - cmd_swap_window_exec > + cmd_swap_window_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-switch-client.c b/cmd-switch-client.c > index 1ca0c41..3f44e12 100644 > --- a/cmd-switch-client.c > +++ b/cmd-switch-client.c > @@ -37,7 +37,8 @@ > CMD_READONLY, > cmd_switch_client_key_binding, > NULL, > - cmd_switch_client_exec > + cmd_switch_client_exec, > + NULL > }; > > void > diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c > index 261ded4..8b6c9d2 100644 > --- a/cmd-unbind-key.c > +++ b/cmd-unbind-key.c > @@ -37,7 +37,8 @@ > 0, > NULL, > cmd_unbind_key_check, > - cmd_unbind_key_exec > + cmd_unbind_key_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd-unlink-window.c b/cmd-unlink-window.c > index 19731ba..f95f454 100644 > --- a/cmd-unlink-window.c > +++ b/cmd-unlink-window.c > @@ -33,7 +33,8 @@ > 0, > NULL, > NULL, > - cmd_unlink_window_exec > + cmd_unlink_window_exec, > + NULL > }; > > enum cmd_retval > diff --git a/cmd.c b/cmd.c > index f88c071..b872c97 100644 > --- a/cmd.c > +++ b/cmd.c > @@ -209,6 +209,22 @@ enum cmd_retval run_hook_after(struct hooks *, struct > cmd *, > free(argv); > } > > +struct cmd_context * > +cmd_context_create(struct cmd_ctx *ctx) > +{ > + struct cmd_context *cmd_context; > + > + cmd_context = xmalloc(sizeof *cmd_context); > + cmd_context->ctx_client = (ctx->curclient != NULL) ? > + ctx->curclient : NULL; > + cmd_context->ctx_session = (ctx->curclient != NULL) ? > + ctx->curclient->session : NULL; > + cmd_context->ctx_window = NULL; > + cmd_context->ctx_window_pane = NULL; > + > + return (cmd_context); > +} > + > struct cmd * > cmd_parse(int argc, char **argv, char **cause) > { > @@ -263,6 +279,7 @@ struct cmd * > cmd = xmalloc(sizeof *cmd); > cmd->entry = entry; > cmd->args = args; > + > return (cmd); > > ambiguous: > @@ -295,6 +312,10 @@ enum cmd_retval > > memcpy(&hook_ctx, ctx, sizeof hook_ctx); > hook_ctx.cmdclient = NULL; > + if (hooks != &global_hooks && cmd->context != NULL && > cmd->context->ctx_client != NULL) { > + log_debug("SETTING CLIENT"); > + hook_ctx.curclient = cmd->context->ctx_client; > + } > xasprintf(&hook_name, "before-%s", cmd->entry->name); > > retval = hooks_call(hooks, hook_name, &hook_ctx); > @@ -314,6 +335,8 @@ enum cmd_retval > > memcpy(&hook_ctx, ctx, sizeof hook_ctx); > hook_ctx.cmdclient = NULL; > + if (hooks != &global_hooks && cmd->context != NULL && > cmd->context->ctx_client != NULL) > + hook_ctx.curclient = cmd->context->ctx_client; > xasprintf(&hook_name, "after-%s", cmd->entry->name); > > retval = hooks_call(hooks, hook_name, &hook_ctx); > @@ -331,10 +354,28 @@ enum cmd_retval > struct hooks *hooks; > enum cmd_retval retval, hooks_retval; > > - if (ctx->curclient != NULL) > - s = ctx->curclient->session; > + hooks = &global_hooks; > + cmd->context = cmd_context_create(ctx); > + if (cmd->entry->context != NULL) { > + log_debug("Setting CONTEXT hooks"); > + cmd->entry->context(cmd, ctx); > + > + /* > + * Set the hooks to be the session the hooks will run > + * in, which is derived from parsing the command > + * flags, and setting the context. > + */ > + if (cmd->context != NULL && cmd->context->ctx_session != NULL) { > + log_debug("HOOKS: SETTING TO SESSION <<%s>>", > + cmd->context->ctx_session->name); > + hooks = &cmd->context->ctx_session->hooks; > + } > + } > + if (hooks == &global_hooks) > + log_debug("HOOKS: USING GLOBAL HOOKS"); > + else if (cmd->context != NULL && hooks == > &cmd->context->ctx_session->hooks) > + log_debug("HOOKS: USING SESSION HOOK"); > > - hooks = (s == NULL) ? &global_hooks : &s->hooks; > > /* Call any hooks set to run before the intended command. */ > hooks_retval = run_hook_before(hooks, cmd, ctx); > diff --git a/tmux.h b/tmux.h > index 34f9616..f48c129 100644 > --- a/tmux.h > +++ b/tmux.h > @@ -1400,6 +1400,7 @@ struct cmd_ctx { > struct cmd { > const struct cmd_entry *entry; > struct args *args; > + struct cmd_context *context; > > TAILQ_ENTRY(cmd) qentry; > }; > @@ -1415,25 +1416,34 @@ enum cmd_retval { > CMD_RETURN_ATTACH > }; > > +struct cmd_context { > + struct client *ctx_client; > + struct session *ctx_session; > + struct window *ctx_window; > + struct winlink *ctx_wl; > + struct window_pane *ctx_window_pane; > +}; > + > struct cmd_entry { > - const char *name; > - const char *alias; > + const char *name; > + const char *alias; > > - const char *args_template; > - int args_lower; > - int args_upper; > + const char *args_template; > + int args_lower; > + int args_upper; > > - const char *usage; > + const char *usage; > > #define CMD_STARTSERVER 0x1 > #define CMD_CANTNEST 0x2 > #define CMD_SENDENVIRON 0x4 > #define CMD_READONLY 0x8 > - int flags; > + int flags; > > - void (*key_binding)(struct cmd *, int); > - int (*check)(struct args *); > - enum cmd_retval (*exec)(struct cmd *, struct cmd_ctx *); > + void (*key_binding)(struct cmd *, int); > + int (*check)(struct args *); > + enum cmd_retval (*exec)(struct cmd *, struct cmd_ctx *); > + void (*context)(struct cmd *, struct cmd_ctx *); > }; > > /* Key binding. */ > @@ -1739,6 +1749,7 @@ long long args_strtonum( > int cmd_unpack_argv(char *, size_t, int, char ***); > char **cmd_copy_argv(int, char *const *); > void cmd_free_argv(int, char **); > +struct cmd_context *cmd_context_create(struct cmd_ctx *); > struct cmd *cmd_parse(int, char **, char **); > enum cmd_retval cmd_exec(struct cmd *, struct cmd_ctx *); > void cmd_free(struct cmd *); ------------------------------------------------------------------------------ Monitor your physical, virtual and cloud infrastructure from a single web console. Get in-depth insight into apps, servers, databases, vmware, SAP, cloud infrastructure, etc. Download 30-day Free Trial. Pricing starts from $795 for 25 servers or applications! http://p.sf.net/sfu/zoho_dev2dev_nov _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users