Whoops, try this instead please:

Index: options-table.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/options-table.c,v
retrieving revision 1.30
diff -u -p -r1.30 options-table.c
--- options-table.c     27 Nov 2012 13:52:23 -0000      1.30
+++ options-table.c     24 Dec 2012 12:21:00 -0000
@@ -91,6 +91,13 @@ const struct options_table_entry server_
 
 /* Session options. */
 const struct options_table_entry session_options_table[] = {
+       { .name = "assume-paste-time",
+         .type = OPTIONS_TABLE_NUMBER,
+         .minimum = 0,
+         .maximum = INT_MAX,
+         .default_num = 1,
+       },
+
        { .name = "base-index",
          .type = OPTIONS_TABLE_NUMBER,
          .minimum = 0,
Index: server-client.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/server-client.c,v
retrieving revision 1.81
diff -u -p -r1.81 server-client.c
--- server-client.c     26 Oct 2012 14:35:42 -0000      1.81
+++ server-client.c     24 Dec 2012 12:21:01 -0000
@@ -34,6 +34,7 @@ void  server_client_check_exit(struct cli
 void   server_client_check_redraw(struct client *);
 void   server_client_set_title(struct client *);
 void   server_client_reset_state(struct client *);
+int    server_client_assume_paste(struct session *);
 
 int    server_client_msg_dispatch(struct client *);
 void   server_client_msg_command(struct client *, struct msg_command_data *);
@@ -325,6 +326,22 @@ server_client_check_mouse(struct client 
        window_pane_mouse(wp, c->session, m);
 }
 
+/* Is this fast enough to probably be a paste? */
+int
+server_client_assume_paste(struct session *s)
+{
+       struct timeval  tv;
+       u_int           t;
+
+       if ((t = options_get_number(&s->options, "assume-paste-time")) == 0)
+               return 0;
+
+       timersub(&s->activity_time, &s->last_activity_time, &tv);
+       if (tv.tv_sec == 0 && tv.tv_usec < t * 1000)
+               return 1;
+       return 0;
+}
+
 /* Handle data key input from client. */
 void
 server_client_handle_key(struct client *c, int key)
@@ -334,7 +351,7 @@ server_client_handle_key(struct client *
        struct window_pane      *wp;
        struct timeval           tv;
        struct key_binding      *bd;
-       int                      xtimeout, isprefix;
+       int                      xtimeout, isprefix, ispaste;
 
        /* Check the client is good to accept input. */
        if ((c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0)
@@ -346,6 +363,9 @@ server_client_handle_key(struct client *
        /* Update the activity timer. */
        if (gettimeofday(&c->activity_time, NULL) != 0)
                fatal("gettimeofday failed");
+
+       memcpy(&s->last_activity_time, &s->activity_time,
+           sizeof s->last_activity_time);
        memcpy(&s->activity_time, &c->activity_time, sizeof s->activity_time);
 
        w = c->session->curw->window;
@@ -382,25 +402,31 @@ server_client_handle_key(struct client *
        }
 
        /* Is this a prefix key? */
-       if (key == options_get_number(&c->session->options, "prefix"))
+       if (key == options_get_number(&s->options, "prefix"))
                isprefix = 1;
-       else if (key == options_get_number(&c->session->options, "prefix2"))
+       else if (key == options_get_number(&s->options, "prefix2"))
                isprefix = 1;
        else
                isprefix = 0;
 
+       /* Treat prefix as a regular key when pasting is detected. */
+       ispaste = server_client_assume_paste(s);
+       if (ispaste)
+               isprefix = 0;
+
        /* No previous prefix key. */
        if (!(c->flags & CLIENT_PREFIX)) {
-               if (isprefix)
+               if (isprefix) {
                        c->flags |= CLIENT_PREFIX;
-               else {
-                       /* Try as a non-prefix key binding. */
-                       if ((bd = key_bindings_lookup(key)) == NULL) {
-                               if (!(c->flags & CLIENT_READONLY))
-                                       window_pane_key(wp, c->session, key);
-                       } else
-                               key_bindings_dispatch(bd, c);
+                       return;
                }
+
+               /* Try as a non-prefix key binding. */
+               if (ispaste || (bd = key_bindings_lookup(key)) == NULL) {
+                       if (!(c->flags & CLIENT_READONLY))
+                               window_pane_key(wp, s, key);
+               } else
+                       key_bindings_dispatch(bd, c);
                return;
        }
 
@@ -413,7 +439,7 @@ server_client_handle_key(struct client *
                        if (isprefix)
                                c->flags |= CLIENT_PREFIX;
                        else if (!(c->flags & CLIENT_READONLY))
-                               window_pane_key(wp, c->session, key);
+                               window_pane_key(wp, s, key);
                }
                return;
        }
@@ -424,12 +450,12 @@ server_client_handle_key(struct client *
                if (isprefix)
                        c->flags |= CLIENT_PREFIX;
                else if (!(c->flags & CLIENT_READONLY))
-                       window_pane_key(wp, c->session, key);
+                       window_pane_key(wp, s, key);
                return;
        }
 
        /* If this key can repeat, reset the repeat flags and timer. */
-       xtimeout = options_get_number(&c->session->options, "repeat-time");
+       xtimeout = options_get_number(&s->options, "repeat-time");
        if (xtimeout != 0 && bd->can_repeat) {
                c->flags |= CLIENT_PREFIX|CLIENT_REPEAT;
 
Index: tmux.1
===================================================================
RCS file: /cvs/src/usr.bin/tmux/tmux.1,v
retrieving revision 1.308
diff -u -p -r1.308 tmux.1
--- tmux.1      27 Nov 2012 15:09:35 -0000      1.308
+++ tmux.1      24 Dec 2012 12:21:07 -0000
@@ -2031,6 +2031,13 @@ interactive menu when required.
 .Pp
 Available session options are:
 .Bl -tag -width Ds
+.It Ic assume-paste-time Ar milliseconds
+If keys are entered faster than one in
+.Ar milliseconds ,
+they are assumed to have been pasted rather than typed and
+.Nm
+key bindings are not processed.
+The default is one millisecond and zero disables.
 .It Ic base-index Ar index
 Set the base index from which an unused index should be searched when a new
 window is created.
Index: tmux.h
===================================================================
RCS file: /cvs/src/usr.bin/tmux/tmux.h,v
retrieving revision 1.368
diff -u -p -r1.368 tmux.h
--- tmux.h      27 Nov 2012 22:59:34 -0000      1.368
+++ tmux.h      24 Dec 2012 12:21:08 -0000
@@ -1095,6 +1095,7 @@ struct session {
 
        struct timeval   creation_time;
        struct timeval   activity_time;
+       struct timeval   last_activity_time;
 
        u_int            sx;
        u_int            sy;
@@ -1706,7 +1707,6 @@ int                paste_replace(struct paste_stack *
 char           *paste_print(struct paste_buffer *, size_t);
 void            paste_send_pane(struct paste_buffer *, struct window_pane *,
                     const char *, int);
-
 
 /* clock.c */
 extern const char clock_table[14][5][5];




On Sun, Dec 23, 2012 at 01:17:25AM +0100, Marcin Kulik wrote:
> Yes, patch -l solved that.
> 
> But it seems sth is wrong. Default value (1) doesn't do anything, tmux
> is still interpreting prefix key when pasting. Also, when I try to set
> assume-paste-time I can only do that with value 0. Higher values (like
> 1) give me "Value is too large: 1".
> 
> On Fri, Dec 21, 2012 at 2:01 PM, Nicholas Marriott
> <nicholas.marri...@gmail.com> wrote:
> > Does it work with patch -l?
> >
> >
> > On Fri, Dec 21, 2012 at 12:57:59PM +0100, Marcin Kulik wrote:
> >>  Hey,
> >>
> >> I was trying to apply this patch but with no luck. I'm running: patch
> >> -p0 < 0001-nick.patch but I'm getting:
> >>
> >> patching file options-table.c
> >> Hunk #1 FAILED at 91.
> >> 1 out of 1 hunk FAILED -- saving rejects to file options-table.c.rej
> >> patching file server-client.c
> >> Hunk #1 FAILED at 34.
> >> Hunk #2 succeeded at 324 with fuzz 1 (offset -1 lines).
> >> Hunk #3 FAILED at 350.
> >> Hunk #4 FAILED at 362.
> >> Hunk #5 FAILED at 398.
> >> Hunk #6 FAILED at 429.
> >> Hunk #7 FAILED at 440.
> >> 6 out of 7 hunks FAILED -- saving rejects to file server-client.c.rej
> >> patching file tmux.1
> >> Hunk #1 succeeded at 2035 (offset 4 lines).
> >> patching file tmux.h
> >> Hunk #1 FAILED at 1095.
> >> 1 out of 1 hunk FAILED -- saving rejects to file tmux.h.rej
> >>
> >> I tried to apply it on several revisions from 27th Nov, also on
> >> current master but no luck.
> >>
> >> Marcin
> >>
> >> On Tue, Nov 27, 2012 at 3:15 PM, Nicholas Marriott
> >> <nicholas.marri...@gmail.com> wrote:
> >> > Hi
> >> >
> >> > Sorry for the delay.
> >> >
> >> > This needs to handle -n key bindings too and unfortunately I think it
> >> > needs to be an option. Try this please:
> >> >
> >> > Index: options-table.c
> >> > ===================================================================
> >> > RCS file: /cvs/src/usr.bin/tmux/options-table.c,v
> >> > retrieving revision 1.30
> >> > diff -u -p -r1.30 options-table.c
> >> > --- options-table.c     27 Nov 2012 13:52:23 -0000      1.30
> >> > +++ options-table.c     27 Nov 2012 14:14:20 -0000
> >> > @@ -91,6 +91,11 @@ const struct options_table_entry server_
> >> >
> >> >  /* Session options. */
> >> >  const struct options_table_entry session_options_table[] = {
> >> > +       { .name = "assume-paste-time",
> >> > +         .type = OPTIONS_TABLE_NUMBER,
> >> > +         .default_num = 1,
> >> > +       },
> >> > +
> >> >         { .name = "base-index",
> >> >           .type = OPTIONS_TABLE_NUMBER,
> >> >           .minimum = 0,
> >> > Index: server-client.c
> >> > ===================================================================
> >> > RCS file: /cvs/src/usr.bin/tmux/server-client.c,v
> >> > retrieving revision 1.81
> >> > diff -u -p -r1.81 server-client.c
> >> > --- server-client.c     26 Oct 2012 14:35:42 -0000      1.81
> >> > +++ server-client.c     27 Nov 2012 14:14:25 -0000
> >> > @@ -34,6 +34,7 @@ void  server_client_check_exit(struct cli
> >> >  void   server_client_check_redraw(struct client *);
> >> >  void   server_client_set_title(struct client *);
> >> >  void   server_client_reset_state(struct client *);
> >> > +int    server_client_assume_paste(struct session *);
> >> >
> >> >  int    server_client_msg_dispatch(struct client *);
> >> >  void   server_client_msg_command(struct client *, struct 
> >> > msg_command_data *);
> >> > @@ -325,6 +326,22 @@ server_client_check_mouse(struct client
> >> >         window_pane_mouse(wp, c->session, m);
> >> >  }
> >> >
> >> > +/* Is this fast enough to probably be a paste? */
> >> > +int
> >> > +server_client_assume_paste(struct session *s)
> >> > +{
> >> > +       struct timeval  tv;
> >> > +       u_int           t;
> >> > +
> >> > +       if ((t = options_get_number(&s->options, "assume-paste-time")) 
> >> > == 0)
> >> > +               return 0;
> >> > +
> >> > +       timersub(&s->activity_time, &s->last_activity_time, &tv);
> >> > +       if (tv.tv_sec == 0 && tv.tv_usec < t * 1000)
> >> > +               return 1;
> >> > +       return 0;
> >> > +}
> >> > +
> >> >  /* Handle data key input from client. */
> >> >  void
> >> >  server_client_handle_key(struct client *c, int key)
> >> > @@ -334,7 +351,7 @@ server_client_handle_key(struct client *
> >> >         struct window_pane      *wp;
> >> >         struct timeval           tv;
> >> >         struct key_binding      *bd;
> >> > -       int                      xtimeout, isprefix;
> >> > +       int                      xtimeout, isprefix, ispaste;
> >> >
> >> >         /* Check the client is good to accept input. */
> >> >         if ((c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0)
> >> > @@ -346,6 +363,9 @@ server_client_handle_key(struct client *
> >> >         /* Update the activity timer. */
> >> >         if (gettimeofday(&c->activity_time, NULL) != 0)
> >> >                 fatal("gettimeofday failed");
> >> > +
> >> > +       memcpy(&s->last_activity_time, &s->activity_time,
> >> > +           sizeof s->last_activity_time);
> >> >         memcpy(&s->activity_time, &c->activity_time, sizeof 
> >> > s->activity_time);
> >> >
> >> >         w = c->session->curw->window;
> >> > @@ -382,25 +402,31 @@ server_client_handle_key(struct client *
> >> >         }
> >> >
> >> >         /* Is this a prefix key? */
> >> > -       if (key == options_get_number(&c->session->options, "prefix"))
> >> > +       if (key == options_get_number(&s->options, "prefix"))
> >> >                 isprefix = 1;
> >> > -       else if (key == options_get_number(&c->session->options, 
> >> > "prefix2"))
> >> > +       else if (key == options_get_number(&s->options, "prefix2"))
> >> >                 isprefix = 1;
> >> >         else
> >> >                 isprefix = 0;
> >> >
> >> > +       /* Treat prefix as a regular key when pasting is detected. */
> >> > +       ispaste = server_client_assume_paste(s);
> >> > +       if (ispaste)
> >> > +               isprefix = 0;
> >> > +
> >> >         /* No previous prefix key. */
> >> >         if (!(c->flags & CLIENT_PREFIX)) {
> >> > -               if (isprefix)
> >> > +               if (isprefix) {
> >> >                         c->flags |= CLIENT_PREFIX;
> >> > -               else {
> >> > -                       /* Try as a non-prefix key binding. */
> >> > -                       if ((bd = key_bindings_lookup(key)) == NULL) {
> >> > -                               if (!(c->flags & CLIENT_READONLY))
> >> > -                                       window_pane_key(wp, c->session, 
> >> > key);
> >> > -                       } else
> >> > -                               key_bindings_dispatch(bd, c);
> >> > +                       return;
> >> >                 }
> >> > +
> >> > +               /* Try as a non-prefix key binding. */
> >> > +               if (ispaste || (bd = key_bindings_lookup(key)) == NULL) {
> >> > +                       if (!(c->flags & CLIENT_READONLY))
> >> > +                               window_pane_key(wp, s, key);
> >> > +               } else
> >> > +                       key_bindings_dispatch(bd, c);
> >> >                 return;
> >> >         }
> >> >
> >> > @@ -413,7 +439,7 @@ server_client_handle_key(struct client *
> >> >                         if (isprefix)
> >> >                                 c->flags |= CLIENT_PREFIX;
> >> >                         else if (!(c->flags & CLIENT_READONLY))
> >> > -                               window_pane_key(wp, c->session, key);
> >> > +                               window_pane_key(wp, s, key);
> >> >                 }
> >> >                 return;
> >> >         }
> >> > @@ -424,12 +450,12 @@ server_client_handle_key(struct client *
> >> >                 if (isprefix)
> >> >                         c->flags |= CLIENT_PREFIX;
> >> >                 else if (!(c->flags & CLIENT_READONLY))
> >> > -                       window_pane_key(wp, c->session, key);
> >> > +                       window_pane_key(wp, s, key);
> >> >                 return;
> >> >         }
> >> >
> >> >         /* If this key can repeat, reset the repeat flags and timer. */
> >> > -       xtimeout = options_get_number(&c->session->options, 
> >> > "repeat-time");
> >> > +       xtimeout = options_get_number(&s->options, "repeat-time");
> >> >         if (xtimeout != 0 && bd->can_repeat) {
> >> >                 c->flags |= CLIENT_PREFIX|CLIENT_REPEAT;
> >> >
> >> > Index: tmux.1
> >> > ===================================================================
> >> > RCS file: /cvs/src/usr.bin/tmux/tmux.1,v
> >> > retrieving revision 1.307
> >> > diff -u -p -r1.307 tmux.1
> >> > --- tmux.1      27 Nov 2012 13:52:23 -0000      1.307
> >> > +++ tmux.1      27 Nov 2012 14:14:29 -0000
> >> > @@ -2031,6 +2031,13 @@ interactive menu when required.
> >> >  .Pp
> >> >  Available session options are:
> >> >  .Bl -tag -width Ds
> >> > +.It Ic assume-paste-time Ar milliseconds
> >> > +If keys are entered faster than one in
> >> > +.Ar milliseconds ,
> >> > +they are assumed to have been pasted rather than typed and
> >> > +.Nm
> >> > +key bindings are not processed.
> >> > +The default is one millisecond and zero disables.
> >> >  .It Ic base-index Ar index
> >> >  Set the base index from which an unused index should be searched when a 
> >> > new
> >> >  window is created.
> >> > Index: tmux.h
> >> > ===================================================================
> >> > RCS file: /cvs/src/usr.bin/tmux/tmux.h,v
> >> > retrieving revision 1.364
> >> > diff -u -p -r1.364 tmux.h
> >> > --- tmux.h      22 Nov 2012 14:41:11 -0000      1.364
> >> > +++ tmux.h      27 Nov 2012 14:14:32 -0000
> >> > @@ -1095,6 +1095,7 @@ struct session {
> >> >
> >> >         struct timeval   creation_time;
> >> >         struct timeval   activity_time;
> >> > +       struct timeval   last_activity_time;
> >> >
> >> >         u_int            sx;
> >> >         u_int            sy;
> >> >
> >> >
> >> >
> >> > On Thu, Oct 18, 2012 at 06:40:18PM +0200, Marcin Kulik wrote:
> >> >> Sure, previous version of patch attached.
> >> >> I used both versions and both worked well for me.
> >> >> As for the case of remote host (tcp delay etc) - both versions (with
> >> >> read_len and with time) can fail in this scenario, no?
> >> >>
> >> >> On Thu, Oct 18, 2012 at 4:24 PM, Nicholas Marriott
> >> >> <nicholas.marri...@gmail.com> wrote:
> >> >> > Hmmmf I like the idea but like others have pointed out this will screw
> >> >> > up when using a remote host.
> >> >> >
> >> >> > Maybe your original version with the time was better, can you show me 
> >> >> > it
> >> >> > again?
> >> >> >
> >> >> >
> >> >> > On Mon, Oct 15, 2012 at 04:16:00PM +0200, Marcin Kulik wrote:
> >> >> >> Hi guys,
> >> >> >>
> >> >> >> First, I'd like to give huge kudos to all you tmux developers,
> >> >> >> contributors and users. This is brilliant piece of software. Thanks!
> >> >> >>
> >> >> >> Second, I've been discussing small patch I created (attached) for 
> >> >> >> tmux
> >> >> >> with Thomas Adam on #tmux and we think it's good enough to go into
> >> >> >> master.
> >> >> >>
> >> >> >> What it does is basically changing the way tmux handles prefix key
> >> >> >> detection. Without the patch when you paste some text into your
> >> >> >> terminal and this text contains prefix key (byte) tmux is 
> >> >> >> interpreting
> >> >> >> the prefix like usual and invoking command connected to key binding
> >> >> >> for the character after the prefix.
> >> >> >> With this patch tmux detects if the currently handled prefix keypress
> >> >> >> belongs to longer (>1 in length) stdin read and when this is true it
> >> >> >> treats prefix key like any other, non-special key.
> >> >> >>
> >> >> >> This basically allows for comfortable use of printable character like
> >> >> >> backtick (`) as a prefix without a drawback like possibility of
> >> >> >> messing up the session/window when pasting bash/sql/other code that
> >> >> >> has backticks included.
> >> >> >>
> >> >> >> Marcin
> >> >> >
> >> >> >
> >> >> >> ------------------------------------------------------------------------------
> >> >> >> Don't let slow site performance ruin your business. Deploy New Relic 
> >> >> >> APM
> >> >> >> Deploy New Relic app performance management and know exactly
> >> >> >> what is happening inside your Ruby, Python, PHP, Java, and .NET app
> >> >> >> Try New Relic at no cost today and get our sweet Data Nerd shirt too!
> >> >> >> http://p.sf.net/sfu/newrelic-dev2dev
> >> >> >
> >> >> >> _______________________________________________
> >> >> >> tmux-users mailing list
> >> >> >> tmux-users@lists.sourceforge.net
> >> >> >> https://lists.sourceforge.net/lists/listinfo/tmux-users
> >> >> >
> >> >
> >> >

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to