Instead of every command resolving the target (-t or -s) itself, prepare

the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.
This commit is contained in:
nicm
2015-12-13 14:32:38 +00:00
parent 5ed17e84fa
commit 4a4daf1303
56 changed files with 606 additions and 599 deletions

42
tmux.h
View File

@ -1293,6 +1293,20 @@ struct args {
char **argv;
};
/* Context for a command about to be executed. */
struct cmd_state_flag {
struct session *s;
struct winlink *wl;
struct window_pane *wp;
int idx;
};
struct cmd_state {
struct client *c;
struct cmd_state_flag tflag;
struct cmd_state_flag sflag;
};
/* Command and list of commands. */
struct cmd {
const struct cmd_entry *entry;
@ -1343,6 +1357,8 @@ struct cmd_q {
struct cmd_q_item *item;
struct cmd *cmd;
struct cmd_state state;
time_t time;
u_int number;
@ -1365,10 +1381,31 @@ struct cmd_entry {
#define CMD_STARTSERVER 0x1
#define CMD_READONLY 0x2
#define CMD_SESSION_T 0x4
#define CMD_SESSION_S 0x8
#define CMD_WINDOW_T 0x10
#define CMD_WINDOW_S 0x20
#define CMD_PANE_T 0x40
#define CMD_PANE_S 0x80
#define CMD_CLIENT_T 0x100
#define CMD_CLIENT_C 0x200
#define CMD_INDEX_T 0x400
#define CMD_INDEX_S 0x800
#define CMD_CANFAIL 0x1000
#define CMD_PREFERUNATTACHED 0x2000
#define CMD_MOVEW_R 0x4000 /* for movew -r only */
#define CMD_PANE_MARKED_S 0x8000
#define CMD_PANE_MARKED_T 0x10000
#define CMD_WINDOW_MARKED_T 0x20000
#define CMD_WINDOW_MARKED_S 0x40000
int flags;
enum cmd_retval (*exec)(struct cmd *, struct cmd_q *);
};
#define CMD_ALL_T (CMD_SESSION_T|CMD_WINDOW_T|CMD_PANE_T|CMD_INDEX_T| \
CMD_MOVEW_R|CMD_PANE_MARKED_T|CMD_WINDOW_MARKED_T)
#define CMD_ALL_S (CMD_SESSION_S|CMD_WINDOW_S|CMD_PANE_S|CMD_INDEX_S| \
CMD_PANE_MARKED_S|CMD_WINDOW_MARKED_S)
/* Key binding and key table. */
struct key_binding {
@ -1718,6 +1755,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 **);
int cmd_prepare_state(struct cmd *, struct cmd_q *);
char *cmd_print(struct cmd *);
int cmd_mouse_at(struct window_pane *, struct mouse_event *,
u_int *, u_int *, int);
@ -1728,8 +1766,8 @@ char *cmd_template_replace(const char *, const char *, int);
extern const struct cmd_entry *cmd_table[];
/* cmd-attach-session.c */
enum cmd_retval cmd_attach_session(struct cmd_q *, const char *, int, int,
const char *, int);
enum cmd_retval cmd_attach_session(struct cmd_q *, int, int, const char *,
int);
/* cmd-list.c */
struct cmd_list *cmd_list_parse(int, char **, const char *, u_int, char **);