From 85671a5bed961b7a542ffce853749fb61b0558ca Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 21 Oct 2014 22:06:46 +0000 Subject: [PATCH 1/7] Save next item after firing command in case it has added to the queue. --- cmd-queue.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd-queue.c b/cmd-queue.c index 6495d3fd..0ddf90f7 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -180,8 +180,6 @@ cmdq_continue(struct cmd_q *cmdq) cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry); do { - next = TAILQ_NEXT(cmdq->item, qentry); - while (cmdq->cmd != NULL) { cmd_print(cmdq->cmd, s, sizeof s); log_debug("cmdq %p: %s (client %d)", cmdq, s, @@ -213,6 +211,7 @@ cmdq_continue(struct cmd_q *cmdq) cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry); } + next = TAILQ_NEXT(cmdq->item, qentry); TAILQ_REMOVE(&cmdq->queue, cmdq->item, qentry); cmd_list_free(cmdq->item->cmdlist); From a02c2e55c0ee0a6f2d3a897c06a396794b765a6c Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 21 Oct 2014 22:22:04 +0000 Subject: [PATCH 2/7] Only redraw pane when it has actually changed. --- cmd-select-pane.c | 3 +-- tmux.h | 2 +- window.c | 7 ++++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd-select-pane.c b/cmd-select-pane.c index 99594ae9..5810eeab 100644 --- a/cmd-select-pane.c +++ b/cmd-select-pane.c @@ -99,8 +99,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq) wp->flags &= ~PANE_INPUTOFF; else if (args_has(self->args, 'd')) wp->flags |= PANE_INPUTOFF; - else { - window_set_active_pane(wl->window, wp); + else if (window_set_active_pane(wl->window, wp)) { server_status_window(wl->window); server_redraw_window_borders(wl->window); } diff --git a/tmux.h b/tmux.h index 11803985..a8ea70dc 100644 --- a/tmux.h +++ b/tmux.h @@ -2116,7 +2116,7 @@ void window_destroy(struct window *); struct window_pane *window_get_active_at(struct window *, u_int, u_int); void window_set_active_at(struct window *, u_int, u_int); struct window_pane *window_find_string(struct window *, const char *); -void window_set_active_pane(struct window *, struct window_pane *); +int window_set_active_pane(struct window *, struct window_pane *); struct window_pane *window_add_pane(struct window *, u_int); void window_resize(struct window *, u_int, u_int); int window_zoom(struct window_pane *); diff --git a/window.c b/window.c index 21dd8d55..0144cdc8 100644 --- a/window.c +++ b/window.c @@ -386,11 +386,11 @@ window_resize(struct window *w, u_int sx, u_int sy) w->sy = sy; } -void +int window_set_active_pane(struct window *w, struct window_pane *wp) { if (wp == w->active) - return; + return (0); w->last = w->active; w->active = wp; while (!window_pane_visible(w->active)) { @@ -398,9 +398,10 @@ window_set_active_pane(struct window *w, struct window_pane *wp) if (w->active == NULL) w->active = TAILQ_LAST(&w->panes, window_panes); if (w->active == wp) - return; + return (1); } w->active->active_point = next_active_point++; + return (1); } struct window_pane * From 68cb1c0e6b169c6765e0d52c5319fe4354edaf09 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 22 Oct 2014 23:11:41 +0000 Subject: [PATCH 3/7] Merge unlink-window into kill-window. --- Makefile | 1 - cmd-kill-window.c | 43 ++++++++++++++++++++++------ cmd-unlink-window.c | 68 --------------------------------------------- session.c | 18 ++++++++++-- tmux.h | 1 + 5 files changed, 51 insertions(+), 80 deletions(-) delete mode 100644 cmd-unlink-window.c diff --git a/Makefile b/Makefile index 692ec558..f1ad13f7 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,6 @@ SRCS= arguments.c \ cmd-swap-window.c \ cmd-switch-client.c \ cmd-unbind-key.c \ - cmd-unlink-window.c \ cmd-wait-for.c \ cmd.c \ cmd-queue.c \ diff --git a/cmd-kill-window.c b/cmd-kill-window.c index dd4d7f59..d402acce 100644 --- a/cmd-kill-window.c +++ b/cmd-kill-window.c @@ -34,23 +34,48 @@ const struct cmd_entry cmd_kill_window_entry = { cmd_kill_window_exec }; +const struct cmd_entry cmd_unlink_window_entry = { + "unlink-window", "unlinkw", + "kt:", 0, 0, + "[-k] " CMD_TARGET_WINDOW_USAGE, + 0, + cmd_kill_window_exec +}; + enum cmd_retval cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq) { - struct args *args = self->args; - struct winlink *wl, *wl2, *wl3; - struct session *s; + struct args *args = self->args; + struct winlink *wl, *wl2, *wl3; + struct window *w; + struct session *s; + struct session_group *sg; + u_int references; if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL) return (CMD_RETURN_ERROR); + w = wl->window; - if (args_has(args, 'a')) { - RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) { - if (wl != wl2) - server_kill_window(wl2->window); + if (self->entry == &cmd_unlink_window_entry) { + sg = session_group_find(s); + if (sg != NULL) + references = session_group_count(sg); + else + references = 1; + if (!args_has(self->args, 'k') && w->references == references) { + cmdq_error(cmdq, "window only linked to one session"); + return (CMD_RETURN_ERROR); } - } else - server_kill_window(wl->window); + server_unlink_window(s, wl); + } else { + if (args_has(args, 'a')) { + RB_FOREACH_SAFE(wl2, winlinks, &s->windows, wl3) { + if (wl != wl2) + server_kill_window(wl2->window); + } + } else + server_kill_window(wl->window); + } recalculate_sizes(); return (CMD_RETURN_NORMAL); diff --git a/cmd-unlink-window.c b/cmd-unlink-window.c deleted file mode 100644 index adc70168..00000000 --- a/cmd-unlink-window.c +++ /dev/null @@ -1,68 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2007 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include "tmux.h" - -/* - * Unlink a window, unless it would be destroyed by doing so (only one link). - */ - -enum cmd_retval cmd_unlink_window_exec(struct cmd *, struct cmd_q *); - -const struct cmd_entry cmd_unlink_window_entry = { - "unlink-window", "unlinkw", - "kt:", 0, 0, - "[-k] " CMD_TARGET_WINDOW_USAGE, - 0, - cmd_unlink_window_exec -}; - -enum cmd_retval -cmd_unlink_window_exec(struct cmd *self, struct cmd_q *cmdq) -{ - struct args *args = self->args; - struct winlink *wl; - struct window *w; - struct session *s, *s2; - struct session_group *sg; - u_int references; - - if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL) - return (CMD_RETURN_ERROR); - w = wl->window; - - sg = session_group_find(s); - if (sg != NULL) { - references = 0; - TAILQ_FOREACH(s2, &sg->sessions, gentry) - references++; - } else - references = 1; - - if (!args_has(self->args, 'k') && w->references == references) { - cmdq_error(cmdq, "window is only linked to one session"); - return (CMD_RETURN_ERROR); - } - - server_unlink_window(s, wl); - recalculate_sizes(); - - return (CMD_RETURN_NORMAL); -} diff --git a/session.c b/session.c index 3bc2363e..0f8c1122 100644 --- a/session.c +++ b/session.c @@ -492,6 +492,19 @@ session_group_remove(struct session *s) } } +/* Count number of sessions in session group. */ +u_int +session_group_count(struct session_group *sg) +{ + struct session *s; + u_int n; + + n = 0; + TAILQ_FOREACH(s, &sg->sessions, gentry) + n++; + return (n); +} + /* Synchronize a session to its session group. */ void session_group_synchronize_to(struct session *s) @@ -579,8 +592,9 @@ session_group_synchronize1(struct session *target, struct session *s) /* Then free the old winlinks list. */ while (!RB_EMPTY(&old_windows)) { wl = RB_ROOT(&old_windows); - if (winlink_find_by_window_id(&s->windows, wl->window->id) == NULL) - notify_window_unlinked(s, wl->window); + wl2 = winlink_find_by_window_id(&s->windows, wl->window->id); + if (wl2 == NULL) + notify_window_unlinked(s, wl->window); winlink_remove(&old_windows, wl); } } diff --git a/tmux.h b/tmux.h index a8ea70dc..adba24d2 100644 --- a/tmux.h +++ b/tmux.h @@ -2296,6 +2296,7 @@ struct session_group *session_group_find(struct session *); u_int session_group_index(struct session_group *); void session_group_add(struct session *, struct session *); void session_group_remove(struct session *); +u_int session_group_count(struct session_group *); void session_group_synchronize_to(struct session *); void session_group_synchronize_from(struct session *); void session_group_synchronize1(struct session *, struct session *); From abfb9656ef4404cff7847032cd4722eb0af55ee3 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 22 Oct 2014 23:18:53 +0000 Subject: [PATCH 4/7] Fix some spacing nits. --- cmd-find-window.c | 2 +- key-bindings.c | 8 ++++---- server-client.c | 4 ++-- session.c | 2 +- tty-keys.c | 2 +- window-choose.c | 6 +++--- window-copy.c | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cmd-find-window.c b/cmd-find-window.c index deacf99c..88e48798 100644 --- a/cmd-find-window.c +++ b/cmd-find-window.c @@ -162,7 +162,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq) xasprintf(&searchstr, "*%s*", str); RB_FOREACH(wm, winlinks, &s->windows) - cmd_find_window_match (&find_list, match_flags, wm, str, searchstr); + cmd_find_window_match(&find_list, match_flags, wm, str, searchstr); free(searchstr); if (ARRAY_LENGTH(&find_list) == 0) { diff --git a/key-bindings.c b/key-bindings.c index 13ba9f25..00f73d73 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -167,16 +167,16 @@ key_bindings_init(void) RB_INIT(&key_bindings); - cmdq = cmdq_new (NULL); + cmdq = cmdq_new(NULL); for (i = 0; i < nitems(defaults); i++) { error = cmd_string_parse(defaults[i], &cmdlist, "", i, &cause); if (error != 0) fatalx("bad default key"); - cmdq_run (cmdq, cmdlist); - cmd_list_free (cmdlist); + cmdq_run(cmdq, cmdlist); + cmd_list_free(cmdlist); } - cmdq_free (cmdq); + cmdq_free(cmdq); } void diff --git a/server-client.c b/server-client.c index bd7579fe..e0b0c668 100644 --- a/server-client.c +++ b/server-client.c @@ -160,7 +160,7 @@ server_client_lost(struct client *c) evbuffer_free(c->stdin_data); evbuffer_free(c->stdout_data); if (c->stderr_data != c->stdout_data) - evbuffer_free (c->stderr_data); + evbuffer_free(c->stderr_data); status_free_jobs(&c->status_new); status_free_jobs(&c->status_old); @@ -638,7 +638,7 @@ server_client_reset_state(struct client *c) if (!window_pane_visible(wp) || wp->yoff + s->cy >= c->tty.sy - status) tty_cursor(&c->tty, 0, 0); else { - o = status && options_get_number (oo, "status-position") == 0; + o = status && options_get_number(oo, "status-position") == 0; tty_cursor(&c->tty, wp->xoff + s->cx, o + wp->yoff + s->cy); } diff --git a/session.c b/session.c index 0f8c1122..03ddb10d 100644 --- a/session.c +++ b/session.c @@ -127,7 +127,7 @@ session_create(const char *name, int argc, char **argv, const char *path, s->name = NULL; do { s->id = next_session_id++; - free (s->name); + free(s->name); xasprintf(&s->name, "%u", s->id); } while (RB_FIND(sessions, &sessions, s) != NULL); } diff --git a/tty-keys.c b/tty-keys.c index 967decaf..a987c44b 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -382,7 +382,7 @@ tty_keys_build(struct tty *tty) const char *s; if (tty->key_tree != NULL) - tty_keys_free (tty); + tty_keys_free(tty); tty->key_tree = NULL; for (i = 0; i < nitems(tty_default_raw_keys); i++) { diff --git a/window-choose.c b/window-choose.c index ef3b8562..db092872 100644 --- a/window-choose.c +++ b/window-choose.c @@ -98,7 +98,7 @@ window_choose_add(struct window_pane *wp, struct window_choose_data *wcd) item->pos = ARRAY_LENGTH(&data->list) - 1; item->state = 0; - data->width = xsnprintf (tmp, sizeof tmp , "%u", item->pos); + data->width = xsnprintf(tmp, sizeof tmp , "%u", item->pos); } void @@ -787,9 +787,9 @@ window_choose_write_line( key = window_choose_key_index(data, data->top + py); if (key != -1) - xsnprintf (label, sizeof label, "(%c)", key); + xsnprintf(label, sizeof label, "(%c)", key); else - xsnprintf (label, sizeof label, "(%d)", item->pos); + xsnprintf(label, sizeof label, "(%d)", item->pos); screen_write_nputs(ctx, screen_size_x(s) - 1, &gc, utf8flag, "%*s %s %s", data->width + 2, label, /* diff --git a/window-copy.c b/window-copy.c index 69921f62..b1301676 100644 --- a/window-copy.c +++ b/window-copy.c @@ -1585,7 +1585,7 @@ window_copy_copy_line(struct window_pane *wp, s = tty_acs_get(NULL, ud.data[0]); if (s != NULL && strlen(s) <= sizeof ud.data) { ud.size = strlen(s); - memcpy (ud.data, s, ud.size); + memcpy(ud.data, s, ud.size); } } From 428b51e03187f13ccaf1451fb89d53848facab6d Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 25 Oct 2014 08:47:04 +0000 Subject: [PATCH 5/7] Add pane_input_off format, from Anish R Athalye. --- format.c | 1 + tmux.1 | 1 + 2 files changed, 2 insertions(+) diff --git a/format.c b/format.c index b5e51494..441e61be 100644 --- a/format.c +++ b/format.c @@ -554,6 +554,7 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_id", "%%%u", wp->id); format_add(ft, "pane_active", "%d", wp == wp->window->active); format_add(ft, "pane_dead", "%d", wp->fd == -1); + format_add(ft, "pane_input_off", "%d", !!(wp->flags & PANE_INPUTOFF)); if (window_pane_visible(wp)) { format_add(ft, "pane_left", "%u", wp->xoff); diff --git a/tmux.1 b/tmux.1 index 0c738f3e..9b853a1f 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3099,6 +3099,7 @@ The following variables are available, where appropriate: .It Li "pane_height" Ta "" Ta "Height of pane" .It Li "pane_id" Ta "#D" Ta "Unique pane ID" .It Li "pane_in_mode" Ta "" Ta "If pane is in a mode" +.It Li "pane_input_off" Ta "" Ta "If input to pane is disabled" .It Li "pane_index" Ta "#P" Ta "Index of pane" .It Li "pane_left" Ta "" Ta "Left of pane" .It Li "pane_pid" Ta "" Ta "PID of first process in pane" From b496b1fe11b99614e407d02edb1a21905f384929 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 27 Oct 2014 22:23:47 +0000 Subject: [PATCH 6/7] Move cfg_causes local into cfg.c and remove struct causelist. --- cfg.c | 34 ++++++++++++++++++++++++++++++---- cmd-queue.c | 9 ++++----- cmd-source-file.c | 22 ++++------------------ server.c | 19 ++++++------------- tmux.h | 6 ++---- 5 files changed, 46 insertions(+), 44 deletions(-) diff --git a/cfg.c b/cfg.c index 7502cee7..23828923 100644 --- a/cfg.c +++ b/cfg.c @@ -30,7 +30,7 @@ struct cmd_q *cfg_cmd_q; int cfg_finished; int cfg_references; -struct causelist cfg_causes; +ARRAY_DECL (, char *) cfg_causes = ARRAY_INITIALIZER; struct client *cfg_client; int @@ -40,7 +40,7 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause) char delim[3] = { '\\', '\\', '\0' }; u_int found; size_t line = 0; - char *buf, *cause1, *msg, *p; + char *buf, *cause1, *p; struct cmd_list *cmdlist; log_debug("loading %s", path); @@ -67,8 +67,7 @@ load_cfg(const char *path, struct cmd_q *cmdq, char **cause) free(buf); if (cause1 == NULL) continue; - xasprintf(&msg, "%s:%zu: %s", path, line, cause1); - ARRAY_ADD(&cfg_causes, msg); + cfg_add_cause("%s:%zu: %s", path, line, cause1); free(cause1); continue; } @@ -113,6 +112,33 @@ cfg_default_done(unused struct cmd_q *cmdq) } } +void +cfg_add_cause(const char* fmt, ...) +{ + va_list ap; + char* msg; + + va_start(ap, fmt); + xvasprintf(&msg, fmt, ap); + va_end (ap); + + ARRAY_ADD(&cfg_causes, msg); +} + +void +cfg_print_causes(struct cmd_q *cmdq) +{ + char *cause; + u_int i; + + for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) { + cause = ARRAY_ITEM(&cfg_causes, i); + cmdq_print(cmdq, "%s", cause); + free(cause); + } + ARRAY_FREE(&cfg_causes); +} + void cfg_show_causes(struct session *s) { diff --git a/cmd-queue.c b/cmd-queue.c index 0ddf90f7..a98fa9b6 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -93,17 +93,16 @@ cmdq_error(struct cmd_q *cmdq, const char *fmt, ...) struct client *c = cmdq->client; struct cmd *cmd = cmdq->cmd; va_list ap; - char *msg, *cause; + char *msg; size_t msglen; va_start(ap, fmt); msglen = xvasprintf(&msg, fmt, ap); va_end(ap); - if (c == NULL) { - xasprintf(&cause, "%s:%u: %s", cmd->file, cmd->line, msg); - ARRAY_ADD(&cfg_causes, cause); - } else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) { + if (c == NULL) + cfg_add_cause("%s:%u: %s", cmd->file, cmd->line, msg); + else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) { evbuffer_add(c->stderr_data, msg, msglen); evbuffer_add(c->stderr_data, "\n", 1); diff --git a/cmd-source-file.c b/cmd-source-file.c index 8610d807..e5710a0c 100644 --- a/cmd-source-file.c +++ b/cmd-source-file.c @@ -28,7 +28,6 @@ enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *); -void cmd_source_file_show(struct cmd_q *); void cmd_source_file_done(struct cmd_q *); const struct cmd_entry cmd_source_file_entry = { @@ -59,11 +58,12 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq) free(cause); return (CMD_RETURN_ERROR); } - ARRAY_ADD(&cfg_causes, cause); + cfg_add_cause("%s", cause); + free(cause); /* FALLTHROUGH */ case 0: if (cfg_references == 0) - cmd_source_file_show(cmdq); + cfg_print_causes(cmdq); cmdq_free(cmdq1); return (CMD_RETURN_NORMAL); } @@ -75,20 +75,6 @@ cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_WAIT); } -void -cmd_source_file_show(struct cmd_q *cmdq) -{ - u_int i; - char *cause; - - for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) { - cause = ARRAY_ITEM(&cfg_causes, i); - cmdq_print(cmdq, "%s", cause); - free(cause); - } - ARRAY_FREE(&cfg_causes); -} - void cmd_source_file_done(struct cmd_q *cmdq1) { @@ -105,6 +91,6 @@ cmd_source_file_done(struct cmd_q *cmdq1) return; if (cfg_references == 0) - cmd_source_file_show(cmdq); + cfg_print_causes(cmdq); cmdq_continue(cmdq); } diff --git a/server.c b/server.c index acf5aaf6..db261306 100644 --- a/server.c +++ b/server.c @@ -165,25 +165,18 @@ server_start(int lockfd, char *lockfile) cfg_cmd_q->emptyfn = cfg_default_done; cfg_finished = 0; cfg_references = 1; - ARRAY_INIT(&cfg_causes); cfg_client = ARRAY_FIRST(&clients); if (cfg_client != NULL) cfg_client->references++; if (access(TMUX_CONF, R_OK) == 0) { - if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1) { - xasprintf(&cause, "%s: %s", TMUX_CONF, cause); - ARRAY_ADD(&cfg_causes, cause); - } - } else if (errno != ENOENT) { - xasprintf(&cause, "%s: %s", TMUX_CONF, strerror(errno)); - ARRAY_ADD(&cfg_causes, cause); - } + if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1) + cfg_add_cause("%s: %s", TMUX_CONF, cause); + } else if (errno != ENOENT) + cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno)); if (cfg_file != NULL) { - if (load_cfg(cfg_file, cfg_cmd_q, &cause) == -1) { - xasprintf(&cause, "%s: %s", cfg_file, cause); - ARRAY_ADD(&cfg_causes, cause); - } + if (load_cfg(cfg_file, cfg_cmd_q, &cause) == -1) + cfg_add_cause("%s: %s", cfg_file, cause); } cmdq_continue(cfg_cmd_q); diff --git a/tmux.h b/tmux.h index adba24d2..d310c7af 100644 --- a/tmux.h +++ b/tmux.h @@ -381,9 +381,6 @@ struct tty_term_code_entry { const char *name; }; -/* List of error causes. */ -ARRAY_DECL(causelist, char *); - /* Message codes. */ enum msgtype { MSG_VERSION = 12, @@ -1500,10 +1497,11 @@ __dead void shell_exec(const char *, const char *); extern struct cmd_q *cfg_cmd_q; extern int cfg_finished; extern int cfg_references; -extern struct causelist cfg_causes; extern struct client *cfg_client; int load_cfg(const char *, struct cmd_q *, char **); void cfg_default_done(struct cmd_q *); +void cfg_add_cause(const char *, ...); +void cfg_print_causes(struct cmd_q *); void cfg_show_causes(struct session *); /* format.c */ From 10a9440055ccdda5788965bcb048207eab2a0548 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 27 Oct 2014 22:40:29 +0000 Subject: [PATCH 7/7] Merge linkw and movew which are virtually identical. --- Makefile | 1 - cmd-link-window.c | 63 ----------------------------------------------- cmd-move-window.c | 19 +++++++++++--- 3 files changed, 15 insertions(+), 68 deletions(-) delete mode 100644 cmd-link-window.c diff --git a/Makefile b/Makefile index f1ad13f7..67b39bb2 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,6 @@ SRCS= arguments.c \ cmd-kill-server.c \ cmd-kill-session.c \ cmd-kill-window.c \ - cmd-link-window.c \ cmd-list-buffers.c \ cmd-list-clients.c \ cmd-list-keys.c \ diff --git a/cmd-link-window.c b/cmd-link-window.c deleted file mode 100644 index ee5b62a5..00000000 --- a/cmd-link-window.c +++ /dev/null @@ -1,63 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Copyright (c) 2007 Nicholas Marriott - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include - -#include - -#include "tmux.h" - -/* - * Link a window into another session. - */ - -enum cmd_retval cmd_link_window_exec(struct cmd *, struct cmd_q *); - -const struct cmd_entry cmd_link_window_entry = { - "link-window", "linkw", - "dks:t:", 0, 0, - "[-dk] " CMD_SRCDST_WINDOW_USAGE, - 0, - cmd_link_window_exec -}; - -enum cmd_retval -cmd_link_window_exec(struct cmd *self, struct cmd_q *cmdq) -{ - struct args *args = self->args; - struct session *src, *dst; - struct winlink *wl; - char *cause; - int idx, kflag, dflag; - - if ((wl = cmd_find_window(cmdq, args_get(args, 's'), &src)) == NULL) - return (CMD_RETURN_ERROR); - if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst)) == -2) - return (CMD_RETURN_ERROR); - - kflag = args_has(self->args, 'k'); - dflag = args_has(self->args, 'd'); - if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { - cmdq_error(cmdq, "can't link window: %s", cause); - free(cause); - return (CMD_RETURN_ERROR); - } - recalculate_sizes(); - - return (CMD_RETURN_NORMAL); -} diff --git a/cmd-move-window.c b/cmd-move-window.c index eef96f1c..3064cd6e 100644 --- a/cmd-move-window.c +++ b/cmd-move-window.c @@ -36,6 +36,14 @@ const struct cmd_entry cmd_move_window_entry = { cmd_move_window_exec }; +const struct cmd_entry cmd_link_window_entry = { + "link-window", "linkw", + "dks:t:", 0, 0, + "[-dk] " CMD_SRCDST_WINDOW_USAGE, + 0, + cmd_move_window_exec +}; + enum cmd_retval cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq) { @@ -46,7 +54,8 @@ cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq) int idx, kflag, dflag; if (args_has(args, 'r')) { - if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL) + s = cmd_find_session(cmdq, args_get(args, 't'), 0); + if (s == NULL) return (CMD_RETURN_ERROR); session_renumber_windows(s); @@ -62,12 +71,14 @@ cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq) kflag = args_has(self->args, 'k'); dflag = args_has(self->args, 'd'); - if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) { - cmdq_error(cmdq, "can't move window: %s", cause); + if (server_link_window(src, wl, dst, idx, kflag, !dflag, + &cause) != 0) { + cmdq_error(cmdq, "can't link window: %s", cause); free(cause); return (CMD_RETURN_ERROR); } - server_unlink_window(src, wl); + if (self->entry == &cmd_move_window_entry) + server_unlink_window(src, wl); recalculate_sizes(); return (CMD_RETURN_NORMAL);