-k on link-window to kill dest window if it exists.

pull/1/head
Nicholas Marriott 2007-11-17 08:21:54 +00:00
parent 54d01c1a5f
commit 958cd9cb94
3 changed files with 48 additions and 10 deletions

View File

@ -1,3 +1,7 @@
17 November 2007
* (nicm) Add -k option to link-window to kill target window if it exists.
16 November 2007 16 November 2007
* (nicm) Split in-client display into two columns. This is a hack but not a lot * (nicm) Split in-client display into two columns. This is a hack but not a lot
@ -223,4 +227,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.72 2007-11-16 22:06:45 nicm Exp $ $Id: CHANGES,v 1.73 2007-11-17 08:21:54 nicm Exp $

View File

@ -1,4 +1,4 @@
/* $Id: cmd-link-window.c,v 1.6 2007-11-16 21:12:31 nicm Exp $ */ /* $Id: cmd-link-window.c,v 1.7 2007-11-17 08:21:54 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -34,14 +34,15 @@ void cmd_link_window_recv(void **, struct buffer *);
void cmd_link_window_free(void *); void cmd_link_window_free(void *);
struct cmd_link_window_data { struct cmd_link_window_data {
int flag_detached;
int flag_kill;
int dstidx; int dstidx;
int srcidx; int srcidx;
char *srcname; char *srcname;
int flag_detached;
}; };
const struct cmd_entry cmd_link_window_entry = { const struct cmd_entry cmd_link_window_entry = {
"link-window", "linkw", "[-i index] name index", "link-window", "linkw", "[-dk] [-i index] name index",
CMD_NOCLIENT, CMD_NOCLIENT,
cmd_link_window_parse, cmd_link_window_parse,
cmd_link_window_exec, cmd_link_window_exec,
@ -59,11 +60,12 @@ cmd_link_window_parse(void **ptr, int argc, char **argv, char **cause)
*ptr = data = xmalloc(sizeof *data); *ptr = data = xmalloc(sizeof *data);
data->flag_detached = 0; data->flag_detached = 0;
data->flag_kill = 0;
data->dstidx = -1; data->dstidx = -1;
data->srcidx = -1; data->srcidx = -1;
data->srcname = NULL; data->srcname = NULL;
while ((opt = getopt(argc, argv, "di:")) != EOF) { while ((opt = getopt(argc, argv, "dki:")) != EOF) {
switch (opt) { switch (opt) {
case 'i': case 'i':
data->dstidx = strtonum(optarg, 0, INT_MAX, &errstr); data->dstidx = strtonum(optarg, 0, INT_MAX, &errstr);
@ -75,6 +77,9 @@ cmd_link_window_parse(void **ptr, int argc, char **argv, char **cause)
case 'd': case 'd':
data->flag_detached = 1; data->flag_detached = 1;
break; break;
case 'k':
data->flag_kill = 1;
break;
default: default:
goto usage; goto usage;
} }
@ -107,7 +112,7 @@ cmd_link_window_exec(void *ptr, struct cmd_ctx *ctx)
{ {
struct cmd_link_window_data *data = ptr; struct cmd_link_window_data *data = ptr;
struct session *dst = ctx->session, *src; struct session *dst = ctx->session, *src;
struct winlink *wl; struct winlink *wl, *wl2;
if (data == NULL) if (data == NULL)
return; return;
@ -131,7 +136,30 @@ cmd_link_window_exec(void *ptr, struct cmd_ctx *ctx)
if (data->dstidx < 0) if (data->dstidx < 0)
data->dstidx = -1; data->dstidx = -1;
if ((wl = session_attach(dst, wl->window, data->dstidx)) == NULL) { if (data->flag_kill && data->dstidx != -1) {
wl2 = winlink_find_by_index(&dst->windows, data->dstidx);
/*
* Can't use session_detach as it will destroy session if this
* makes it empty.
*/
session_cancelbell(dst, wl2);
winlink_remove(&dst->windows, wl2);
/* Force select/redraw if current. */
if (wl2 == dst->curw)
data->flag_detached = 0;
if (wl2 == dst->lastw)
dst->lastw = NULL;
/*
* Can't error out after this or there could be an empty
* session!
*/
}
wl = session_attach(dst, wl->window, data->dstidx);
if (wl == NULL) {
ctx->error(ctx, "index in use: %d", data->dstidx); ctx->error(ctx, "index in use: %d", data->dstidx);
return; return;
} }

12
tmux.1
View File

@ -1,4 +1,4 @@
.\" $Id: tmux.1,v 1.14 2007-11-16 21:12:31 nicm Exp $ .\" $Id: tmux.1,v 1.15 2007-11-17 08:21:54 nicm Exp $
.\" .\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\" .\"
@ -171,6 +171,7 @@ removing it from any sessions to which it is linked.
.D1 (alias: Ic last ) .D1 (alias: Ic last )
Select the last (previously selected) window. Select the last (previously selected) window.
.It Xo Ic link-window .It Xo Ic link-window
.Op Fl dk
.Op Fl i Ar destination-index .Op Fl i Ar destination-index
.Ar source-name Ar source-index .Ar source-name Ar source-index
.Xc .Xc
@ -183,9 +184,14 @@ into the specified session. If
.Ar destination-index .Ar destination-index
is specified and no window exists with that index, the window is linked at is specified and no window exists with that index, the window is linked at
that index. that index.
If a window already exists at If
.Fl k
is given and a window exists at
.Ar destination-index , .Ar destination-index ,
an error is generated. it is killed, otherwise an error is generated.
If
.Fl d
is given, the newly linked window is not selected.
.It Xo Ic list-clients .It Xo Ic list-clients
.Xc .Xc
.D1 (alias: Ic lsc ) .D1 (alias: Ic lsc )