From 1bc85cb59e90df5ad1d2e4234202315114dbec3b Mon Sep 17 00:00:00 2001 From: Dane Jensen Date: Tue, 14 Apr 2026 12:40:59 -0700 Subject: [PATCH] Adjustment from feedback and slight touchups. --- Makefile.am | 2 +- cmd-find.c | 2 +- cmd-new-pane.c => cmd-split-window.c | 82 +++++++++++++--------------- tmux.1 | 58 +++++++++++--------- 4 files changed, 74 insertions(+), 70 deletions(-) rename cmd-new-pane.c => cmd-split-window.c (82%) diff --git a/Makefile.am b/Makefile.am index c22a9dab..999e9909 100644 --- a/Makefile.am +++ b/Makefile.am @@ -115,7 +115,6 @@ dist_tmux_SOURCES = \ cmd-lock-server.c \ cmd-minimise-pane.c \ cmd-move-window.c \ - cmd-new-pane.c \ cmd-new-session.c \ cmd-new-window.c \ cmd-parse.y \ @@ -145,6 +144,7 @@ dist_tmux_SOURCES = \ cmd-show-options.c \ cmd-show-prompt-history.c \ cmd-source-file.c \ + cmd-split-window.c \ cmd-swap-pane.c \ cmd-tile-float-pane.c \ cmd-swap-window.c \ diff --git a/cmd-find.c b/cmd-find.c index 8b747a1c..747d204a 100644 --- a/cmd-find.c +++ b/cmd-find.c @@ -1030,7 +1030,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item, fs->w = fs->wl->window; fs->wp = fs->w->active; } - break; + goto found; } if (fs->wp == NULL) { if (~flags & CMD_FIND_QUIET) diff --git a/cmd-new-pane.c b/cmd-split-window.c similarity index 82% rename from cmd-new-pane.c rename to cmd-split-window.c index a2e8269a..0789d0dc 100644 --- a/cmd-new-pane.c +++ b/cmd-split-window.c @@ -27,70 +27,58 @@ #include "tmux.h" /* - * Split a window (add a new pane). + * Create a new pane. */ #define NEW_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" -static enum cmd_retval cmd_new_pane_exec(struct cmd *, struct cmdq_item *); +static enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmdq_item *); const struct cmd_entry cmd_new_pane_entry = { .name = "new-pane", .alias = "newp", - .args = { "bc:de:fF:hH:Ikl:m:p:PR:s:S:t:T:w:x:y:vZ", 0, -1, NULL }, + .args = { "bc:de:fF:hH:Ikl:m:M:p:PR:s:S:t:w:x:y:vZ", 0, -1, NULL }, .usage = "[-bdefhIklPvZ] [-c start-directory] [-e environment] " "[-F format] [-H height] [-l size] [-m message] " - "[-R inactive-border-style] [-s style] " + "[-M mode] [-R inactive-border-style] [-s style] " "[-S active-border-style] [-w width] [-x x-position] " - "[-y y-position]" CMD_TARGET_PANE_USAGE "[-T type] " - " [shell-command [argument ...]]", + "[-y y-position]" CMD_TARGET_PANE_USAGE + "[shell-command [argument ...]]", .target = { 't', CMD_FIND_PANE, 0 }, .flags = 0, - .exec = cmd_new_pane_exec + .exec = cmd_split_window_exec }; const struct cmd_entry cmd_split_window_entry = { .name = "split-window", .alias = "splitw", - .args = { "bc:de:fF:hH:Ikl:m:p:PR:s:S:t:T:w:x:y:vZ", 0, -1, NULL }, + .args = { "bc:de:fF:hH:Ikl:m:M:p:PR:s:S:t:w:x:y:vZ", 0, -1, NULL }, .usage = "[-bdefhIklPvZ] [-c start-directory] [-e environment] " "[-F format] [-H height] [-l size] [-m message] " - "[-R inactive-border-style] [-s style] " + "[-M mode] [-R inactive-border-style] [-s style] " "[-S active-border-style] [-w width] [-x x-position] " - "[-y y-position]" CMD_TARGET_PANE_USAGE "[-T type] " - " [shell-command [argument ...]]", + "[-y y-position]" CMD_TARGET_PANE_USAGE + "[shell-command [argument ...]]", .target = { 't', CMD_FIND_PANE, 0 }, .flags = 0, - .exec = cmd_new_pane_exec + .exec = cmd_split_window_exec }; -enum new_pane_type { +enum new_pane_mode { FLOATING, TILED, NONE, }; -static enum new_pane_type -cmd_new_pane_get_type(const char* val) -{ - if (strncmp(val, "floating", (sizeof "floating") - 1) == 0 || - strncmp(val, "f", (sizeof "f") - 1) == 0) - return FLOATING; - if (strncmp(val, "tiled", (sizeof "tiled") - 1) == 0 || - strncmp(val, "t", (sizeof "t") - 1) == 0) - return TILED; - return NONE; -} - static struct layout_cell * -cmd_new_pane_get_floating_layout_cell(struct cmdq_item *item, struct args *args, - struct window *w) +cmd_split_window_get_floating_layout_cell(struct cmdq_item *item, + struct args *args, struct window *w) { struct layout_cell *lc = NULL; char *cause = NULL; @@ -164,8 +152,8 @@ cmd_new_pane_get_floating_layout_cell(struct cmdq_item *item, struct args *args, } static struct layout_cell * -cmd_new_pane_get_tiled_layout_cell(struct cmdq_item *item, struct args *args, - struct window *w, struct window_pane *wp, int flags) +cmd_split_window_get_tiled_layout_cell(struct cmdq_item *item, + struct args *args, struct window *w, struct window_pane *wp, int flags) { enum layout_type type; struct layout_cell *lc = NULL; @@ -222,7 +210,7 @@ cmd_new_pane_get_tiled_layout_cell(struct cmdq_item *item, struct args *args, } static enum cmd_retval -cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item) +cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = cmd_get_args(self); struct cmd_find_state *current = cmdq_get_current(item); @@ -240,20 +228,25 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item) char *cause = NULL, *cp; struct args_value *av; u_int count = args_count(args); - enum new_pane_type pane_type = NONE; + enum new_pane_mode pane_mode = NONE; - if (args_has(args, 'T')) { - pane_type = cmd_new_pane_get_type(args_get(args, 'T')); + if (args_has(args, 'M')) { + if (strcasecmp(args_get(args, 'M'), "f") == 0) + pane_mode = FLOATING; + else if (strcasecmp(args_get(args, 'M'), "t") == 0) + pane_mode = TILED; + else + pane_mode = NONE; } else { if (cmd_get_entry(self) == &cmd_new_pane_entry) - pane_type = FLOATING; + pane_mode = FLOATING; else - pane_type = TILED; + pane_mode = TILED; } input = (args_has(args, 'I') && count == 0); - flags = pane_type == FLOATING ? SPAWN_FLOATING : 0; + flags = pane_mode == FLOATING ? SPAWN_FLOATING : 0; if (args_has(args, 'b')) flags |= SPAWN_BEFORE; if (args_has(args, 'f')) @@ -262,13 +255,16 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item) flags |= SPAWN_EMPTY; - if (pane_type == FLOATING) { - lc = cmd_new_pane_get_floating_layout_cell(item, args, w); - } else if (pane_type == TILED) - lc = cmd_new_pane_get_tiled_layout_cell(item, args, w, wp, + if (pane_mode == FLOATING) + lc = cmd_split_window_get_floating_layout_cell(item, args, w); + else if (pane_mode == TILED) + lc = cmd_split_window_get_tiled_layout_cell(item, args, w, wp, flags); - else - cmdq_error(item, "unrecognized pane type '%s'", args_get(args, 'T')); + else { + cmdq_error(item, "unrecognized pane mode '%s'", + args_get(args, 'M')); + return (CMD_RETURN_ERROR); + } if (lc == NULL) return (CMD_RETURN_ERROR); @@ -345,7 +341,7 @@ cmd_new_pane_exec(struct cmd *self, struct cmdq_item *item) switch (window_pane_start_input(new_wp, item, &cause)) { case -1: server_client_remove_pane(new_wp); - if (pane_type == TILED) + if (pane_mode == TILED) layout_close_pane(new_wp); window_remove_pane(wp->window, new_wp); cmdq_error(item, "%s", cause); diff --git a/tmux.1 b/tmux.1 index 1bf17910..dcb15490 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3330,34 +3330,39 @@ but a different format may be specified with .Op Fl H Ar height .Op Fl l Ar size .Op Fl m Ar message +.Op Fl M Ar mode .Op Fl p Ar percentage .Op Fl R Ar inactive-border-style .Op Fl s Ar style .Op Fl S Ar active-border-style .Op Fl t Ar target-pane -.Op Fl T Ar type .Op Fl w Ar width .Op Fl x Ar x-position .Op Fl y Ar y-position .Op Ar shell-command Op Ar argument ... .Xc .D1 Pq alias: Ic newp -Create a new pane. The new pane may be floating by specifying the -.Ar type -with -.Fl Tf -/ -.Fl Tfloating , -or tiled into the layout by splitting an existing pane with -.Fl Tt -/ -.Fl Ttiled . +Create a new pane. +A +.Ar mode +may be specified with the +.Fl M +option and must be followed by one of the following special values: +.Bl -column "XXXXX" -offset indent +.It Sy "Value" Ta Sy "Meaning" +.It Li "f" Ta "floating pane above the current layout" +.It Li "t" Ta "tiled into the layout by splitting a pane" +.El +.Pp +If no +.Ar mode +is specified, +.Ic f +is assumed. When creating a tiled pane, a target pane may be specified with .Fl t . -Note that some options are related to dimensions/layout. Those options will -only affect one creation -.Ar type -and will be in their own sections. +Note that some options will only affect one +.Ar mode . .Pp If .Fl d @@ -3374,8 +3379,8 @@ sets the border style when the pane is inactive (see .Fl k keeps the pane open after the optional .Ar shell-command -exits and waits for a keypress (any non-mouse key) before closing it. The -message shown is controlled by the +exits and waits for a keypress (any non-mouse key) before closing it. +The message shown is controlled by the .Ic remain-on-exit-format option. .Fl m Ar message @@ -3393,24 +3398,26 @@ The flag (if .Ar shell-command is not specified or empty) -will create an empty pane and forward any output from stdin to it. For example: +will create an empty pane and forward any output from stdin to it. +For example: .Bd -literal -offset indent $ make 2>&1|tmux splitw \-dI & .Ed .Pp -For floating panes, the following flags are availible: +For floating panes, the following options are availible: The .Fl w , .Fl h , .Fl x , and .Fl y -options set the width, height, and position of the pane; if not given, -the pane is sized to half the window dimensions and offset from the -previous floating pane. These four options may be followed by '%' to specify -a percentage of the current window dimensions. +options set the width, height, and position of the pane. +If not given, the pane is sized to half the window dimensions and offset from +the previous floating pane. +These four options may be followed by '%' to specify a percentage of the +current window dimensions. .Pp -For tiled panes, the following flags are availible: +For tiled panes, the following options are availible: .Fl h does a horizontal split and .Fl v @@ -3783,7 +3790,8 @@ the command behaves like .Op Ar shell-command Op Ar argument ... .Xc .D1 Pq alias: Ic splitw -Creates a new pane. Default behavior is to split the pane in a tiled layout. +Creates a new pane. +Default behavior is to split the pane in a tiled layout. Shares behavior with .Ic new-pane . .Pp