I appreciate the patch that went in a while back to add "copy-mode -e",
allowing to automatically exit copy-mode when reaching the bottom of the
buffer.  But I find that this functionality is a bit of "spooky action at a
distance": the decision to exit depends not on the input the caused the
scroll-down, but instead of the input that initially scrolled up.

I've put together a small patch to allow opting into the auto-exit behavior
on scroll-down commands instead.  Currently I've overloaded the send-keys
-R argument (which seems somewhat appropriate given that exiting copy-mode
is a sort of "reset"), but I'd also be happy to find a different way to
pass the option (either adding an additional argument to send-keys, or
adding scroll-down, etc, to the 1-arg branch so that you'd write "send-keys
-X scroll-down -e", though in that case I'm not sure what to do if the
argument is anything *other* than -e - currently it silently does nothing
if a command has the wrong (number of) arguments, which isn't great.

Please let me know how to proceed so that this functionality can be added.
Or if you'd rather continue on a GitHub pull request, that would be great
as well.

Thanks!
steve

-- 
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 post to this group, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
From 9b3196b45dcffc8cd97df4ddc7472d9d072207e6 Mon Sep 17 00:00:00 2001
From: Stephen Hicks <[email protected]>
Date: Wed, 25 Oct 2017 11:29:09 -0700
Subject: [PATCH] Allow scroll/page-down commands to optionally cancel
 copy-mode.

These copy-mode commands now read the -R option from send-keys, which previously did nothing.  This provides an alternative to keying off of a special flag sent when *entering* copy-mode, which allows for less "spooky action at a distance": the decision for automatically exiting if at the bottom depends only on which keypress scrolled down, rather than what initially scrolled up.  The overloading of "reset terminal state" seems reasonably appropriate, since we are optionally resetting to normal mode.
---
 window-copy.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/window-copy.c b/window-copy.c
index 09ccc26c..2e2a5110 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -30,7 +30,7 @@ static void	window_copy_command(struct window_pane *, struct client *,
 static struct screen *window_copy_init(struct window_pane *,
 		    struct cmd_find_state *, struct args *);
 static void	window_copy_free(struct window_pane *);
-static int	window_copy_pagedown(struct window_pane *, int);
+static int	window_copy_pagedown(struct window_pane *, int, int);
 static void	window_copy_next_paragraph(struct window_pane *);
 static void	window_copy_previous_paragraph(struct window_pane *);
 static void	window_copy_resize(struct window_pane *, u_int, u_int);
@@ -392,7 +392,7 @@ window_copy_pageup(struct window_pane *wp, int half_page)
 }
 
 static int
-window_copy_pagedown(struct window_pane *wp, int half_page)
+window_copy_pagedown(struct window_pane *wp, int half_page, int scroll_exit)
 {
 	struct window_copy_mode_data	*data = wp->modedata;
 	struct screen			*s = &data->screen;
@@ -431,7 +431,7 @@ window_copy_pagedown(struct window_pane *wp, int half_page)
 			window_copy_cursor_end_of_line(wp);
 	}
 
-	if (data->scroll_exit && data->oy == 0)
+	if (scroll_exit && data->oy == 0)
 		return (1);
 	window_copy_update_selection(wp, 1);
 	window_copy_redraw_screen(wp);
@@ -630,8 +630,9 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
 		if (strcmp(command, "end-of-line") == 0)
 			window_copy_cursor_end_of_line(wp);
 		if (strcmp(command, "halfpage-down") == 0) {
+			int exit = args_has(args, 'R') || data->scroll_exit;
 			for (; np != 0; np--) {
-				if (window_copy_pagedown(wp, 1)) {
+				if (window_copy_pagedown(wp, 1, exit)) {
 					cancel = 1;
 					break;
 				}
@@ -728,8 +729,9 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
 				window_copy_other_end(wp);
 		}
 		if (strcmp(command, "page-down") == 0) {
+			int exit = args_has(args, 'R') || data->scroll_exit;
 			for (; np != 0; np--) {
-				if (window_copy_pagedown(wp, 0)) {
+				if (window_copy_pagedown(wp, 0, exit)) {
 					cancel = 1;
 					break;
 				}
@@ -759,7 +761,8 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
 		if (strcmp(command, "scroll-down") == 0) {
 			for (; np != 0; np--)
 				window_copy_cursor_down(wp, 1);
-			if (data->scroll_exit && data->oy == 0)
+			if ((args_has(args, 'R') || data->scroll_exit)
+			    && data->oy == 0)
 				cancel = 1;
 		}
 		if (strcmp(command, "scroll-up") == 0) {
-- 
2.15.0.rc2.357.g7e34df9404-goog

Reply via email to