This patch adds a new command, move-pane. It is a wafer-thin wrapper
around the implementation of join-pane and simply removes the
restriction that source and target must belong to different windows.
In order for move-pane to be complete, join-pane gets a -b argument
that says to place the source before the target (left of for a
vertical split or on top for a horizontal split). A handful of stray
spaces that my editor removed are also included in this diff.
Index: tmux.h
===================================================================
--- tmux.h (revision 2697)
+++ tmux.h (working copy)
@@ -1597,6 +1597,7 @@
extern const struct cmd_entry cmd_lock_client_entry;
extern const struct cmd_entry cmd_lock_server_entry;
extern const struct cmd_entry cmd_lock_session_entry;
+extern const struct cmd_entry cmd_move_pane_entry;
extern const struct cmd_entry cmd_move_window_entry;
extern const struct cmd_entry cmd_new_session_entry;
extern const struct cmd_entry cmd_new_window_entry;
@@ -1653,6 +1654,10 @@
/* client.c */
int client_main(int, char **, int);
+/* cmd-join-pane.c */
+int join_pane(
+ struct cmd *self, struct cmd_ctx *ctx, int require_diff_windows);
+
/* key-bindings.c */
extern struct key_bindings key_bindings;
int key_bindings_cmp(struct key_binding *, struct key_binding *);
@@ -1991,7 +1996,8 @@
struct client *c, struct mouse_event *mouse);
void layout_assign_pane(struct layout_cell *, struct window_pane *);
struct layout_cell *layout_split_pane(
- struct window_pane *, enum layout_type, int);
+ struct window_pane *, enum layout_type, int,
+ int);
void layout_close_pane(struct window_pane *);
/* layout-custom.c */
Index: layout.c
===================================================================
--- layout.c (revision 2697)
+++ layout.c (working copy)
@@ -92,7 +92,7 @@
case LAYOUT_LEFTRIGHT:
case LAYOUT_TOPBOTTOM:
TAILQ_FOREACH(lcchild, &lc->cells, entry)
- layout_print_cell(lcchild, hdr, n + 1);
+ layout_print_cell(lcchild, hdr, n + 1);
break;
case LAYOUT_WINDOWPANE:
break;
@@ -490,7 +490,7 @@
{
struct window *w;
struct window_pane *wp;
- int pane_border;
+ int pane_border;
w = c->session->curw->window;
@@ -616,7 +616,8 @@
* split. This must be followed by layout_assign_pane before much else happens!
**/
struct layout_cell *
-layout_split_pane(struct window_pane *wp, enum layout_type type, int size)
+layout_split_pane(struct window_pane *wp, enum layout_type type,
+ int size, int insert_before)
{
struct layout_cell *lc, *lcparent, *lcnew;
u_int sx, sy, xoff, yoff, size1, size2;
@@ -651,7 +652,11 @@
/* Create the new child cell. */
lcnew = layout_create_cell(lc->parent);
- TAILQ_INSERT_AFTER(&lc->parent->cells, lc, lcnew, entry);
+ if (insert_before)
+ TAILQ_INSERT_BEFORE(lc, lcnew, entry);
+ else
+ TAILQ_INSERT_AFTER(
+ &lc->parent->cells, lc, lcnew, entry);
} else {
/*
* Otherwise create a new parent and insert it.
@@ -672,7 +677,10 @@
/* Create the new child cell. */
lcnew = layout_create_cell(lcparent);
- TAILQ_INSERT_TAIL(&lcparent->cells, lcnew, entry);
+ if (insert_before)
+ TAILQ_INSERT_HEAD(&lcparent->cells, lcnew, entry);
+ else
+ TAILQ_INSERT_TAIL(&lcparent->cells, lcnew, entry);
}
/* Set new cell sizes. size is the target size or -1 for middle split,
Index: cmd-split-window.c
===================================================================
--- cmd-split-window.c (revision 2697)
+++ cmd-split-window.c (working copy)
@@ -58,7 +58,7 @@
struct window *w;
struct window_pane *wp, *new_wp = NULL;
struct environ env;
- const char *cmd, *cwd, *shell;
+ const char *cmd, *cwd, *shell;
char *cause, *new_cause;
u_int hlimit, paneidx;
int size, percentage;
@@ -112,7 +112,7 @@
if (*shell == '\0' || areshell(shell))
shell = _PATH_BSHELL;
- if ((lc = layout_split_pane(wp, type, size)) == NULL) {
+ if ((lc = layout_split_pane(wp, type, size, 0)) == NULL) {
cause = xstrdup("pane too small");
goto error;
}
Index: Makefile.am
===================================================================
--- Makefile.am (revision 2697)
+++ Makefile.am (working copy)
@@ -96,6 +96,7 @@
cmd-list.c \
cmd-load-buffer.c \
cmd-lock-server.c \
+ cmd-move-pane.c \
cmd-move-window.c \
cmd-new-session.c \
cmd-new-window.c \
Index: cmd-join-pane.c
===================================================================
--- cmd-join-pane.c (revision 2697)
+++ cmd-join-pane.c (working copy)
@@ -32,8 +32,8 @@
const struct cmd_entry cmd_join_pane_entry = {
"join-pane", "joinp",
- "dhvp:l:s:t:", 0, 0,
- "[-dhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
+ "bdhvp:l:s:t:", 0, 0,
+ "[-bdhv] [-p percentage|-l size] [-s src-pane] [-t dst-pane]",
0,
cmd_join_pane_key_binding,
NULL,
@@ -57,6 +57,12 @@
int
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
{
+ return join_pane(self, ctx, 1);
+}
+
+int
+join_pane(struct cmd *self, struct cmd_ctx *ctx, int require_diff_windows)
+{
struct args *args = self->args;
struct session *dst_s;
struct winlink *src_wl, *dst_wl;
@@ -78,10 +84,14 @@
return (-1);
src_w = src_wl->window;
- if (src_w == dst_w) {
+ if (require_diff_windows && src_w == dst_w) {
ctx->error(ctx, "can't join a pane to its own window");
return (-1);
}
+ if (!require_diff_windows && src_wp == dst_wp) {
+ ctx->error(ctx, "source and target panes must be different");
+ return (-1);
+ }
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
@@ -107,8 +117,8 @@
else
size = (dst_wp->sx * percentage) / 100;
}
-
- if ((lc = layout_split_pane(dst_wp, type, size)) == NULL) {
+ lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'));
+ if (lc == NULL) {
ctx->error(ctx, "create pane failed: pane too small");
return (-1);
}
Index: cmd.c
===================================================================
--- cmd.c (revision 2697)
+++ cmd.c (working copy)
@@ -67,6 +67,7 @@
&cmd_lock_client_entry,
&cmd_lock_server_entry,
&cmd_lock_session_entry,
+ &cmd_move_pane_entry,
&cmd_move_window_entry,
&cmd_new_session_entry,
&cmd_new_window_entry,
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
tmux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-users