Don't bork on link/swap the same window. Also extend comment.

This commit is contained in:
Nicholas Marriott 2008-06-05 22:59:38 +00:00
parent 741f8967b4
commit 197347b61f
5 changed files with 36 additions and 16 deletions

13
CHANGES
View File

@ -21,6 +21,17 @@
tmux renamew -t/dev/ttypi:0 newname (client /dev/ttypi's current tmux renamew -t/dev/ttypi:0 newname (client /dev/ttypi's current
session, window 0) 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 * Infrastructure for printing arguments in list-keys output. Easy ones only for
now. now.
@ -429,4 +440,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other (including mutt, emacs). No status bar yet and no key remapping or other
customisation. 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 $

1
TODO
View File

@ -34,7 +34,6 @@
command to purge window history command to purge window history
extend list-clients to list clients attached to a session (-a for all?) extend list-clients to list clients attached to a session (-a for all?)
bring back detach-session to detach all clients on a session? 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) buffer manip: clear, view etc (clear-buffer, show-buffer)
- function groups, bind-key ^W { select-window 0; send-key ^W } etc *** - function groups, bind-key ^W { select-window 0; send-key ^W } etc ***
- allow fnmatch for -c, so that you can, eg, detach all clients - allow fnmatch for -c, so that you can, eg, detach all clients

View File

@ -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 <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -66,16 +66,20 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
return; return;
} }
if (data->flags & CMD_KFLAG) { if (idx != -1)
wl_dst = winlink_find_by_index(&s->windows, idx); 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 * Can't use session_detach as it will destroy session
* if this makes it empty. * if this makes it empty.
*/ */
session_alert_cancel(s, wl_dst); session_alert_cancel(s, wl_dst);
winlink_remove(&s->windows, wl_dst); winlink_remove(&s->windows, wl_dst);
/* Force select/redraw if current. */ /* Force select/redraw if current. */
if (wl_dst == s->curw) { if (wl_dst == s->curw) {
data->flags &= ~CMD_DFLAG; data->flags &= ~CMD_DFLAG;
@ -85,8 +89,8 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
s->lastw = NULL; s->lastw = NULL;
/* /*
* Can't error out after this or there could be an empty * Can't error out after this or there could be an
* session! * empty session!
*/ */
} }
} }
@ -104,6 +108,7 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_session(s); server_redraw_session(s);
} }
out:
if (ctx->cmdclient != NULL) if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -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 <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -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) if ((wl_dst = cmd_find_window(ctx, data->dst, &dst)) == NULL)
return; return;
if (wl_dst->window == wl_src->window)
goto out;
w = wl_dst->window; w = wl_dst->window;
wl_dst->window = wl_src->window; wl_dst->window = wl_src->window;
wl_src->window = w; wl_src->window = w;
@ -68,6 +71,7 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
if (src != dst) if (src != dst)
server_redraw_session(dst); server_redraw_session(dst);
out:
if (ctx->cmdclient != NULL) if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

15
cmd.c
View File

@ -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 <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -313,14 +313,15 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
s = ctx->cursession; s = ctx->cursession;
if (s == NULL) if (s == NULL)
s = cmd_current_session(ctx); s = cmd_current_session(ctx);
if (s != NULL) { if (s == NULL)
if (idx == -1) return (NULL);
wl = s->curw;
else
wl = winlink_find_by_index(&s->windows, idx);
}
if (sp != NULL) if (sp != NULL)
*sp = s; *sp = s;
if (idx == -1)
wl = s->curw;
else
wl = winlink_find_by_index(&s->windows, idx);
if (wl == NULL) if (wl == NULL)
ctx->error(ctx, "window not found: %s:%d", s->name, idx); ctx->error(ctx, "window not found: %s:%d", s->name, idx);
return (wl); return (wl);