From 197347b61f4f6cfdf0da94aa3d6205e692e5954e Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 5 Jun 2008 22:59:38 +0000 Subject: Don't bork on link/swap the same window. Also extend comment. --- CHANGES | 13 ++++++++++++- TODO | 1 - cmd-link-window.c | 17 +++++++++++------ cmd-swap-window.c | 6 +++++- cmd.c | 15 ++++++++------- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index 4ffc4210..f7335951 100644 --- a/CHANGES +++ b/CHANGES @@ -21,6 +21,17 @@ tmux renamew -t/dev/ttypi:0 newname (client /dev/ttypi's current session, window 0) + This does have some downsides, for example, having to use -t on selectw, + + tmux selectw -t7 + + is annoying. But then using non-flagged arguments would mean renaming the + current window would need to be something like: + + tmux renamew : newname + + It might be better not to try and be so consistent; comments to the usual + address ;-). * Infrastructure for printing arguments in list-keys output. Easy ones only for now. @@ -429,4 +440,4 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.111 2008-06-05 21:24:59 nicm Exp $ +$Id: CHANGES,v 1.112 2008-06-05 22:59:38 nicm Exp $ diff --git a/TODO b/TODO index d3122dfa..ad78ee4f 100644 --- a/TODO +++ b/TODO @@ -34,7 +34,6 @@ command to purge window history extend list-clients to list clients attached to a session (-a for all?) bring back detach-session to detach all clients on a session? - paste buffer etc shouldn't be limited to keys buffer manip: clear, view etc (clear-buffer, show-buffer) - function groups, bind-key ^W { select-window 0; send-key ^W } etc *** - allow fnmatch for -c, so that you can, eg, detach all clients diff --git a/cmd-link-window.c b/cmd-link-window.c index a1c298f4..54ea5dc3 100644 --- a/cmd-link-window.c +++ b/cmd-link-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-link-window.c,v 1.19 2008-06-05 21:25:00 nicm Exp $ */ +/* $Id: cmd-link-window.c,v 1.20 2008-06-05 22:59:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -66,16 +66,20 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx) return; } - if (data->flags & CMD_KFLAG) { + if (idx != -1) wl_dst = winlink_find_by_index(&s->windows, idx); - if (wl_dst != NULL) { + if (wl_dst != NULL) { + if (wl_dst->window == wl_src->window) + goto out; + + if (data->flags & CMD_KFLAG) { /* * Can't use session_detach as it will destroy session * if this makes it empty. */ session_alert_cancel(s, wl_dst); winlink_remove(&s->windows, wl_dst); - + /* Force select/redraw if current. */ if (wl_dst == s->curw) { data->flags &= ~CMD_DFLAG; @@ -85,8 +89,8 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx) s->lastw = NULL; /* - * Can't error out after this or there could be an empty - * session! + * Can't error out after this or there could be an + * empty session! */ } } @@ -104,6 +108,7 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx) server_redraw_session(s); } +out: if (ctx->cmdclient != NULL) server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd-swap-window.c b/cmd-swap-window.c index 1f473e19..8cb63ca8 100644 --- a/cmd-swap-window.c +++ b/cmd-swap-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-swap-window.c,v 1.11 2008-06-05 21:25:00 nicm Exp $ */ +/* $Id: cmd-swap-window.c,v 1.12 2008-06-05 22:59:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -55,6 +55,9 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx) if ((wl_dst = cmd_find_window(ctx, data->dst, &dst)) == NULL) return; + if (wl_dst->window == wl_src->window) + goto out; + w = wl_dst->window; wl_dst->window = wl_src->window; wl_src->window = w; @@ -68,6 +71,7 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx) if (src != dst) server_redraw_session(dst); +out: if (ctx->cmdclient != NULL) server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); } diff --git a/cmd.c b/cmd.c index 5ac2874e..6685ef0a 100644 --- a/cmd.c +++ b/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.43 2008-06-05 21:25:00 nicm Exp $ */ +/* $Id: cmd.c,v 1.44 2008-06-05 22:59:38 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -313,14 +313,15 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp) s = ctx->cursession; if (s == NULL) s = cmd_current_session(ctx); - if (s != NULL) { - if (idx == -1) - wl = s->curw; - else - wl = winlink_find_by_index(&s->windows, idx); - } + if (s == NULL) + return (NULL); if (sp != NULL) *sp = s; + + if (idx == -1) + wl = s->curw; + else + wl = winlink_find_by_index(&s->windows, idx); if (wl == NULL) ctx->error(ctx, "window not found: %s:%d", s->name, idx); return (wl); -- cgit v1.2.3