Hi

I have made a few changes to your diff, an updated one is below:

- The variable names are very long which means some of the lines are
  either too long or need to wrap so I made them a lot shorter.

- It is not necessary to check if args_get('x') is NULL if we know
  args_has('x') is true - in fact we can just do args_get instead of
  args_has.

- I forgot that join-pane also has -p so I changed it too (it is much
  the same code as split-window).

- I think we can remove -p from the man page since the "-l 10%" form is
  clearly better. It is still supported in the code for backwards
  compatibility.

Let me know if you see any problems.

Thanks!


Index: cmd-join-pane.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/cmd-join-pane.c,v
retrieving revision 1.35
diff -u -p -r1.35 cmd-join-pane.c
--- cmd-join-pane.c     20 Jun 2019 11:59:59 -0000      1.35
+++ cmd-join-pane.c     14 Oct 2019 09:58:24 -0000
@@ -21,6 +21,7 @@
 
 #include <paths.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include "tmux.h"
@@ -36,7 +37,7 @@ const struct cmd_entry cmd_join_pane_ent
        .alias = "joinp",
 
        .args = { "bdhvp:l:s:t:", 0, 0 },
-       .usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
+       .usage = "[-bdhv] [-l size] " CMD_SRCDST_PANE_USAGE,
 
        .source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
        .target = { 't', CMD_FIND_PANE, 0 },
@@ -68,11 +69,13 @@ cmd_join_pane_exec(struct cmd *self, str
        struct winlink          *src_wl, *dst_wl;
        struct window           *src_w, *dst_w;
        struct window_pane      *src_wp, *dst_wp;
-       char                    *cause;
-       int                      size, percentage, dst_idx;
+       char                    *cause, *copy;
+       const char              *errstr, *p;
+       size_t                   plen;
+       int                      size, percentage, dst_idx, not_same_window;
+       int                      flags;
        enum layout_type         type;
        struct layout_cell      *lc;
-       int                      not_same_window, flags;
 
        if (self->entry == &cmd_join_pane_entry)
                not_same_window = 1;
@@ -105,12 +108,28 @@ cmd_join_pane_exec(struct cmd *self, str
                type = LAYOUT_LEFTRIGHT;
 
        size = -1;
-       if (args_has(args, 'l')) {
-               size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
-               if (cause != NULL) {
-                       cmdq_error(item, "size %s", cause);
-                       free(cause);
-                       return (CMD_RETURN_ERROR);
+       if ((p = args_get(args, 'l')) != NULL) {
+               plen = strlen(p);
+               if (p[plen - 1] == '%') {
+                       copy = xstrdup(p);
+                       copy[plen - 1] = '\0';
+                       percentage = strtonum(copy, 0, INT_MAX, &errstr);
+                       free(copy);
+                       if (errstr != NULL) {
+                               cmdq_error(item, "percentage %s", errstr);
+                               return (CMD_RETURN_ERROR);
+                       }
+                       if (type == LAYOUT_TOPBOTTOM)
+                               size = (dst_wp->sy * percentage) / 100;
+                       else
+                               size = (dst_wp->sx * percentage) / 100;
+               } else {
+                       size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
+                       if (cause != NULL) {
+                               cmdq_error(item, "size %s", cause);
+                               free(cause);
+                               return (CMD_RETURN_ERROR);
+                       }
                }
        } else if (args_has(args, 'p')) {
                percentage = args_strtonum(args, 'p', 0, 100, &cause);
Index: cmd-resize-pane.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/cmd-resize-pane.c,v
retrieving revision 1.38
diff -u -p -r1.38 cmd-resize-pane.c
--- cmd-resize-pane.c   6 Jul 2019 20:56:34 -0000       1.38
+++ cmd-resize-pane.c   14 Oct 2019 09:58:24 -0000
@@ -19,6 +19,7 @@
 #include <sys/types.h>
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "tmux.h"
 
@@ -55,10 +56,11 @@ cmd_resize_pane_exec(struct cmd *self, s
        struct window           *w = wl->window;
        struct client           *c = item->client;
        struct session          *s = item->target.s;
-       const char              *errstr;
-       char                    *cause;
+       const char              *errstr, *p;
+       char                    *cause, *copy;
        u_int                    adjust;
-       int                      x, y;
+       int                      x, y, percentage;
+       size_t                   plen;
 
        if (args_has(args, 'M')) {
                if (cmd_mouse_window(&shared->mouse, &s) == NULL)
@@ -91,21 +93,58 @@ cmd_resize_pane_exec(struct cmd *self, s
                }
        }
 
-       if (args_has(args, 'x')) {
-               x = args_strtonum(args, 'x', PANE_MINIMUM, INT_MAX, &cause);
-               if (cause != NULL) {
-                       cmdq_error(item, "width %s", cause);
-                       free(cause);
-                       return (CMD_RETURN_ERROR);
+       if ((p = args_get(args, 'x')) != NULL) {
+               plen = strlen(p);
+               if (p[plen - 1] == '%') {
+                       copy = xstrdup(p);
+                       copy[plen - 1] = '\0';
+                       percentage = strtonum(copy, 0, INT_MAX, &errstr);
+                       free(copy);
+                       if (errstr != NULL) {
+                               cmdq_error(item, "width %s", errstr);
+                               return (CMD_RETURN_ERROR);
+                       }
+                       x = (w->sx * percentage) / 100;
+                       if (x < PANE_MINIMUM)
+                               x = PANE_MINIMUM;
+                       if (x > INT_MAX)
+                               x = INT_MAX;
+               } else {
+                       x = args_strtonum(args, 'x', PANE_MINIMUM, INT_MAX,
+                           &cause);
+                       if (cause != NULL) {
+                               cmdq_error(item, "width %s", cause);
+                               free(cause);
+                               return (CMD_RETURN_ERROR);
+                       }
                }
                layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
        }
-       if (args_has(args, 'y')) {
-               y = args_strtonum(args, 'y', PANE_MINIMUM, INT_MAX, &cause);
-               if (cause != NULL) {
-                       cmdq_error(item, "height %s", cause);
-                       free(cause);
-                       return (CMD_RETURN_ERROR);
+       if ((p = args_get(args, 'y')) != NULL) {
+               plen = strlen(p);
+               if (p[plen - 1] == '%') {
+                       copy = xstrdup(p);
+                       copy[plen - 1] = '\0';
+                       percentage = strtonum(copy, 0, INT_MAX, &errstr);
+                       free(copy);
+                       if (errstr != NULL) {
+                               cmdq_error(item, "height %s", errstr);
+                               return (CMD_RETURN_ERROR);
+                       }
+                       y = (w->sy * percentage) / 100;
+                       if (y < PANE_MINIMUM)
+                               y = PANE_MINIMUM;
+                       if (y > INT_MAX)
+                               y = INT_MAX;
+               }
+               else {
+                       y = args_strtonum(args, 'y', PANE_MINIMUM, INT_MAX,
+                           &cause);
+                       if (cause != NULL) {
+                               cmdq_error(item, "height %s", cause);
+                               free(cause);
+                               return (CMD_RETURN_ERROR);
+                       }
                }
                layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
        }
Index: cmd-split-window.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/cmd-split-window.c,v
retrieving revision 1.95
diff -u -p -r1.95 cmd-split-window.c
--- cmd-split-window.c  3 May 2019 20:44:24 -0000       1.95
+++ cmd-split-window.c  14 Oct 2019 09:58:24 -0000
@@ -42,8 +42,7 @@ const struct cmd_entry cmd_split_window_
 
        .args = { "bc:de:fF:hIl:p:Pt:v", 0, -1 },
        .usage = "[-bdefhIPv] [-c start-directory] [-e environment] "
-                "[-F format] [-p percentage|-l size] " CMD_TARGET_PANE_USAGE
-                " [command]",
+                "[-F format] [-l size] " CMD_TARGET_PANE_USAGE " [command]",
 
        .target = { 't', CMD_FIND_PANE, 0 },
 
@@ -65,20 +64,37 @@ cmd_split_window_exec(struct cmd *self, 
        struct layout_cell      *lc;
        struct cmd_find_state    fs;
        int                      size, percentage, flags, input;
-       const char              *template, *add;
-       char                    *cause, *cp;
+       const char              *template, *add, *errstr, *p;
+       char                    *cause, *cp, *copy;
+       size_t                   plen;
        struct args_value       *value;
 
        if (args_has(args, 'h'))
                type = LAYOUT_LEFTRIGHT;
        else
                type = LAYOUT_TOPBOTTOM;
-       if (args_has(args, 'l')) {
-               size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
-               if (cause != NULL) {
-                       cmdq_error(item, "create pane failed: -l %s", cause);
-                       free(cause);
-                       return (CMD_RETURN_ERROR);
+       if ((p = args_get(args, 'l')) != NULL) {
+               plen = strlen(p);
+               if (p[plen - 1] == '%') {
+                       copy = xstrdup(p);
+                       copy[plen - 1] = '\0';
+                       percentage = strtonum(copy, 0, INT_MAX, &errstr);
+                       free(copy);
+                       if (errstr != NULL) {
+                               cmdq_error(item, "percentage %s", errstr);
+                               return (CMD_RETURN_ERROR);
+                       }
+                       if (type == LAYOUT_TOPBOTTOM)
+                               size = (wp->sy * percentage) / 100;
+                       else
+                               size = (wp->sx * percentage) / 100;
+               } else {
+                       size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
+                       if (cause != NULL) {
+                               cmdq_error(item, "lines %s", cause);
+                               free(cause);
+                               return (CMD_RETURN_ERROR);
+                       }
                }
        } else if (args_has(args, 'p')) {
                percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
Index: tmux.1
===================================================================
RCS file: /cvs/src/usr.bin/tmux/tmux.1,v
retrieving revision 1.689
diff -u -p -r1.689 tmux.1
--- tmux.1      19 Sep 2019 09:02:30 -0000      1.689
+++ tmux.1      14 Oct 2019 09:58:24 -0000
@@ -1891,9 +1891,7 @@ zooms the pane.
 This command works only if at least one client is attached.
 .It Xo Ic join-pane
 .Op Fl bdhv
-.Oo Fl l
-.Ar size |
-.Fl p Ar percentage Oc
+.Op Fl l Ar size
 .Op Fl s Ar src-pane
 .Op Fl t Ar dst-pane
 .Xc
@@ -2030,9 +2028,7 @@ flag, see the
 section.
 .It Xo Ic move-pane
 .Op Fl bdhv
-.Oo Fl l
-.Ar size |
-.Fl p Ar percentage Oc
+.Op Fl l Ar size
 .Op Fl s Ar src-pane
 .Op Fl t Ar dst-pane
 .Xc
@@ -2241,8 +2237,14 @@ or
 .Fl y .
 The
 .Ar adjustment
-is given in lines or cells (the default is 1).
-.Pp
+is given in lines or columns (the default is 1);
+.Fl x
+and
+.Fl y
+may be a given as a number of lines or columns or followed by
+.Ql %
+for a percentage of the window size (for example
+.Ql -x 10% ) .
 With
 .Fl Z ,
 the active pane is toggled between zoomed (occupying the whole of the window)
@@ -2434,9 +2436,7 @@ the command behaves like
 .Op Fl bdfhIvP
 .Op Fl c Ar start-directory
 .Op Fl e Ar environment
-.Oo Fl l
-.Ar size |
-.Fl p Ar percentage Oc
+.Op Fl l Ar size
 .Op Fl t Ar target-pane
 .Op Ar shell-command
 .Op Fl F Ar format
@@ -2452,10 +2452,12 @@ a vertical split; if neither is specifie
 is assumed.
 The
 .Fl l
-and
-.Fl p
-options specify the size of the new pane in lines (for vertical split) or in
-cells (for horizontal split), or as a percentage, respectively.
+option specifies the size of the new pane in lines (for vertical split) or in
+columns (for horizontal split);
+.Ar size
+may be followed by
+.Ql %
+to specify a percentage of the available space.
 The
 .Fl b
 option causes the new pane to be created to the left of or above

-- 
You received this message because you are subscribed to the Google Groups 
"tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/tmux-users/20191014095919.krsccppowuyqvs5m%40yelena.

Reply via email to