Discussion:
[PATCH] select-panes: add wrap-panes window-option
Patrick Börjesson
2014-08-12 16:52:09 UTC
Permalink
Hi everybody!

I just started using tmux and encountered a peculiarity which I couldn't live
with.
When switching between panes with select-pane, the switching "wraps around" when
it encounters the window edge. E.g. if the right-most pane is selected and I try
to switch to the right of the selected pane with "select-pane -R", it wraps
around to the left-most pane.
This behaviour is unacceptable for me, thus this patch I'm hereby sending to you
all. I thought a window-option with the current behaviour as default would be
the best approach to this.

The patch should apply to current 'master' branch.

Comments and critique very welcome. Pleace CC me though, as I'm not subscribed
to the list.

Greetings,
Patrick Börjesson

Patrick Börjesson (1):
select-panes: add wrap-panes window-option

cmd-select-pane.c | 22 +++++++++++++---------
options-table.c | 5 +++++
window.c | 8 ++++----
3 files changed, 22 insertions(+), 13 deletions(-)
--
Patrick Börjesson
Patrick Börjesson
2014-08-12 16:52:10 UTC
Permalink
The flag decides if select-pane should "wrap around" when it encounters
the window edge.

Signed-off-by: Patrick Börjesson <***@gmail.com>
Reviewed-and-Tested-by: Anders Roxell <***@linaro.org>
---
cmd-select-pane.c | 22 +++++++++++++---------
options-table.c | 5 +++++
window.c | 8 ++++----
3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/cmd-select-pane.c b/cmd-select-pane.c
index c342fef..2ae1819 100644
--- a/cmd-select-pane.c
+++ b/cmd-select-pane.c
@@ -66,7 +66,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
- struct window_pane *wp;
+ struct window_pane *wp, *next_wp;

if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
@@ -96,17 +96,21 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
}

if (args_has(self->args, 'L'))
- wp = window_pane_find_left(wp);
+ next_wp = window_pane_find_left(wp);
else if (args_has(self->args, 'R'))
- wp = window_pane_find_right(wp);
+ next_wp = window_pane_find_right(wp);
else if (args_has(self->args, 'U'))
- wp = window_pane_find_up(wp);
+ next_wp = window_pane_find_up(wp);
else if (args_has(self->args, 'D'))
- wp = window_pane_find_down(wp);
- if (wp == NULL) {
- cmdq_error(cmdq, "pane not found");
- return (CMD_RETURN_ERROR);
- }
+ next_wp = window_pane_find_down(wp);
+
+ if (next_wp == NULL) {
+ if (options_get_number(&wl->window->options, "wrap-panes")) {
+ cmdq_error(cmdq, "pane not found");
+ return (CMD_RETURN_ERROR);
+ }
+ } else
+ wp = next_wp;

window_set_active_pane(wl->window, wp);
server_status_window(wl->window);
diff --git a/options-table.c b/options-table.c
index 8d680b3..a124bb4 100644
--- a/options-table.c
+++ b/options-table.c
@@ -510,6 +510,11 @@ const struct options_table_entry window_options_table[] = {
.default_num = 0
},

+ { .name = "wrap-panes",
+ .type = OPTIONS_TABLE_FLAG,
+ .default_num = 1
+ },
+
{ .name = "allow-rename",
.type = OPTIONS_TABLE_FLAG,
.default_num = 1
diff --git a/window.c b/window.c
index e9ec7ea..e992a09 100644
--- a/window.c
+++ b/window.c
@@ -1182,7 +1182,7 @@ window_pane_find_up(struct window_pane *wp)
ARRAY_INIT(&list);

edge = wp->yoff;
- if (edge == 0)
+ if (edge == 0 && options_get_number(&wp->window->options, "wrap-panes"))
edge = wp->window->sy + 1;

left = wp->xoff;
@@ -1225,7 +1225,7 @@ window_pane_find_down(struct window_pane *wp)
ARRAY_INIT(&list);

edge = wp->yoff + wp->sy + 1;
- if (edge >= wp->window->sy)
+ if (edge >= wp->window->sy && options_get_number(&wp->window->options, "wrap-panes"))
edge = 0;

left = wp->xoff;
@@ -1268,7 +1268,7 @@ window_pane_find_left(struct window_pane *wp)
ARRAY_INIT(&list);

edge = wp->xoff;
- if (edge == 0)
+ if (edge == 0 && options_get_number(&wp->window->options, "wrap-panes"))
edge = wp->window->sx + 1;

top = wp->yoff;
@@ -1311,7 +1311,7 @@ window_pane_find_right(struct window_pane *wp)
ARRAY_INIT(&list);

edge = wp->xoff + wp->sx + 1;
- if (edge >= wp->window->sx)
+ if (edge >= wp->window->sx && options_get_number(&wp->window->options, "wrap-panes"))
edge = 0;

top = wp->yoff;
--
2.0.4
Patrick Börjesson
2014-08-12 17:03:45 UTC
Permalink
The flag decides if select-pane should "wrap around" when it encounters
the window edge.

Signed-off-by: Patrick Börjesson <***@gmail.com>
Reviewed-and-Tested-by: Anders Roxell <***@linaro.org>
---
cmd-select-pane.c | 22 +++++++++++++---------
options-table.c | 5 +++++
window.c | 8 ++++----
3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/cmd-select-pane.c b/cmd-select-pane.c
index c342fef..0d57176 100644
--- a/cmd-select-pane.c
+++ b/cmd-select-pane.c
@@ -66,7 +66,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
- struct window_pane *wp;
+ struct window_pane *wp, *next_wp = NULL;

if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
@@ -96,17 +96,21 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
}

if (args_has(self->args, 'L'))
- wp = window_pane_find_left(wp);
+ next_wp = window_pane_find_left(wp);
else if (args_has(self->args, 'R'))
- wp = window_pane_find_right(wp);
+ next_wp = window_pane_find_right(wp);
else if (args_has(self->args, 'U'))
- wp = window_pane_find_up(wp);
+ next_wp = window_pane_find_up(wp);
else if (args_has(self->args, 'D'))
- wp = window_pane_find_down(wp);
- if (wp == NULL) {
- cmdq_error(cmdq, "pane not found");
- return (CMD_RETURN_ERROR);
- }
+ next_wp = window_pane_find_down(wp);
+
+ if (next_wp == NULL) {
+ if (options_get_number(&wl->window->options, "wrap-panes")) {
+ cmdq_error(cmdq, "pane not found");
+ return (CMD_RETURN_ERROR);
+ }
+ } else
+ wp = next_wp;

window_set_active_pane(wl->window, wp);
server_status_window(wl->window);
diff --git a/options-table.c b/options-table.c
index 8d680b3..a124bb4 100644
--- a/options-table.c
+++ b/options-table.c
@@ -510,6 +510,11 @@ const struct options_table_entry window_options_table[] = {
.default_num = 0
},

+ { .name = "wrap-panes",
+ .type = OPTIONS_TABLE_FLAG,
+ .default_num = 1
+ },
+
{ .name = "allow-rename",
.type = OPTIONS_TABLE_FLAG,
.default_num = 1
diff --git a/window.c b/window.c
index e9ec7ea..e992a09 100644
--- a/window.c
+++ b/window.c
@@ -1182,7 +1182,7 @@ window_pane_find_up(struct window_pane *wp)
ARRAY_INIT(&list);

edge = wp->yoff;
- if (edge == 0)
+ if (edge == 0 && options_get_number(&wp->window->options, "wrap-panes"))
edge = wp->window->sy + 1;

left = wp->xoff;
@@ -1225,7 +1225,7 @@ window_pane_find_down(struct window_pane *wp)
ARRAY_INIT(&list);

edge = wp->yoff + wp->sy + 1;
- if (edge >= wp->window->sy)
+ if (edge >= wp->window->sy && options_get_number(&wp->window->options, "wrap-panes"))
edge = 0;

left = wp->xoff;
@@ -1268,7 +1268,7 @@ window_pane_find_left(struct window_pane *wp)
ARRAY_INIT(&list);

edge = wp->xoff;
- if (edge == 0)
+ if (edge == 0 && options_get_number(&wp->window->options, "wrap-panes"))
edge = wp->window->sx + 1;

top = wp->yoff;
@@ -1311,7 +1311,7 @@ window_pane_find_right(struct window_pane *wp)
ARRAY_INIT(&list);

edge = wp->xoff + wp->sx + 1;
- if (edge >= wp->window->sx)
+ if (edge >= wp->window->sx && options_get_number(&wp->window->options, "wrap-panes"))
edge = 0;

top = wp->yoff;
--
Patrick Börjesson
Thomas Adam
2014-08-24 09:15:47 UTC
Permalink
Post by Patrick Börjesson
Hi everybody!
I just started using tmux and encountered a peculiarity which I couldn't live
with.
When switching between panes with select-pane, the switching "wraps around" when
it encounters the window edge. E.g. if the right-most pane is selected and I try
to switch to the right of the selected pane with "select-pane -R", it wraps
around to the left-most pane.
This behaviour is unacceptable for me, thus this patch I'm hereby sending to you
all. I thought a window-option with the current behaviour as default would be
the best approach to this.
We discussed something like this earlier this year:

http://sourceforge.net/p/tmux/tickets/122/

I can't say I'm in favour of your patches.

-- Thomas Adam
--
"Deep in my heart I wish I was wrong. But deep in my heart I know I am
not." -- Morrissey ("Girl Least Likely To" -- off of Viva Hate.)
Nicholas Marriott
2014-08-24 10:35:07 UTC
Permalink
I'm not sure that issue is the same thing but in any case I think supporting multiple wrapping behaviours is a bikeshed too far.

-------- Original message --------
From: Thomas Adam <***@xteddy.org>
Date: 24/08/2014 10:15 (GMT+00:00)
To: Patrick Börjesson <***@gmail.com>
Cc: tmux-***@lists.sourceforge.net
Subject: Re: [PATCH] select-panes: add wrap-panes window-option
Post by Patrick Börjesson
Hi everybody!
I just started using tmux and encountered a peculiarity which I couldn't live
with.
When switching between panes with select-pane, the switching "wraps around" when
it encounters the window edge. E.g. if the right-most pane is selected and I try
to switch to the right of the selected pane with "select-pane -R", it wraps
around to the left-most pane.
This behaviour is unacceptable for me, thus this patch I'm hereby sending to you
all. I thought a window-option with the current behaviour as default would be
the best approach to this.
We discussed something like this earlier this year:

http://sourceforge.net/p/tmux/tickets/122/

I can't say I'm in favour of your patches.

-- Thomas Adam
--
"Deep in my heart I wish I was wrong.  But deep in my heart I know I am
not." -- Morrissey ("Girl Least Likely To" -- off of Viva Hate.)
Patrick Börjesson
2014-08-24 11:24:56 UTC
Permalink
Honestly, for me personally, I'd rather just go with the non-wrapping
behavior as the only behavior. I just added the option because of
backwards-compatibility.

The wrapping behavior being awkward for me stems from having used vim
extensively for many years, and its behavior regarding split-panes is of
the non-wrapping kind.
I'm mostly using tmux in full-screen mode, and use tmux as a window-manager
of sorts. Because of this, I (my brain/eyes) expect to focus to the right
of the current pane when I tell tmux to switch to a pane to the right of
the current one. There's just too much of a disconnect between the
right-most pane and the left-most pane for me to expect it to "wrap
around".

Additionally (this is my specific use-case) I make tmux send keybindings
through to vim so that I can use the same keybindings in tmux and in vim
for switching panes, so I can view the entire tmux workspace (with vim in
some panes) as a cohesive whole, and I don't have to care if it's tmux or
vim panes I'm navigating between. Thus, "switch right" just switches to a
right-more pane, no matter if it's inside vim, or if it's to another
tmux-pane. That behaviour only works if tmux doesn't wrap panes though.

Honestly though, I really don't care if it's included in the main codebase.
The patch is small enough for me to maintain it outside mainline.
I really do think though that this is a change that a lot of people would
want, especially vim-users. Either as a change in default behaviour, or as
an additional option.


On Sun, Aug 24, 2014 at 12:35 PM, Nicholas Marriott <
Post by Nicholas Marriott
I'm not sure that issue is the same thing but in any case I think
supporting multiple wrapping behaviours is a bikeshed too far.
-------- Original message --------
Date: 24/08/2014 10:15 (GMT+00:00)
Subject: Re: [PATCH] select-panes: add wrap-panes window-option
Post by Patrick Börjesson
Hi everybody!
I just started using tmux and encountered a peculiarity which I couldn't
live
Post by Patrick Börjesson
with.
When switching between panes with select-pane, the switching "wraps
around" when
Post by Patrick Börjesson
it encounters the window edge. E.g. if the right-most pane is selected
and I try
Post by Patrick Börjesson
to switch to the right of the selected pane with "select-pane -R", it
wraps
Post by Patrick Börjesson
around to the left-most pane.
This behaviour is unacceptable for me, thus this patch I'm hereby
sending to you
Post by Patrick Börjesson
all. I thought a window-option with the current behaviour as default
would be
Post by Patrick Börjesson
the best approach to this.
http://sourceforge.net/p/tmux/tickets/122/
I can't say I'm in favour of your patches.
-- Thomas Adam
--
"Deep in my heart I wish I was wrong. But deep in my heart I know I am
not." -- Morrissey ("Girl Least Likely To" -- off of Viva Hate.)
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
tmux-users mailing list
https://lists.sourceforge.net/lists/listinfo/tmux-users
Loading...