summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2015-02-05 10:29:43 +0000
committernicm <nicm>2015-02-05 10:29:43 +0000
commit4946f74253de52f10beb023d4c5b88bafdb11ec4 (patch)
tree4210eaf66f9aee7998ec558ce34a1c9454ae0b71
parente5d9ceff18e37320b9243d24204a0a79d77172e4 (diff)
Wrap all the individual format_* calls in a single format_defaults
functions.
-rw-r--r--cmd-attach-session.c14
-rw-r--r--cmd-break-pane.c7
-rw-r--r--cmd-choose-buffer.c2
-rw-r--r--cmd-choose-client.c3
-rw-r--r--cmd-display-message.c6
-rw-r--r--cmd-find-window.c4
-rw-r--r--cmd-if-shell.c7
-rw-r--r--cmd-list-buffers.c2
-rw-r--r--cmd-list-clients.c3
-rw-r--r--cmd-list-panes.c4
-rw-r--r--cmd-list-sessions.c2
-rw-r--r--cmd-list-windows.c4
-rw-r--r--cmd-new-session.c9
-rw-r--r--cmd-new-window.c14
-rw-r--r--cmd-run-shell.c7
-rw-r--r--cmd-split-window.c14
-rw-r--r--control-notify.c2
-rw-r--r--format.c48
-rw-r--r--names.c4
-rw-r--r--status.c9
-rw-r--r--tmux.h12
-rw-r--r--window-choose.c6
-rw-r--r--window-copy.c4
23 files changed, 78 insertions, 109 deletions
diff --git a/cmd-attach-session.c b/cmd-attach-session.c
index 160f2a8f..a67ec82c 100644
--- a/cmd-attach-session.c
+++ b/cmd-attach-session.c
@@ -106,11 +106,8 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
if (cflag != NULL) {
ft = format_create();
- if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
- format_client(ft, c);
- format_session(ft, s);
- format_winlink(ft, s, s->curw);
- format_window_pane(ft, s->curw->window->active);
+ format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
+ NULL, NULL);
cp = format_expand(ft, cflag);
format_free(ft);
@@ -139,11 +136,8 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag,
if (cflag != NULL) {
ft = format_create();
- if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
- format_client(ft, c);
- format_session(ft, s);
- format_winlink(ft, s, s->curw);
- format_window_pane(ft, s->curw->window->active);
+ format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s,
+ NULL, NULL);
cp = format_expand(ft, cflag);
format_free(ft);
diff --git a/cmd-break-pane.c b/cmd-break-pane.c
index 0025167f..a1da0a3a 100644
--- a/cmd-break-pane.c
+++ b/cmd-break-pane.c
@@ -49,7 +49,6 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
char *name;
char *cause;
int base_idx;
- struct client *c;
struct format_tree *ft;
const char *template;
char *cp;
@@ -90,11 +89,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
template = BREAK_PANE_TEMPLATE;
ft = format_create();
- if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
- format_client(ft, c);
- format_session(ft, s);
- format_winlink(ft, s, wl);
- format_window_pane(ft, wp);
+ format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, wl, wp);
cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp);
diff --git a/cmd-choose-buffer.c b/cmd-choose-buffer.c
index 19f5fba2..33125a0e 100644
--- a/cmd-choose-buffer.c
+++ b/cmd-choose-buffer.c
@@ -83,7 +83,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
cdata->idx = idx;
cdata->ft_template = xstrdup(template);
- format_paste_buffer(cdata->ft, pb, utf8flag);
+ format_defaults_paste_buffer(cdata->ft, pb, utf8flag);
xasprintf(&action_data, "%s", pb->name);
cdata->command = cmd_template_replace(action, action_data, 1);
diff --git a/cmd-choose-client.c b/cmd-choose-client.c
index 5a1892f4..3002f7ba 100644
--- a/cmd-choose-client.c
+++ b/cmd-choose-client.c
@@ -94,8 +94,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq)
cdata->ft_template = xstrdup(template);
format_add(cdata->ft, "line", "%u", i);
- format_session(cdata->ft, c1->session);
- format_client(cdata->ft, c1);
+ format_defaults(cdata->ft, c1, NULL, NULL, NULL);
cdata->command = cmd_template_replace(action, c1->tty.path, 1);
diff --git a/cmd-display-message.c b/cmd-display-message.c
index f3547b00..0a61fd1e 100644
--- a/cmd-display-message.c
+++ b/cmd-display-message.c
@@ -92,11 +92,7 @@ cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq)
template = DISPLAY_MESSAGE_TEMPLATE;
ft = format_create();
- if (c != NULL)
- format_client(ft, c);
- format_session(ft, s);
- format_winlink(ft, s, wl);
- format_window_pane(ft, wp);
+ format_defaults(ft, c, s, wl, wp);
t = time(NULL);
len = strftime(out, sizeof out, template, localtime(&t));
diff --git a/cmd-find-window.c b/cmd-find-window.c
index 88e48798..25155f7b 100644
--- a/cmd-find-window.c
+++ b/cmd-find-window.c
@@ -194,9 +194,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
format_add(cdata->ft, "line", "%u", i);
format_add(cdata->ft, "window_find_matches", "%s",
ARRAY_ITEM(&find_list, i).list_ctx);
- format_session(cdata->ft, s);
- format_winlink(cdata->ft, s, wm);
- format_window_pane(cdata->ft, wm->window->active);
+ format_defaults(cdata->ft, NULL, s, wm, NULL);
window_choose_add(wl->window->active, cdata);
}
diff --git a/cmd-if-shell.c b/cmd-if-shell.c
index 15432919..8c6620da 100644
--- a/cmd-if-shell.c
+++ b/cmd-if-shell.c
@@ -76,12 +76,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
}
ft = format_create();
- if (s != NULL)
- format_session(ft, s);
- if (s != NULL && wl != NULL)
- format_winlink(ft, s, wl);
- if (wp != NULL)
- format_window_pane(ft, wp);
+ format_defaults(ft, NULL, s, wl, wp);
shellcmd = format_expand(ft, args->argv[0]);
format_free(ft);
diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c
index 8eb1610f..37571b80 100644
--- a/cmd-list-buffers.c
+++ b/cmd-list-buffers.c
@@ -55,7 +55,7 @@ cmd_list_buffers_exec(unused struct cmd *self, struct cmd_q *cmdq)
pb = NULL;
while ((pb = paste_walk(pb)) != NULL) {
ft = format_create();
- format_paste_buffer(ft, pb, 0);
+ format_defaults_paste_buffer(ft, pb, 0);
line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line);
diff --git a/cmd-list-clients.c b/cmd-list-clients.c
index 292be722..893a6d05 100644
--- a/cmd-list-clients.c
+++ b/cmd-list-clients.c
@@ -74,8 +74,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq)
ft = format_create();
format_add(ft, "line", "%u", i);
- format_session(ft, c->session);
- format_client(ft, c);
+ format_defaults(ft, c, NULL, NULL, NULL);
line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line);
diff --git a/cmd-list-panes.c b/cmd-list-panes.c
index 7f62177b..bd34344f 100644
--- a/cmd-list-panes.c
+++ b/cmd-list-panes.c
@@ -128,9 +128,7 @@ cmd_list_panes_window(struct cmd *self,
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
ft = format_create();
format_add(ft, "line", "%u", n);
- format_session(ft, s);
- format_winlink(ft, s, wl);
- format_window_pane(ft, wp);
+ format_defaults(ft, NULL, s, wl, wp);
line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line);
diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c
index ea8f3e32..8ad55d03 100644
--- a/cmd-list-sessions.c
+++ b/cmd-list-sessions.c
@@ -63,7 +63,7 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq)
RB_FOREACH(s, sessions, &sessions) {
ft = format_create();
format_add(ft, "line", "%u", n);
- format_session(ft, s);
+ format_defaults(ft, NULL, s, NULL, NULL);
line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line);
diff --git a/cmd-list-windows.c b/cmd-list-windows.c
index 5f73e8d2..3f6b2a4c 100644
--- a/cmd-list-windows.c
+++ b/cmd-list-windows.c
@@ -107,9 +107,7 @@ cmd_list_windows_session(
RB_FOREACH(wl, winlinks, &s->windows) {
ft = format_create();
format_add(ft, "line", "%u", n);
- format_session(ft, s);
- format_winlink(ft, s, wl);
- format_window_pane(ft, wl->window->active);
+ format_defaults(ft, NULL, s, wl, NULL);
line = format_expand(ft, template);
cmdq_print(cmdq, "%s", line);
diff --git a/cmd-new-session.c b/cmd-new-session.c
index e244f885..ec292fa8 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -119,8 +119,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
/* Get the new session working directory. */
if (args_has(args, 'c')) {
ft = format_create();
- if ((c0 = cmd_find_client(cmdq, NULL, 1)) != NULL)
- format_client(ft, c0);
+ format_defaults(ft, cmd_find_client(cmdq, NULL, 1), NULL, NULL,
+ NULL);
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
@@ -287,9 +287,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
template = NEW_SESSION_TEMPLATE;
ft = format_create();
- if ((c0 = cmd_find_client(cmdq, NULL, 1)) != NULL)
- format_client(ft, c0);
- format_session(ft, s);
+ format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL,
+ NULL);
cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp);
diff --git a/cmd-new-window.c b/cmd-new-window.c
index 7f14b21a..be3f43a1 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -109,11 +109,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 'c')) {
ft = format_create();
- if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
- format_client(ft, c);
- format_session(ft, s);
- format_winlink(ft, s, s->curw);
- format_window_pane(ft, s->curw->window->active);
+ format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL,
+ NULL);
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
@@ -173,11 +170,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
template = NEW_WINDOW_TEMPLATE;
ft = format_create();
- if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
- format_client(ft, c);
- format_session(ft, s);
- format_winlink(ft, s, wl);
- format_window_pane(ft, wl->window->active);
+ format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, wl,
+ NULL);
cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp);
diff --git a/cmd-run-shell.c b/cmd-run-shell.c
index b47c2827..5d6d178b 100644
--- a/cmd-run-shell.c
+++ b/cmd-run-shell.c
@@ -93,12 +93,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
}
ft = format_create();
- if (s != NULL)
- format_session(ft, s);
- if (s != NULL && wl != NULL)
- format_winlink(ft, s, wl);
- if (wp != NULL)
- format_window_pane(ft, wp);
+ format_defaults(ft, NULL, s, wl, wp);
shellcmd = format_expand(ft, args->argv[0]);
format_free(ft);
diff --git a/cmd-split-window.c b/cmd-split-window.c
index 7e34e523..d26ce821 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -89,11 +89,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(args, 'c')) {
ft = format_create();
- if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
- format_client(ft, c);
- format_session(ft, s);
- format_winlink(ft, s, s->curw);
- format_window_pane(ft, s->curw->window->active);
+ format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL,
+ NULL);
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
@@ -181,11 +178,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
template = SPLIT_WINDOW_TEMPLATE;
ft = format_create();
- if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
- format_client(ft, c);
- format_session(ft, s);
- format_winlink(ft, s, wl);
- format_window_pane(ft, new_wp);
+ format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, wl,
+ new_wp);
cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp);
diff --git a/control-notify.c b/control-notify.c
index 4ea1570b..747ef5b4 100644
--- a/control-notify.c
+++ b/control-notify.c
@@ -88,7 +88,7 @@ control_notify_window_layout_changed(struct window *w)
ft = format_create();
wl = winlink_find_by_window(&s->windows, w);
if (wl != NULL) {
- format_winlink(ft, c->session, wl);
+ format_defaults(ft, c, NULL, wl, NULL);
control_write(c, "%s", format_expand(ft, template));
}
format_free(ft);
diff --git a/format.c b/format.c
index ea0a91b1..f7cd3596 100644
--- a/format.c
+++ b/format.c
@@ -38,7 +38,12 @@
int format_replace(struct format_tree *, const char *, size_t, char **,
size_t *, size_t *);
char *format_get_command(struct window_pane *);
-void format_window_pane_tabs(struct format_tree *, struct window_pane *);
+
+void format_defaults_pane_tabs(struct format_tree *, struct window_pane *);
+void format_defaults_session(struct format_tree *, struct session *);
+void format_defaults_client(struct format_tree *, struct client *);
+void format_defaults_winlink(struct format_tree *, struct session *,
+ struct winlink *);
/* Entry in format tree. */
struct format_entry {
@@ -418,9 +423,31 @@ format_get_command(struct window_pane *wp)
return (out);
}
+/* Set defaults for any of arguments that are not NULL. */
+void
+format_defaults(struct format_tree *ft, struct client *c, struct session *s,
+ struct winlink *wl, struct window_pane *wp)
+{
+ if (s == NULL && c != NULL)
+ s = c->session;
+ if (wl == NULL && s != NULL)
+ wl = s->curw;
+ if (wp == NULL && wl != NULL)
+ wp = wl->window->active;
+
+ if (c != NULL)
+ format_defaults_client(ft, c);
+ if (s != NULL)
+ format_defaults_session(ft, s);
+ if (s != NULL && wl != NULL)
+ format_defaults_winlink(ft, s, wl);
+ if (wp != NULL)
+ format_defaults_pane(ft, wp);
+}
+
/* Set default format keys for a session. */
void
-format_session(struct format_tree *ft, struct session *s)
+format_defaults_session(struct format_tree *ft, struct session *s)
{
struct session_group *sg;
char *tim;
@@ -451,7 +478,7 @@ format_session(struct format_tree *ft, struct session *s)
/* Set default format keys for a client. */
void
-format_client(struct format_tree *ft, struct client *c)
+format_defaults_client(struct format_tree *ft, struct client *c)
{
char *tim;
time_t t;
@@ -501,7 +528,7 @@ format_client(struct format_tree *ft, struct client *c)
/* Set default format keys for a window. */
void
-format_window(struct format_tree *ft, struct window *w)
+format_defaults_window(struct format_tree *ft, struct window *w)
{
char *layout;
@@ -523,7 +550,8 @@ format_window(struct format_tree *ft, struct window *w)
/* Set default format keys for a winlink. */
void
-format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
+format_defaults_winlink(struct format_tree *ft, struct session *s,
+ struct winlink *wl)
{
struct window *w = wl->window;
char *flags;
@@ -533,7 +561,7 @@ format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
flags = window_printable_flags(s, wl);
- format_window(ft, w);
+ format_defaults_window(ft, w);
format_add(ft, "window_index", "%d", wl->idx);
format_add(ft, "window_flags", "%s", flags);
@@ -553,7 +581,7 @@ format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
/* Add window pane tabs. */
void
-format_window_pane_tabs(struct format_tree *ft, struct window_pane *wp)
+format_defaults_pane_tabs(struct format_tree *ft, struct window_pane *wp)
{
struct evbuffer *buffer;
u_int i;
@@ -575,7 +603,7 @@ format_window_pane_tabs(struct format_tree *ft, struct window_pane *wp)
/* Set default format keys for a window pane. */
void
-format_window_pane(struct format_tree *ft, struct window_pane *wp)
+format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
{
struct grid *gd = wp->base.grid;
struct grid_line *gl;
@@ -665,12 +693,12 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp)
format_add(ft, "mouse_utf8_flag", "%d",
!!(wp->base.mode & MODE_MOUSE_UTF8));
- format_window_pane_tabs(ft, wp);
+ format_defaults_pane_tabs(ft, wp);
}
/* Set default format keys for paste buffer. */
void
-format_paste_buffer(struct format_tree *ft, struct paste_buffer *pb,
+format_defaults_paste_buffer(struct format_tree *ft, struct paste_buffer *pb,
int utf8flag)
{
char *s;
diff --git a/names.c b/names.c
index 8e01d347..1ceb83c0 100644
--- a/names.c
+++ b/names.c
@@ -86,8 +86,8 @@ format_window_name(struct window *w)
char *fmt, *name;
ft = format_create();
- format_window(ft, w);
- format_window_pane(ft, w->active);
+ format_defaults_window(ft, w);
+ format_defaults_pane(ft, w->active);
fmt = options_get_string(&w->options, "automatic-rename-format");
name = format_expand(ft, fmt);
diff --git a/status.c b/status.c
index dc6d390e..93dc0217 100644
--- a/status.c
+++ b/status.c
@@ -474,14 +474,7 @@ status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t,
*optr = '\0';
ft = format_create();
- if (c != NULL)
- format_client(ft, c);
- if (s != NULL)
- format_session(ft, s);
- if (s != NULL && wl != NULL)
- format_winlink(ft, s, wl);
- if (wp != NULL)
- format_window_pane(ft, wp);
+ format_defaults(ft, c, s, wl, wp);
expanded = format_expand(ft, out);
format_free(ft);
return (expanded);
diff --git a/tmux.h b/tmux.h
index da8d3bfe..c9be497a 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1513,14 +1513,12 @@ void printflike(3, 4) format_add(struct format_tree *, const char *,
const char *, ...);
const char *format_find(struct format_tree *, const char *);
char *format_expand(struct format_tree *, const char *);
-void format_session(struct format_tree *, struct session *);
-void format_client(struct format_tree *, struct client *);
-void format_window(struct format_tree *, struct window *);
-void format_winlink(struct format_tree *, struct session *,
- struct winlink *);
-void format_window_pane(struct format_tree *,
+void format_defaults(struct format_tree *, struct client *,
+ struct session *, struct winlink *, struct window_pane *);
+void format_defaults_window(struct format_tree *, struct window *);
+void format_defaults_pane(struct format_tree *,
struct window_pane *);
-void format_paste_buffer(struct format_tree *,
+void format_defaults_paste_buffer(struct format_tree *,
struct paste_buffer *, int);
/* mode-key.c */
diff --git a/window-choose.c b/window-choose.c
index 0d724746..69141676 100644
--- a/window-choose.c
+++ b/window-choose.c
@@ -919,7 +919,7 @@ window_choose_add_session(struct window_pane *wp, struct client *c,
wcd->ft_template = xstrdup(template);
format_add(wcd->ft, "line", "%u", idx);
- format_session(wcd->ft, s);
+ format_defaults(wcd->ft, NULL, s, NULL, NULL);
wcd->command = cmd_template_replace(action, s->name, 1);
@@ -946,9 +946,7 @@ window_choose_add_window(struct window_pane *wp, struct client *c,
wcd->ft_template = xstrdup(template);
format_add(wcd->ft, "line", "%u", idx);
- format_session(wcd->ft, s);
- format_winlink(wcd->ft, s, wl);
- format_window_pane(wcd->ft, wl->window->active);
+ format_defaults(wcd->ft, NULL, s, wl, NULL);
xasprintf(&expanded, "%s:%d", s->name, wl->idx);
wcd->command = cmd_template_replace(action, expanded, 1);
diff --git a/window-copy.c b/window-copy.c
index 6447a2d5..223df88a 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -1512,9 +1512,7 @@ window_copy_copy_pipe(struct window_pane *wp, struct session *sess,
return;
ft = format_create();
- format_window_pane(ft, wp);
- if (sess != NULL)
- format_session(ft, sess);
+ format_defaults(ft, NULL, sess, NULL, wp);
expanded = format_expand(ft, arg);
job = job_run(expanded, sess, NULL, NULL, NULL);