From ca413cf270d001df59a13dc1978236b2de8261e4 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Fri, 7 Jan 2011 15:02:38 +0000 Subject: Sync OpenBSD patchset 831: Now that parsing is common, merge some of the small, related commands together to use the same code. Also add some arguments (such as -n and -p) to some commands to match existing commands. --- cmd-last-pane.c | 57 ------------------------------ cmd-last-window.c | 57 ------------------------------ cmd-lock-client.c | 52 --------------------------- cmd-lock-server.c | 42 +++++++++++++++++++--- cmd-lock-session.c | 52 --------------------------- cmd-next-layout.c | 53 ---------------------------- cmd-next-window.c | 71 ------------------------------------- cmd-previous-layout.c | 53 ---------------------------- cmd-previous-window.c | 71 ------------------------------------- cmd-select-layout.c | 44 ++++++++++++++++++++--- cmd-select-pane.c | 29 +++++++++++++-- cmd-select-window.c | 89 ++++++++++++++++++++++++++++++++++++++++++----- cmd-set-option.c | 15 ++++++-- cmd-set-window-option.c | 46 ------------------------ cmd-show-options.c | 15 ++++++-- cmd-show-window-options.c | 49 -------------------------- tmux.1 | 32 +++++++++++++++-- 17 files changed, 239 insertions(+), 588 deletions(-) delete mode 100644 cmd-last-pane.c delete mode 100644 cmd-last-window.c delete mode 100644 cmd-lock-client.c delete mode 100644 cmd-lock-session.c delete mode 100644 cmd-next-layout.c delete mode 100644 cmd-next-window.c delete mode 100644 cmd-previous-layout.c delete mode 100644 cmd-previous-window.c delete mode 100644 cmd-set-window-option.c delete mode 100644 cmd-show-window-options.c diff --git a/cmd-last-pane.c b/cmd-last-pane.c deleted file mode 100644 index df6a8fb1..00000000 --- a/cmd-last-pane.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $Id: cmd-last-pane.c,v 1.2 2011-01-07 14:45:34 tcunha Exp $ */ - -/* - * Copyright (c) 2010 Nicholas Marriott - * - * 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 - -#include "tmux.h" - -/* - * Move to last pane. - */ - -int cmd_last_pane_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_last_pane_entry = { - "last-pane", "lastp", - "t:", 0, 0, - CMD_TARGET_WINDOW_USAGE, - 0, - NULL, - NULL, - cmd_last_pane_exec -}; - -int -cmd_last_pane_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct winlink *wl; - struct window *w; - - if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) - return (-1); - w = wl->window; - - if (w->last == NULL) { - ctx->error(ctx, "no last pane"); - return (-1); - } - window_set_active_pane(w, w->last); - - return (0); -} diff --git a/cmd-last-window.c b/cmd-last-window.c deleted file mode 100644 index 4cc1d0b5..00000000 --- a/cmd-last-window.c +++ /dev/null @@ -1,57 +0,0 @@ -/* $Id: cmd-last-window.c,v 1.20 2011-01-07 14:45:34 tcunha Exp $ */ - -/* - * Copyright (c) 2007 Nicholas Marriott - * - * 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 - -#include "tmux.h" - -/* - * Move to last window. - */ - -int cmd_last_window_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_last_window_entry = { - "last-window", "last", - "t:", 0, 0, - CMD_TARGET_SESSION_USAGE, - 0, - NULL, - NULL, - cmd_last_window_exec -}; - -int -cmd_last_window_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct session *s; - - if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) - return (-1); - - if (session_last(s) == 0) - server_redraw_session(s); - else { - ctx->error(ctx, "no last window"); - return (-1); - } - recalculate_sizes(); - - return (0); -} diff --git a/cmd-lock-client.c b/cmd-lock-client.c deleted file mode 100644 index 9d373acb..00000000 --- a/cmd-lock-client.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $Id: cmd-lock-client.c,v 1.3 2011-01-07 14:45:34 tcunha Exp $ */ - -/* - * Copyright (c) 2009 Nicholas Marriott - * - * 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 - -#include "tmux.h" - -/* - * Lock a single client. - */ - -int cmd_lock_client_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_lock_client_entry = { - "lock-client", "lockc", - "t:", 0, 0, - CMD_TARGET_CLIENT_USAGE, - 0, - NULL, - NULL, - cmd_lock_client_exec -}; - -int -cmd_lock_client_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct client *c; - - if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) - return (-1); - - server_lock_client(c); - recalculate_sizes(); - - return (0); -} diff --git a/cmd-lock-server.c b/cmd-lock-server.c index da2b48e7..53efbfdb 100644 --- a/cmd-lock-server.c +++ b/cmd-lock-server.c @@ -1,4 +1,4 @@ -/* $Id: cmd-lock-server.c,v 1.10 2011-01-07 14:45:34 tcunha Exp $ */ +/* $Id: cmd-lock-server.c,v 1.11 2011-01-07 15:02:38 tcunha Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -25,7 +25,7 @@ #include "tmux.h" /* - * Lock server. + * Lock commands. */ int cmd_lock_server_exec(struct cmd *, struct cmd_ctx *); @@ -40,11 +40,45 @@ const struct cmd_entry cmd_lock_server_entry = { cmd_lock_server_exec }; +const struct cmd_entry cmd_lock_session_entry = { + "lock-session", "locks", + "t:", 0, 0, + CMD_TARGET_SESSION_USAGE, + 0, + NULL, + NULL, + cmd_lock_server_exec +}; + +const struct cmd_entry cmd_lock_client_entry = { + "lock-client", "lockc", + "t:", 0, 0, + CMD_TARGET_CLIENT_USAGE, + 0, + NULL, + NULL, + cmd_lock_server_exec +}; + /* ARGSUSED */ int -cmd_lock_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx) +cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx) { - server_lock(); + struct args *args = self->args; + struct client *c; + struct session *s; + + if (self->entry == &cmd_lock_server_entry) + server_lock(); + else if (self->entry == &cmd_lock_session_entry) { + if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) + return (-1); + server_lock_session(s); + } else { + if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) + return (-1); + server_lock_client(c); + } recalculate_sizes(); return (0); diff --git a/cmd-lock-session.c b/cmd-lock-session.c deleted file mode 100644 index aa49aed5..00000000 --- a/cmd-lock-session.c +++ /dev/null @@ -1,52 +0,0 @@ -/* $Id: cmd-lock-session.c,v 1.3 2011-01-07 14:45:34 tcunha Exp $ */ - -/* - * Copyright (c) 2009 Nicholas Marriott - * - * 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 - -#include "tmux.h" - -/* - * Lock all clients attached to a session. - */ - -int cmd_lock_session_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_lock_session_entry = { - "lock-session", "locks", - "t:", 0, 0, - CMD_TARGET_SESSION_USAGE, - 0, - NULL, - NULL, - cmd_lock_session_exec -}; - -int -cmd_lock_session_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct session *s; - - if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) - return (-1); - - server_lock_session(s); - recalculate_sizes(); - - return (0); -} diff --git a/cmd-next-layout.c b/cmd-next-layout.c deleted file mode 100644 index 764fc9d8..00000000 --- a/cmd-next-layout.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $Id: cmd-next-layout.c,v 1.7 2011-01-07 14:45:34 tcunha Exp $ */ - -/* - * Copyright (c) 2009 Nicholas Marriott - * - * 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 - -#include "tmux.h" - -/* - * Switch window to next layout. - */ - -int cmd_next_layout_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_next_layout_entry = { - "next-layout", "nextl", - "t:", 0, 0, - CMD_TARGET_WINDOW_USAGE, - 0, - NULL, - NULL, - cmd_next_layout_exec -}; - -int -cmd_next_layout_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct winlink *wl; - u_int layout; - - if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) - return (-1); - - layout = layout_set_next(wl->window); - ctx->info(ctx, "arranging in: %s", layout_set_name(layout)); - - return (0); -} diff --git a/cmd-next-window.c b/cmd-next-window.c deleted file mode 100644 index 17785dfc..00000000 --- a/cmd-next-window.c +++ /dev/null @@ -1,71 +0,0 @@ -/* $Id: cmd-next-window.c,v 1.22 2011-01-07 14:45:34 tcunha Exp $ */ - -/* - * Copyright (c) 2007 Nicholas Marriott - * - * 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 - -#include "tmux.h" - -/* - * Move to next window. - */ - -void cmd_next_window_key_binding(struct cmd *, int); -int cmd_next_window_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_next_window_entry = { - "next-window", "next", - "at:", 0, 0, - "[-a] " CMD_TARGET_SESSION_USAGE, - 0, - cmd_next_window_key_binding, - NULL, - cmd_next_window_exec -}; - -void -cmd_next_window_key_binding(struct cmd *self, int key) -{ - self->args = args_create(0); - if (key == ('n' | KEYC_ESCAPE)) - args_set(self->args, 'a', NULL); -} - -int -cmd_next_window_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct session *s; - int activity; - - if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) - return (-1); - - activity = 0; - if (args_has(self->args, 'a')) - activity = 1; - - if (session_next(s, activity) == 0) - server_redraw_session(s); - else { - ctx->error(ctx, "no next window"); - return (-1); - } - recalculate_sizes(); - - return (0); -} diff --git a/cmd-previous-layout.c b/cmd-previous-layout.c deleted file mode 100644 index 60b7b61c..00000000 --- a/cmd-previous-layout.c +++ /dev/null @@ -1,53 +0,0 @@ -/* $Id: cmd-previous-layout.c,v 1.7 2011-01-07 14:45:34 tcunha Exp $ */ - -/* - * Copyright (c) 2009 Nicholas Marriott - * - * 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 - -#include "tmux.h" - -/* - * Switch window to previous layout. - */ - -int cmd_previous_layout_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_previous_layout_entry = { - "previous-layout", "prevl", - "t:", 0, 0, - CMD_TARGET_WINDOW_USAGE, - 0, - NULL, - NULL, - cmd_previous_layout_exec -}; - -int -cmd_previous_layout_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct winlink *wl; - u_int layout; - - if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) - return (-1); - - layout = layout_set_previous(wl->window); - ctx->info(ctx, "arranging in: %s", layout_set_name(layout)); - - return (0); -} diff --git a/cmd-previous-window.c b/cmd-previous-window.c deleted file mode 100644 index 7d70d3ca..00000000 --- a/cmd-previous-window.c +++ /dev/null @@ -1,71 +0,0 @@ -/* $Id: cmd-previous-window.c,v 1.22 2011-01-07 14:45:34 tcunha Exp $ */ - -/* - * Copyright (c) 2007 Nicholas Marriott - * - * 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 - -#include "tmux.h" - -/* - * Move to previous window. - */ - -void cmd_previous_window_key_binding(struct cmd *, int); -int cmd_previous_window_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_previous_window_entry = { - "previous-window", "prev", - "at:", 0, 0, - "[-a] " CMD_TARGET_SESSION_USAGE, - 0, - cmd_previous_window_key_binding, - NULL, - cmd_previous_window_exec -}; - -void -cmd_previous_window_key_binding(struct cmd *self, int key) -{ - self->args = args_create(0); - if (key == ('p' | KEYC_ESCAPE)) - args_set(self->args, 'a', NULL); -} - -int -cmd_previous_window_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - struct session *s; - int activity; - - if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL) - return (-1); - - activity = 0; - if (args_has(self->args, 'a')) - activity = 1; - - if (session_previous(s, activity) == 0) - server_redraw_session(s); - else { - ctx->error(ctx, "no previous window"); - return (-1); - } - recalculate_sizes(); - - return (0); -} diff --git a/cmd-select-layout.c b/cmd-select-layout.c index a0d157dc..cad1893b 100644 --- a/cmd-select-layout.c +++ b/cmd-select-layout.c @@ -1,4 +1,4 @@ -/* $Id: cmd-select-layout.c,v 1.13 2011-01-07 14:45:34 tcunha Exp $ */ +/* $Id: cmd-select-layout.c,v 1.14 2011-01-07 15:02:38 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -29,14 +29,34 @@ int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_select_layout_entry = { "select-layout", "selectl", - "t:", 0, 1, - CMD_TARGET_WINDOW_USAGE " [layout-name]", + "npt:", 0, 1, + "[-np] " CMD_TARGET_WINDOW_USAGE " [layout-name]", 0, cmd_select_layout_key_binding, NULL, cmd_select_layout_exec }; +const struct cmd_entry cmd_next_layout_entry = { + "next-layout", "nextl", + "t:", 0, 0, + CMD_TARGET_WINDOW_USAGE, + 0, + NULL, + NULL, + cmd_select_layout_exec +}; + +const struct cmd_entry cmd_previous_layout_entry = { + "previous-layout", "prevl", + "t:", 0, 0, + CMD_TARGET_WINDOW_USAGE, + 0, + NULL, + NULL, + cmd_select_layout_exec +}; + void cmd_select_layout_key_binding(struct cmd *self, int key) { @@ -68,11 +88,27 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx) struct args *args = self->args; struct winlink *wl; const char *layoutname; - int layout; + int next, previous, layout; if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) return (-1); + next = self->entry == &cmd_next_layout_entry; + if (args_has(self->args, 'n')) + next = 1; + previous = self->entry == &cmd_previous_layout_entry; + if (args_has(self->args, 'p')) + previous = 1; + + if (next || previous) { + if (next) + layout = layout_set_next(wl->window); + else + layout = layout_set_previous(wl->window); + ctx->info(ctx, "arranging in: %s", layout_set_name(layout)); + return (0); + } + if (args->argc == 0) layout = wl->window->lastlayout; else diff --git a/cmd-select-pane.c b/cmd-select-pane.c index 8fa71072..c490ab38 100644 --- a/cmd-select-pane.c +++ b/cmd-select-pane.c @@ -1,4 +1,4 @@ -/* $Id: cmd-select-pane.c,v 1.14 2011-01-07 14:45:34 tcunha Exp $ */ +/* $Id: cmd-select-pane.c,v 1.15 2011-01-07 15:02:38 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -29,14 +29,24 @@ int cmd_select_pane_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_select_pane_entry = { "select-pane", "selectp", - "DLRt:U", 0, 0, - "[-DLRU] " CMD_TARGET_PANE_USAGE, + "lDLRt:U", 0, 0, + "[-lDLRU] " CMD_TARGET_PANE_USAGE, 0, cmd_select_pane_key_binding, NULL, cmd_select_pane_exec }; +const struct cmd_entry cmd_last_pane_entry = { + "last-pane", "lastp", + "t:", 0, 0, + CMD_TARGET_WINDOW_USAGE, + 0, + NULL, + NULL, + cmd_select_pane_exec +}; + void cmd_select_pane_key_binding(struct cmd *self, int key) { @@ -60,6 +70,19 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx) struct winlink *wl; struct window_pane *wp; + if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) { + wl = cmd_find_window(ctx, args_get(args, 't'), NULL); + if (wl == NULL) + return (-1); + + if (wl->window->last == NULL) { + ctx->error(ctx, "no last pane"); + return (-1); + } + window_set_active_pane(wl->window, wl->window->last); + return (0); + } + if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL) return (-1); diff --git a/cmd-select-window.c b/cmd-select-window.c index 83e38ee9..61176d35 100644 --- a/cmd-select-window.c +++ b/cmd-select-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-select-window.c,v 1.25 2011-01-07 14:45:34 tcunha Exp $ */ +/* $Id: cmd-select-window.c,v 1.26 2011-01-07 15:02:38 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -31,23 +31,56 @@ int cmd_select_window_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_select_window_entry = { "select-window", "selectw", - "t:", 0, 0, - CMD_TARGET_WINDOW_USAGE, + "lnpt:", 0, 0, + "[-lnp] " CMD_TARGET_WINDOW_USAGE, + 0, + cmd_select_window_key_binding, + NULL, + cmd_select_window_exec +}; + +const struct cmd_entry cmd_next_window_entry = { + "next-window", "next", + "at:", 0, 0, + "[-a] " CMD_TARGET_SESSION_USAGE, + 0, + cmd_select_window_key_binding, + NULL, + cmd_select_window_exec +}; + +const struct cmd_entry cmd_previous_window_entry = { + "previous-window", "prev", + "at:", 0, 0, + "[-a] " CMD_TARGET_SESSION_USAGE, 0, cmd_select_window_key_binding, NULL, cmd_select_window_exec }; +const struct cmd_entry cmd_last_window_entry = { + "last-window", "last", + "t:", 0, 0, + CMD_TARGET_SESSION_USAGE, + 0, + NULL, + NULL, + cmd_select_window_exec +}; + void cmd_select_window_key_binding(struct cmd *self, int key) { char tmp[16]; - xsnprintf(tmp, sizeof tmp, ":%d", key - '0'); - self->args = args_create(0); - args_set(self->args, 't', tmp); + if (key >= '0' && key <= '9') { + xsnprintf(tmp, sizeof tmp, ":%d", key - '0'); + args_set(self->args, 't', tmp); + } + if (key == ('n' | KEYC_ESCAPE) || key == ('p' | KEYC_ESCAPE)) + args_set(self->args, 'a', NULL); } int @@ -56,12 +89,50 @@ cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx) struct args *args = self->args; struct winlink *wl; struct session *s; + int next, previous, last, activity; - if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) - return (-1); + next = self->entry == &cmd_next_window_entry; + if (args_has(self->args, 'n')) + next = 1; + previous = self->entry == &cmd_previous_window_entry; + if (args_has(self->args, 'p')) + previous = 1; + last = self->entry == &cmd_last_window_entry; + if (args_has(self->args, 'l')) + last = 1; + + if (next || previous || last) { + s = cmd_find_session(ctx, args_get(args, 't')); + if (s == NULL) + return (-1); + + activity = args_has(self->args, 'a'); + if (next) { + if (session_next(s, activity) != 0) { + ctx->error(ctx, "no next window"); + return (-1); + } + } else if (previous) { + if (session_previous(s, activity) != 0) { + ctx->error(ctx, "no previous window"); + return (-1); + } + } else { + if (session_last(s) != 0) { + ctx->error(ctx, "no last window"); + return (-1); + } + } - if (session_select(s, wl->idx) == 0) server_redraw_session(s); + } else { + wl = cmd_find_window(ctx, args_get(args, 't'), &s); + if (wl == NULL) + return (-1); + + if (session_select(s, wl->idx) == 0) + server_redraw_session(s); + } recalculate_sizes(); return (0); diff --git a/cmd-set-option.c b/cmd-set-option.c index 8e052c2d..88922db7 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $Id: cmd-set-option.c,v 1.106 2011-01-07 14:51:54 tcunha Exp $ */ +/* $Id: cmd-set-option.c,v 1.107 2011-01-07 15:02:38 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -68,6 +68,16 @@ const struct cmd_entry cmd_set_option_entry = { cmd_set_option_exec }; +const struct cmd_entry cmd_set_window_option_entry = { + "set-window-option", "setw", + "agt:u", 1, 2, + "[-agu] " CMD_TARGET_WINDOW_USAGE " option [value]", + 0, + NULL, + NULL, + cmd_set_option_exec +}; + int cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) { @@ -87,7 +97,8 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(self->args, 's')) { oo = &global_options; table = server_options_table; - } else if (args_has(self->args, 'w')) { + } else if (args_has(self->args, 'w') || + self->entry == &cmd_set_window_option_entry) { table = window_options_table; if (args_has(self->args, 'g')) oo = &global_w_options; diff --git a/cmd-set-window-option.c b/cmd-set-window-option.c deleted file mode 100644 index 1ed152ff..00000000 --- a/cmd-set-window-option.c +++ /dev/null @@ -1,46 +0,0 @@ -/* $Id: cmd-set-window-option.c,v 1.44 2011-01-07 14:45:34 tcunha Exp $ */ - -/* - * Copyright (c) 2008 Nicholas Marriott - * - * 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 - -#include "tmux.h" - -/* - * Set a window option. This is just an alias for set-option -w. - */ - -int cmd_set_window_option_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_set_window_option_entry = { - "set-window-option", "setw", - "agt:u", 1, 2, - "[-agu] " CMD_TARGET_WINDOW_USAGE " option [value]", - 0, - NULL, - NULL, - cmd_set_window_option_exec -}; - -int -cmd_set_window_option_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - - args_set(args, 'w', NULL); - return (cmd_set_option_entry.exec(self, ctx)); -} diff --git a/cmd-show-options.c b/cmd-show-options.c index 4e3a72ab..4b44ab26 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -1,4 +1,4 @@ -/* $Id: cmd-show-options.c,v 1.23 2011-01-07 14:45:34 tcunha Exp $ */ +/* $Id: cmd-show-options.c,v 1.24 2011-01-07 15:02:38 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -39,6 +39,16 @@ const struct cmd_entry cmd_show_options_entry = { cmd_show_options_exec }; +const struct cmd_entry cmd_show_window_options_entry = { + "show-window-options", "showw", + "gt:", 0, 0, + "[-g] " CMD_TARGET_WINDOW_USAGE, + 0, + NULL, + NULL, + cmd_show_options_exec +}; + int cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) { @@ -53,7 +63,8 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(self->args, 's')) { oo = &global_options; table = server_options_table; - } else if (args_has(self->args, 'w')) { + } else if (args_has(self->args, 'w') || + self->entry == &cmd_show_window_options_entry) { table = window_options_table; if (args_has(self->args, 'g')) oo = &global_w_options; diff --git a/cmd-show-window-options.c b/cmd-show-window-options.c deleted file mode 100644 index 0709954d..00000000 --- a/cmd-show-window-options.c +++ /dev/null @@ -1,49 +0,0 @@ -/* $Id: cmd-show-window-options.c,v 1.16 2011-01-07 14:45:34 tcunha Exp $ */ - -/* - * Copyright (c) 2008 Nicholas Marriott - * - * 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 - -#include -#include - -#include "tmux.h" - -/* - * Show window options. This is an alias for show-options -w. - */ - -int cmd_show_window_options_exec(struct cmd *, struct cmd_ctx *); - -const struct cmd_entry cmd_show_window_options_entry = { - "show-window-options", "showw", - "gt:", 0, 0, - "[-g] " CMD_TARGET_WINDOW_USAGE, - 0, - NULL, - NULL, - cmd_show_window_options_exec -}; - -int -cmd_show_window_options_exec(struct cmd *self, struct cmd_ctx *ctx) -{ - struct args *args = self->args; - - args_set(args, 'w', NULL); - return (cmd_show_options_entry.exec(self, ctx)); -} diff --git a/tmux.1 b/tmux.1 index 6e411368..ed5a75b1 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.286 2011-01-07 14:34:45 tcunha Exp $ +.\" $Id: tmux.1,v 1.287 2011-01-07 15:02:38 tcunha Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -1259,6 +1259,7 @@ lower) with .Fl U or downward (numerically higher). .It Xo Ic select-layout +.Op Fl np .Op Fl t Ar target-window .Op Ar layout-name .Xc @@ -1267,8 +1268,16 @@ Choose a specific layout for a window. If .Ar layout-name is not given, the last preset layout used (if any) is reapplied. +.Fl n +and +.Fl p +are equivalent to the +.Ic next-layout +and +.Ic previous-layout +commands. .It Xo Ic select-pane -.Op Fl DLRU +.Op Fl lDLRU .Op Fl t Ar target-pane .Xc .D1 (alias: Ic selectp ) @@ -1284,10 +1293,27 @@ or .Fl U is used, respectively the pane below, to the left, to the right, or above the target pane is used. -.It Ic select-window Op Fl t Ar target-window +.Fl l +is the same as using the +.Ic last-pane +command. +.It Xo Ic select-window +.Op Fl lnp +.Op Fl t Ar target-window +.Xc .D1 (alias: Ic selectw ) Select the window at .Ar target-window . +.Fl l , +.Fl n +and +.Fl p +are equivalent to the +.Ic last-window , +.Ic next-window +and +.Ic previous-window +commands. .It Xo Ic split-window .Op Fl dhvP .Oo Fl l -- cgit v1.2.3