I've added the documentation.

I also went ahead and added S-PageUp and S-PageDown bindings to the default
keymap, the latter of which uses page-down-and-cancel.  This mirrors the
scrollback behavior of xterm and standard linux TTYs, and should therefore
be natural for many users (provided their terminals send those keys in the
first place).  If you want, I can revert that change.

On Sat, Nov 11, 2017 at 1:33 PM, Nicholas Marriott <
[email protected]> wrote:

>
> thanks. you also need to add these to tmux.1
>
>
> On Fri, Nov 10, 2017 at 02:53:26PM -0800, Stephen Hicks wrote:
> >    Sorry for the delay.A  I've redone the patch to instead provide the
> >    -and-cancel versions of the three relevant commands
> >    (cursor-down-and-cancel doesn't seem to make sense, in my opinion, nor
> >    does it currently respect the copy-mode -e flag).
> >    On Mon, Oct 30, 2017 at 12:51 AM, Nicholas Marriott
> >    <[email protected]> wrote:
> >
> >      OK well we can just leave -e for the moment and have the new
> commands as
> >      well assuming the new diff is pretty small.
> >
> >      On Mon, Oct 30, 2017 at 03:50:15PM +1100, Cam Hutchison wrote:
> >      > Yes, I have Prefix-[ and Prefix-^[ set to copy-mode, and
> >      > MouseDrag1Pane, WheelUpPane and "-T root PPage" using copy-mode
> -e.
> >      >
> >      > On 29 October 2017 at 19:34, Nicholas Marriott
> >      > <[email protected]> wrote:
> >      > > Have you got some key bindings that do copy-mode -e and some
> that
> >      just
> >      > > do plain copy-mode?
> >      > >
> >      > >
> >      > >
> >      > > On Sun, Oct 29, 2017 at 01:17:37PM +1100, Cam Hutchison wrote:
> >      > >> Stephen,
> >      > >>
> >      > >> Sorry for the delay in responding - life got in the way...
> >      > >>
> >      > >> Stephen Hicks wrote:
> >      > >> > In my mind, those two models are not mutually exclusive.A
> When I
> >      use the
> >      > >> > mouse wheel to initiate a scrollback, I do tend to be in the
> >      second model,
> >      > >> > but on the keyboard, how I enter copy mode is more related to
> >      whether the
> >      > >> > thing I'm looking for is on the screen or not, in addition to
> >      whether I'm
> >      > >> > searching, scrolling, or copying.
> >      > >>
> >      > >> No, not mutually exclusive but when nicm said to also remove
> the -e
> >      > >> option, I didn't see how your proposed changes would allow me
> to
> >      retain
> >      > >> the mode I ues.
> >      > >>
> >      > >> > My setting looks roughly like this:
> >      > >> >
> >      > >> > bind [ copy-mode
> >      > >> > bind -n S-PgUp copy-mode -u
> >      > >> > bind -T copy-mode PgUp send-keys -X page-up
> >      > >> > bind -T copy-mode S-PgUp send-keys -X page-up
> >      > >> > bind -T copy-mode PgDn send-keys -X page-down
> >      > >> > bind -T copy-mode S-PgDn send-keys -X page-down-maybe-cancel
> >      > >>
> >      > >> I wonder if a simpler way would be to define two new copy mode
> >      commands,
> >      > >> autoexit-on and autoexit-off. It's not quite ideal as two
> commands,
> >      as
> >      > >> it smells more like an option but there are no pane options or
> copy
> >      mode
> >      > >> options.
> >      > >>
> >      > >> With these two commands, you could replace 'copy-mode -e' with
> >      > >> 'copy-mode; send-keys -X autoexit-on' and you could replace
> your
> >      > >> bindings with a similar sequence that sends autoexit-off then
> >      page-down,
> >      > >> or autoexit-on then page-down, etc.
> >      > >>
> >      > >> That is, give control of the basic components needed to
> compose the
> >      > >> higher-level behaviour.
> >      > >>
> >      > >> I'd be happy with getting rid of copy-mode -e with something
> like
> >      this
> >      > >>
> >      > >> If I seem a little defensive of copy-mode -e its because I
> added it
> >      :-)
> >      > >>
> >      > >> Cheers,
> >      > >> Cam
> >      > >>
> >      > >> > On Wed, Oct 25, 2017 at 7:37 PM, Cam Hutchison <[email protected]>
> >      wrote:
> >      > >> >
> >      > >> > > On 26 October 2017 at 05:39, Stephen Hicks
> >      <[email protected]> wrote:
> >      > >> > > > 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.A  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'm not sure I understand your use case or your issue with
> the
> >      current
> >      > >> > > behaviour. Is it just the "spooky action at a distance"
> that
> >      you object to?
> >      > >> > >
> >      > >> > > The current behaviour is intended to model two different
> ways
> >      that copy
> >      > >> > > mode can be used:
> >      > >> > >
> >      > >> > > 1) The normal mode where you are copying data out of the
> >      scrollback
> >      > >> > > buffer, searching through it, or some other explicit
> action.
> >      This mode
> >      > >> > > requires you to take an equally explicit action to exit.
> >      > >> > >
> >      > >> > > 2) Scrollback mode, where you are just scrolling back
> through
> >      the
> >      > >> > > terminal history. In this mode, you enter typically with
> just a
> >      PageUp
> >      > >> > > or ScrollUp event, not a binding that is explicitly
> copy-mode.
> >      This
> >      > >> > > way, exiting mirrors your entry - when you scroll back to
> where
> >      you
> >      > >> > > started, you're no longer in copy mode.
> >      > >> > >
> >      > >> > > I don't understand the "spooky action at a distance" (I get
> >      that how you
> >      > >> > > enter the mode defines how you can exit the mode, but
> that's
> >      all related
> >      > >> > > and not spooky unrelated stuff, or at a distance).
> >      > >> > >
> >      > >> > > I can't see how your approach allows the distinction
> between
> >      these two
> >      > >> > > use cases to be retained. Perhaps using separate key
> tables,
> >      but that
> >      > >> > > feels like a lot of extra configuration.
> >      > >> > >
> >      > >> > > Can you explain why you want to change this?
> >      > >> > >
> >      > >> > > >
> >      > >> > > > I've put together a small patch to allow opting into the
> >      auto-exit
> >      > >> > > behavior
> >      > >> > > > on scroll-down commands instead.A  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 email to
> >      [email protected].
> >      > >> > > > For more options, visit https://groups.google.com/d/
> optout.
> >      > >> > >
> >      > >>
> >      > >> --
> >      > >> 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.
> >      > >
> >      > > --
> >      > > 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.
>
>
>

-- 
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 5beb7e2bd19f12103ef876b5f1cc7884c6a3d96f 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.

Adds page-down-and-cancel, scroll-down-and-cancel, and half-page-down-and-cancel, and sets S-PageUp and S-PageDown to mimic xterm's behavior in the default keymap, with S-PageDown in copy-mode binding to the -and-cancel variant.
---
 key-bindings.c |  3 +++
 tmux.1         | 11 +++++++++--
 window-copy.c  | 36 ++++++++++++++++++++++++++++++------
 3 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/key-bindings.c b/key-bindings.c
index 76778009..eda9e79b 100644
--- a/key-bindings.c
+++ b/key-bindings.c
@@ -210,6 +210,7 @@ key_bindings_init(void)
 		"bind } swap-pane -D",
 		"bind '~' show-messages",
 		"bind PPage copy-mode -u",
+		"bind -n S-PPage copy-mode -u",
 		"bind -r Up select-pane -U",
 		"bind -r Down select-pane -D",
 		"bind -r Left select-pane -L",
@@ -276,6 +277,7 @@ key_bindings_init(void)
 		"bind -Tcopy-mode DoubleClick1Pane select-pane\\; send -X select-word",
 		"bind -Tcopy-mode TripleClick1Pane select-pane\\; send -X select-line",
 		"bind -Tcopy-mode NPage send -X page-down",
+		"bind -Tcopy-mode S-NPage send -X page-down-and-cancel",
 		"bind -Tcopy-mode PPage send -X page-up",
 		"bind -Tcopy-mode Up send -X cursor-up",
 		"bind -Tcopy-mode Down send -X cursor-down",
@@ -375,6 +377,7 @@ key_bindings_init(void)
 		"bind -Tcopy-mode-vi DoubleClick1Pane select-pane\\; send -X select-word",
 		"bind -Tcopy-mode-vi TripleClick1Pane select-pane\\; send -X select-line",
 		"bind -Tcopy-mode-vi BSpace send -X cursor-left",
+		"bind -Tcopy-mode-vi S-NPage send -X page-down-and-cancel",
 		"bind -Tcopy-mode-vi NPage send -X page-down",
 		"bind -Tcopy-mode-vi PPage send -X page-up",
 		"bind -Tcopy-mode-vi Up send -X cursor-up",
diff --git a/tmux.1 b/tmux.1
index 3061790d..bf38afbf 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1126,9 +1126,10 @@ The following commands are supported in copy mode:
 .It Li "end-of-line" Ta "$" Ta "C-e"
 .It Li "goto-line <line>" Ta ":" Ta "g"
 .It Li "halfpage-down" Ta "C-d" Ta "M-Down"
+.It Li "halfpage-down-and-cancel" Ta "" Ta ""
 .It Li "halfpage-up" Ta "C-u" Ta "M-Up"
-.It Li "history-bottom" Ta "G" Ta "M-<"
-.It Li "history-top" Ta "g" Ta "M->"
+.It Li "history-bottom" Ta "G" Ta "M->"
+.It Li "history-top" Ta "g" Ta "M-<"
 .It Li "jump-again" Ta ";" Ta ";"
 .It Li "jump-backward <to>" Ta "F" Ta "F"
 .It Li "jump-forward <to>" Ta "f" Ta "f"
@@ -1143,12 +1144,14 @@ The following commands are supported in copy mode:
 .It Li "next-word-end" Ta "e" Ta "M-f"
 .It Li "other-end" Ta "o" Ta ""
 .It Li "page-down" Ta "C-f" Ta "PageDown"
+.It Li "page-down-and-cancel" Ta "S-PageDown" Ta "S-PageDown"
 .It Li "page-up" Ta "C-b" Ta "PageUp"
 .It Li "previous-paragraph" Ta "{" Ta "M-{"
 .It Li "previous-space" Ta "B" Ta ""
 .It Li "previous-word" Ta "b" Ta "M-b"
 .It Li "rectangle-toggle" Ta "v" Ta "R"
 .It Li "scroll-down" Ta "C-e" Ta "C-Down"
+.It Li "scroll-down-and-cancel" Ta "" Ta ""
 .It Li "scroll-up" Ta "C-y" Ta "C-Up"
 .It Li "search-again" Ta "n" Ta "n"
 .It Li "search-backward <for>" Ta "?" Ta ""
@@ -1188,6 +1191,10 @@ A
 .Ql \&;
 will then jump to the next occurrence.
 .Pp
+Several scrolling commands have -and-cancel variants, which will automatically
+cancel out of copy mode if the window is scrolled down to the bottom of the
+history buffer.
+.Pp
 Commands in copy mode may be prefaced by an optional repeat count.
 With vi key bindings, a prefix is entered using the number keys; with
 emacs, the Alt (meta) key and a number begins prefix entry.
diff --git a/window-copy.c b/window-copy.c
index 09ccc26c..31f4b7b9 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);
@@ -631,7 +631,16 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
 			window_copy_cursor_end_of_line(wp);
 		if (strcmp(command, "halfpage-down") == 0) {
 			for (; np != 0; np--) {
-				if (window_copy_pagedown(wp, 1)) {
+				if (window_copy_pagedown(wp, 1,
+				    data->scroll_exit)) {
+					cancel = 1;
+					break;
+				}
+			}
+		}
+		if (strcmp(command, "halfpage-down-and-cancel") == 0) {
+			for (; np != 0; np--) {
+				if (window_copy_pagedown(wp, 1, 1)) {
 					cancel = 1;
 					break;
 				}
@@ -729,7 +738,16 @@ window_copy_command(struct window_pane *wp, struct client *c, struct session *s,
 		}
 		if (strcmp(command, "page-down") == 0) {
 			for (; np != 0; np--) {
-				if (window_copy_pagedown(wp, 0)) {
+				if (window_copy_pagedown(wp, 0,
+				    data->scroll_exit)) {
+					cancel = 1;
+					break;
+				}
+			}
+		}
+		if (strcmp(command, "page-down-and-cancel") == 0) {
+			for (; np != 0; np--) {
+				if (window_copy_pagedown(wp, 0, 1)) {
 					cancel = 1;
 					break;
 				}
@@ -759,7 +777,13 @@ 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 ((data->scroll_exit) && data->oy == 0)
+				cancel = 1;
+		}
+		if (strcmp(command, "scroll-down-and-cancel") == 0) {
+			for (; np != 0; np--)
+				window_copy_cursor_down(wp, 1);
+			if (data->oy == 0)
 				cancel = 1;
 		}
 		if (strcmp(command, "scroll-up") == 0) {
-- 
2.15.0.448.gf294e3d99a-goog

Reply via email to