Commands now set their running context separately from executing. The state is used at execution time of commands, and by separating this out, the command state can be queried for any hooked commands. --- cmd.c | 32 ++++++++++++++++++++++++++++++++ tmux.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+)
diff --git a/cmd.c b/cmd.c index eeffe4c..66716bd 100644 --- a/cmd.c +++ b/cmd.c @@ -312,6 +312,38 @@ usage: return (NULL); } +void +cmd_prepare(struct cmd *cmd, struct cmd_q *cmdq) +{ + struct args *args = cmd->args; + const char *tflag = args_get(args, 't'); + struct cmd_state *state = &cmdq->state; + + /* FIXME: Handle this! What should happen during cfg_load? */ + if (cfg_finished == 0) + return; + + /* + * Prepare the context for the command. It might be the case that a + * hooked command is being called. If this command doesn't have a + * tflag, use the same one as the command being hooked. + */ + if (tflag == NULL && cmdq->state.prior_tflag != NULL) + tflag = state->prior_tflag; + + if (cmd->entry->flags & CMD_PREPARESESSION) + state->s = cmd_find_session(cmdq, tflag, 0); + if (cmd->entry->flags & CMD_PREPAREWINDOW) + state->wl = cmd_find_window(cmdq, tflag, NULL); + if (cmd->entry->flags & CMD_PREPAREPANE) + state->wl = cmd_find_pane(cmdq, tflag, &state->s, &state->wp); + if (cmd->entry->flags & CMD_PREPARECLIENT) + state->c = cmd_find_client(cmdq, tflag, 0); + + if (cmd->entry->prepare != NULL) + cmd->entry->prepare(cmd, cmdq); +} + size_t cmd_print(struct cmd *cmd, char *buf, size_t len) { diff --git a/tmux.h b/tmux.h index 8fbda56..ab191c6 100644 --- a/tmux.h +++ b/tmux.h @@ -1347,6 +1347,31 @@ struct args { char **argv; }; +/* Context for a command about to be executed. */ +struct cmd_state { + struct client *c; + + struct session *s; + struct session *s2; + + struct winlink *wl; + struct winlink *wl2; + + struct window *w; + struct window *w2; + + struct window_pane *wp; + struct window_pane *wp2; + + int idx; + + const char *tflag; + const char *sflag; + + const char *prior_tflag; + const char *prior_sflag; +}; + /* Command and list of commands. */ struct cmd { const struct cmd_entry *entry; @@ -1391,6 +1416,7 @@ struct cmd_q { struct cmd_q_items queue; struct cmd_q_item *item; struct cmd *cmd; + struct cmd_state state; time_t time; u_int number; @@ -1415,9 +1441,14 @@ struct cmd_entry { #define CMD_STARTSERVER 0x1 #define CMD_CANTNEST 0x2 #define CMD_READONLY 0x4 +#define CMD_PREPARESESSION 0x8 +#define CMD_PREPAREWINDOW 0x10 +#define CMD_PREPAREPANE 0x20 +#define CMD_PREPARECLIENT 0x40 int flags; enum cmd_retval (*exec)(struct cmd *, struct cmd_q *); + void (*prepare)(struct cmd *, struct cmd_q *); }; /* Key binding. */ @@ -1713,6 +1744,7 @@ char **cmd_copy_argv(int, char **); void cmd_free_argv(int, char **); char *cmd_stringify_argv(int, char **); struct cmd *cmd_parse(int, char **, const char *, u_int, char **); +void cmd_prepare(struct cmd *, struct cmd_q *); size_t cmd_print(struct cmd *, char *, size_t); struct session *cmd_current_session(struct cmd_q *, int); struct client *cmd_current_client(struct cmd_q *); -- 2.1.4 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users