summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-03-07 09:29:54 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-03-07 09:29:54 +0000
commit56f80a5b09ce98e3bdbef5c3e24fd092e55ed33f (patch)
tree738f7054a872d1330329f29189b137107d2aa864
parent8a6a7e74da70400cc98e7596c7d9d19848ca3aa1 (diff)
break-pane command to split a pane off into a new window; bound to ! by default.
-rw-r--r--CHANGES6
-rw-r--r--GNUmakefile4
-rw-r--r--Makefile4
-rw-r--r--TODO1
-rw-r--r--cmd-break-pane.c92
-rw-r--r--cmd-kill-pane.c4
-rw-r--r--cmd.c3
-rw-r--r--key-bindings.c5
-rw-r--r--tmux.h4
-rw-r--r--window.c15
10 files changed, 124 insertions, 14 deletions
diff --git a/CHANGES b/CHANGES
index a5ec4f0b..99012b24 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+07 March 2009
+
+* break-pane command to create a new window using an existing pane.
+
02 March 2009
* Make escape key timer work properly so escape+key can be used without
@@ -1119,7 +1123,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.256 2009-03-02 16:55:23 nicm Exp $
+$Id: CHANGES,v 1.257 2009-03-07 09:29:54 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
diff --git a/GNUmakefile b/GNUmakefile
index 1012c571..635f0367 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,4 +1,4 @@
-# $Id: GNUmakefile,v 1.74 2009-02-18 09:04:15 nicm Exp $
+# $Id: GNUmakefile,v 1.75 2009-03-07 09:29:54 nicm Exp $
.PHONY: clean
@@ -37,7 +37,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-resize-pane-up.c cmd-resize-pane-down.c cmd-kill-pane.c \
cmd-up-pane.c cmd-down-pane.c cmd-choose-window.c cmd-choose-session.c \
cmd-suspend-client.c cmd-find-window.c cmd-load-buffer.c \
- cmd-copy-buffer.c \
+ cmd-copy-buffer.c cmd-break-pane.c \
window-clock.c window-scroll.c window-more.c window-copy.c \
window-choose.c \
options.c options-cmd.c paste.c colour.c utf8.c clock.c \
diff --git a/Makefile b/Makefile
index 74040ffc..30a3d697 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.115 2009-02-18 09:04:15 nicm Exp $
+# $Id: Makefile,v 1.116 2009-03-07 09:29:54 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean update-index.html upload-index.html
@@ -40,7 +40,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-resize-pane-up.c cmd-resize-pane-down.c cmd-kill-pane.c \
cmd-up-pane.c cmd-down-pane.c cmd-choose-window.c cmd-choose-session.c \
cmd-suspend-client.c cmd-find-window.c cmd-load-buffer.c \
- cmd-copy-buffer.c \
+ cmd-copy-buffer.c cmd-break-pane.c \
window-clock.c window-scroll.c window-more.c window-copy.c \
window-choose.c \
options.c options-cmd.c paste.c colour.c utf8.c clock.c \
diff --git a/TODO b/TODO
index 90cad5b2..99a60204 100644
--- a/TODO
+++ b/TODO
@@ -93,4 +93,5 @@
- set-option should be set-session-option and should be overall global options
for stuff like mode keys?
- document status-keys
+- document break-pane
- refer to windows by name etc (duplicates? fnmatch?)
diff --git a/cmd-break-pane.c b/cmd-break-pane.c
new file mode 100644
index 00000000..95a0171f
--- /dev/null
+++ b/cmd-break-pane.c
@@ -0,0 +1,92 @@
+/* $Id: cmd-break-pane.c,v 1.1 2009-03-07 09:29:54 nicm Exp $ */
+
+/*
+ * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * 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 <sys/types.h>
+
+#include <stdlib.h>
+
+#include "tmux.h"
+
+/*
+ * Break pane off into a window.
+ */
+
+int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_break_pane_entry = {
+ "break-pane", "breakp",
+ CMD_PANE_WINDOW_USAGE " [-d]",
+ CMD_DFLAG,
+ cmd_pane_init,
+ cmd_pane_parse,
+ cmd_break_pane_exec,
+ cmd_pane_send,
+ cmd_pane_recv,
+ cmd_pane_free,
+ cmd_pane_print
+};
+
+int
+cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
+{
+ struct cmd_pane_data *data = self->data;
+ struct winlink *wl;
+ struct session *s;
+ struct window_pane *wp;
+ struct window *w;
+ char *cause;
+
+ if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
+ return (-1);
+ if (data->pane == -1)
+ wp = wl->window->active;
+ else {
+ wp = window_pane_at_index(wl->window, data->pane);
+ if (wp == NULL) {
+ ctx->error(ctx, "no pane: %d", data->pane);
+ return (-1);
+ }
+ }
+
+ if (window_count_panes(wl->window) == 1) {
+ ctx->error(ctx, "can't break pane: %d", data->pane);
+ return (-1);
+ }
+
+ TAILQ_REMOVE(&wl->window->panes, wp, entry);
+ if (wl->window->active == wp) {
+ wl->window->active = TAILQ_PREV(wp, window_panes, entry);
+ if (wl->window->active == NULL)
+ wl->window->active = TAILQ_NEXT(wp, entry);
+ }
+ window_fit_panes(wl->window);
+
+ w = wp->window = window_create1(s->sx, s->sy);
+ TAILQ_INSERT_HEAD(&w->panes, wp, entry);
+ w->active = wp;
+ window_fit_panes(w);
+ w->name = default_window_name(w);
+
+ wl = session_attach(s, w, -1, &cause); /* can't fail */
+
+ if (!(data->flags & CMD_DFLAG))
+ session_select(s, wl->idx);
+ server_redraw_session(s);
+
+ return (0);
+}
diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c
index aaeea59b..73e36cb9 100644
--- a/cmd-kill-pane.c
+++ b/cmd-kill-pane.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-kill-pane.c,v 1.3 2009-01-19 18:23:40 nicm Exp $ */
+/* $Id: cmd-kill-pane.c,v 1.4 2009-03-07 09:29:54 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -64,8 +64,8 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
ctx->error(ctx, "can't kill pane: %d", data->pane);
return (-1);
}
+
window_remove_pane(wl->window, wp);
server_redraw_window(wl->window);
-
return (0);
}
diff --git a/cmd.c b/cmd.c
index dd25c358..c4e3267d 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,4 @@
-/* $Id: cmd.c,v 1.85 2009-02-03 17:21:19 tcunha Exp $ */
+/* $Id: cmd.c,v 1.86 2009-03-07 09:29:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -28,6 +28,7 @@
const struct cmd_entry *cmd_table[] = {
&cmd_attach_session_entry,
&cmd_bind_key_entry,
+ &cmd_break_pane_entry,
&cmd_choose_session_entry,
&cmd_choose_window_entry,
&cmd_clock_mode_entry,
diff --git a/key-bindings.c b/key-bindings.c
index 5f3c9b16..3b024d47 100644
--- a/key-bindings.c
+++ b/key-bindings.c
@@ -1,4 +1,4 @@
-/* $Id: key-bindings.c,v 1.61 2009-02-13 20:19:30 nicm Exp $ */
+/* $Id: key-bindings.c,v 1.62 2009-03-07 09:29:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -77,12 +77,13 @@ key_bindings_init(void)
int key;
const struct cmd_entry *entry;
} table[] = {
+ { '!', &cmd_break_pane_entry },
{ '"', &cmd_split_window_entry },
{ '#', &cmd_list_buffers_entry },
{ '&', &cmd_kill_window_entry },
{ ',', &cmd_command_prompt_entry },
- { '.', &cmd_command_prompt_entry },
{ '-', &cmd_delete_buffer_entry },
+ { '.', &cmd_command_prompt_entry },
{ '0', &cmd_select_window_entry },
{ '1', &cmd_select_window_entry },
{ '2', &cmd_select_window_entry },
diff --git a/tmux.h b/tmux.h
index c992eb8b..7a5212df 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.277 2009-03-04 17:24:07 nicm Exp $ */
+/* $Id: tmux.h,v 1.278 2009-03-07 09:29:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1147,6 +1147,7 @@ struct winlink *cmd_find_window(
extern const struct cmd_entry *cmd_table[];
extern const struct cmd_entry cmd_attach_session_entry;
extern const struct cmd_entry cmd_bind_key_entry;
+extern const struct cmd_entry cmd_break_pane_entry;
extern const struct cmd_entry cmd_choose_session_entry;
extern const struct cmd_entry cmd_choose_window_entry;
extern const struct cmd_entry cmd_clock_mode_entry;
@@ -1469,6 +1470,7 @@ struct winlink *winlink_previous(struct winlinks *, struct winlink *);
void winlink_stack_push(struct winlink_stack *, struct winlink *);
void winlink_stack_remove(struct winlink_stack *, struct winlink *);
int window_index(struct window *, u_int *);
+struct window *window_create1(u_int, u_int);
struct window *window_create(const char *, const char *,
const char *, const char **, u_int, u_int, u_int, char **);
void window_destroy(struct window *);
diff --git a/window.c b/window.c
index e5bd63a8..10637767 100644
--- a/window.c
+++ b/window.c
@@ -1,4 +1,4 @@
-/* $Id: window.c,v 1.69 2009-03-01 22:05:35 nicm Exp $ */
+/* $Id: window.c,v 1.70 2009-03-07 09:29:54 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -201,8 +201,7 @@ window_index(struct window *s, u_int *i)
}
struct window *
-window_create(const char *name, const char *cmd, const char *cwd,
- const char **envp, u_int sx, u_int sy, u_int hlimit, char **cause)
+window_create1(u_int sx, u_int sy)
{
struct window *w;
u_int i;
@@ -229,6 +228,16 @@ window_create(const char *name, const char *cmd, const char *cwd,
ARRAY_ADD(&windows, w);
w->references = 0;
+ return (w);
+}
+
+struct window *
+window_create(const char *name, const char *cmd, const char *cwd,
+ const char **envp, u_int sx, u_int sy, u_int hlimit, char **cause)
+{
+ struct window *w;
+
+ w = window_create1(sx, sy);
if (window_add_pane(w, -1, cmd, cwd, envp, hlimit, cause) == NULL) {
window_destroy(w);
return (NULL);