Find attached; this is basically the c and C keys from GNU Screen's
copy mode, plus a block mode toggle.  Now, the J key.  :)

-Robin

-- 
They say:  "The first AIs will be built by the military as weapons."
And I'm  thinking:  "Does it even occur to you to try for something
other  than  the default  outcome?"  See http://shrunklink.com/cdiz
http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/
Index: mode-key.c
===================================================================
RCS file: /cvsroot/tmux/tmux/mode-key.c,v
retrieving revision 1.36
diff -C3 -r1.36 mode-key.c
*** mode-key.c  4 Dec 2009 22:14:47 -0000       1.36
--- mode-key.c  20 Jan 2010 03:13:23 -0000
***************
*** 100,105 ****
--- 100,108 ----
        { MODEKEYCOPY_STARTSELECTION, "begin-selection" },
        { MODEKEYCOPY_TOPLINE, "top-line" },
        { MODEKEYCOPY_UP, "cursor-up" },
+       { MODEKEYCOPY_MARGIN_LEFT, "left-margin" },
+       { MODEKEYCOPY_MARGIN_RIGHT, "right-margin" },
+       { MODEKEYCOPY_MARGIN_TOGGLE, "square-copy-toggle" },
  
        { 0, NULL }
  };
***************
*** 186,191 ****
--- 189,197 ----
        { 'n',                  0, MODEKEYCOPY_SEARCHAGAIN },
        { 'q',                  0, MODEKEYCOPY_CANCEL },
        { 'w',                  0, MODEKEYCOPY_NEXTWORD },
+       { 'c',                  0, MODEKEYCOPY_MARGIN_LEFT },
+       { 'C',                  0, MODEKEYCOPY_MARGIN_RIGHT },
+       { 'v',                  0, MODEKEYCOPY_MARGIN_TOGGLE },
        { KEYC_BSPACE,          0, MODEKEYCOPY_LEFT },
        { KEYC_DOWN | KEYC_CTRL,0, MODEKEYCOPY_SCROLLDOWN },
        { KEYC_DOWN,            0, MODEKEYCOPY_DOWN },
***************
*** 276,281 ****
--- 282,290 ----
        { 'R' | KEYC_ESCAPE,    0, MODEKEYCOPY_TOPLINE },
        { 'v' | KEYC_ESCAPE,    0, MODEKEYCOPY_PREVIOUSPAGE },
        { 'w' | KEYC_ESCAPE,    0, MODEKEYCOPY_COPYSELECTION },
+       { 'c' | KEYC_ESCAPE,    0, MODEKEYCOPY_MARGIN_LEFT },
+       { 'C' | KEYC_ESCAPE,    0, MODEKEYCOPY_MARGIN_RIGHT },
+       { 'V' | KEYC_ESCAPE,    0, MODEKEYCOPY_MARGIN_TOGGLE },
        { KEYC_DOWN | KEYC_CTRL,0, MODEKEYCOPY_SCROLLDOWN },
        { KEYC_DOWN | KEYC_ESCAPE, 0, MODEKEYCOPY_HALFPAGEDOWN },
        { KEYC_DOWN,            0, MODEKEYCOPY_DOWN },
Index: screen.c
===================================================================
RCS file: /cvsroot/tmux/tmux/screen.c,v
retrieving revision 1.98
diff -C3 -r1.98 screen.c
*** screen.c    5 Jan 2010 23:54:53 -0000       1.98
--- screen.c    20 Jan 2010 03:13:23 -0000
***************
*** 228,240 ****
  /* Set selection. */
  void
  screen_set_selection(struct screen *s,
!     u_int sx, u_int sy, u_int ex, u_int ey, struct grid_cell *gc)
  {
        struct screen_sel       *sel = &s->sel;
  
        memcpy(&sel->cell, gc, sizeof sel->cell);
        sel->flag = 1;
  
        /* starting line < ending line -- downward selection. */
        if (sy < ey) {
                sel->sx = sx; sel->sy = sy;
--- 228,243 ----
  /* Set selection. */
  void
  screen_set_selection(struct screen *s,
!     u_int sx, u_int sy, u_int ex, u_int ey, int marginl, int marginr, struct 
grid_cell *gc)
  {
        struct screen_sel       *sel = &s->sel;
  
        memcpy(&sel->cell, gc, sizeof sel->cell);
        sel->flag = 1;
  
+         sel->marginl = marginl;
+         sel->marginr = marginr;
+ 
        /* starting line < ending line -- downward selection. */
        if (sy < ey) {
                sel->sx = sx; sel->sy = sy;
***************
*** 279,285 ****
  {
        struct screen_sel       *sel = &s->sel;
  
!       if (!sel->flag || py < sel->sy || py > sel->ey)
                return (0);
  
        if (py == sel->sy && py == sel->ey) {
--- 282,293 ----
  {
        struct screen_sel       *sel = &s->sel;
  
!       if (!sel->flag || py < sel->sy || py > sel->ey || 
!             (sel->marginl > -1 && px < (u_int) sel->marginl) || 
!             /* FIXME: >= below for vi-mode-include-cursor , and no
!              * -1? Test. */
!             (sel->marginr > -1 && px > (u_int) sel->marginr - 1)
!             )
                return (0);
  
        if (py == sel->sy && py == sel->ey) {
Index: tmux.h
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.h,v
retrieving revision 1.536
diff -C3 -r1.536 tmux.h
*** tmux.h      8 Jan 2010 16:31:35 -0000       1.536
--- tmux.h      20 Jan 2010 03:13:24 -0000
***************
*** 470,475 ****
--- 470,478 ----
        MODEKEYCOPY_STARTSELECTION,
        MODEKEYCOPY_TOPLINE,
        MODEKEYCOPY_UP,
+       MODEKEYCOPY_MARGIN_LEFT,
+       MODEKEYCOPY_MARGIN_RIGHT,
+       MODEKEYCOPY_MARGIN_TOGGLE,
  };
  
  /* Entry in the default mode key tables. */
***************
*** 672,677 ****
--- 675,683 ----
        u_int            ex;
        u_int            ey;
  
+       int              marginl;
+       int              marginr;
+ 
        struct grid_cell cell;
  };
  
***************
*** 1762,1768 ****
  void   screen_set_title(struct screen *, const char *);
  void   screen_resize(struct screen *, u_int, u_int);
  void   screen_set_selection(
!            struct screen *, u_int, u_int, u_int, u_int, struct grid_cell *);
  void   screen_clear_selection(struct screen *);
  int    screen_check_selection(struct screen *, u_int, u_int);
  
--- 1768,1775 ----
  void   screen_set_title(struct screen *, const char *);
  void   screen_resize(struct screen *, u_int, u_int);
  void   screen_set_selection(
!            struct screen *, u_int, u_int, u_int, u_int, 
!              int, int, struct grid_cell *);
  void   screen_clear_selection(struct screen *);
  int    screen_check_selection(struct screen *, u_int, u_int);
  
Index: window-copy.c
===================================================================
RCS file: /cvsroot/tmux/tmux/window-copy.c,v
retrieving revision 1.94
diff -C3 -r1.94 window-copy.c
*** window-copy.c       4 Dec 2009 22:14:47 -0000       1.94
--- window-copy.c       20 Jan 2010 03:13:25 -0000
***************
*** 67,72 ****
--- 67,75 ----
  void  window_copy_cursor_previous_word(struct window_pane *);
  void  window_copy_scroll_up(struct window_pane *, u_int);
  void  window_copy_scroll_down(struct window_pane *, u_int);
+ void  window_copy_margin_left(struct window_pane *);
+ void  window_copy_margin_right(struct window_pane *);
+ void  window_copy_margin_toggle(struct window_pane *);
  
  const struct window_mode window_copy_mode = {
        window_copy_init,
***************
*** 94,99 ****
--- 97,105 ----
        u_int           selx;
        u_int           sely;
  
+       int             marginl; /* left margin for block copying */
+       int             marginr; /* right margin for block copying */
+ 
        u_int           cx;
        u_int           cy;
  
***************
*** 125,130 ****
--- 131,139 ----
        data->lastcx = 0;
        data->lastsx = 0;
  
+       data->marginl = -1;
+       data->marginr = -1;
+ 
        data->inputtype = WINDOW_COPY_OFF;
        data->inputprompt = NULL;
        data->inputstr = xstrdup("");
***************
*** 351,356 ****
--- 360,374 ----
                data->inputprompt = "Goto Line";
                *data->inputstr = '\0';
                goto input_on;
+       case MODEKEYCOPY_MARGIN_LEFT:
+               window_copy_margin_left(wp);
+               return;
+       case MODEKEYCOPY_MARGIN_RIGHT:
+               window_copy_margin_right(wp);
+               return;
+       case MODEKEYCOPY_MARGIN_TOGGLE:
+               window_copy_margin_toggle(wp);
+               return;
        default:
                break;
        }
***************
*** 821,827 ****
        sy = screen_hsize(s) + sy;
  
        screen_set_selection(
!           s, sx, sy, data->cx, screen_hsize(s) + data->cy, &gc);
        return (1);
  }
  
--- 839,846 ----
        sy = screen_hsize(s) + sy;
  
        screen_set_selection(
!           s, sx, sy, data->cx, screen_hsize(s) + data->cy, 
!             data->marginl, data->marginr, &gc);
        return (1);
  }
  
***************
*** 832,838 ****
        struct screen                   *s = &data->screen;
        char                            *buf;
        size_t                           off;
!       u_int                            i, xx, yy, sx, sy, ex, ey, limit;
  
        if (!s->sel.flag)
                return;
--- 851,857 ----
        struct screen                   *s = &data->screen;
        char                            *buf;
        size_t                           off;
!       u_int                            i, xx, yy, sx, sy, ex, ey, limit, 
realsx, realex, realxx, realzx;
  
        if (!s->sel.flag)
                return;
***************
*** 863,879 ****
        if (ex > xx)
                ex = xx;
  
        /* Copy the lines. */
!       if (sy == ey)
!               window_copy_copy_line(wp, &buf, &off, sy, sx, ex);
!       else {
                xx = screen_size_x(s);
!               window_copy_copy_line(wp, &buf, &off, sy, sx, xx);
                if (ey - sy > 1) {
                        for (i = sy + 1; i < ey; i++)
!                               window_copy_copy_line(wp, &buf, &off, i, 0, xx);
                }
!               window_copy_copy_line(wp, &buf, &off, ey, 0, ex);
        }
  
        /* Don't bother if no data. */
--- 882,912 ----
        if (ex > xx)
                ex = xx;
  
+       /***
+        * Incorporate magins for block-copy if necessary
+        ***/
+       /* End of single/last line */
+       realex = data->marginr > -1 && data->marginr < (int)ex ? 
(u_int)data->marginr : ex;
+       /* Absolute line end */
+       realxx = data->marginr > -1 && data->marginr < (int)xx ? 
(u_int)data->marginr : xx;
+       /* Start of single/first line */
+       realsx = data->marginl > -1 && data->marginl > (int)sx ? 
(u_int)data->marginl : sx;
+       /* Absolute line start */
+       realzx = data->marginl > -1 && data->marginl > 0 ? (u_int)data->marginl 
: 0;
+ 
        /* Copy the lines. */
!       if (sy == ey) {
!               /* Incorporate magins for block-copy if necessary */
!               window_copy_copy_line(wp, &buf, &off, sy, realsx, realex);
!       } else {
                xx = screen_size_x(s);
!               window_copy_copy_line(wp, &buf, &off, sy, realsx, realex);
! 
                if (ey - sy > 1) {
                        for (i = sy + 1; i < ey; i++)
!                               window_copy_copy_line(wp, &buf, &off, i, 
realzx, realxx);
                }
!               window_copy_copy_line(wp, &buf, &off, ey, realzx, realex);
        }
  
        /* Don't bother if no data. */
***************
*** 1287,1289 ****
--- 1320,1377 ----
        screen_write_cursormove(&ctx, data->cx, data->cy);
        screen_write_stop(&ctx);
  }
+ 
+ void
+ window_copy_margin_left(struct window_pane *wp)
+ {
+       struct window_copy_mode_data    *data = wp->modedata;
+ 
+       data->marginl = data->cx;
+ 
+       window_copy_update_selection(wp);
+         window_copy_redraw_screen(wp);
+ }
+ 
+ void
+ window_copy_margin_right(struct window_pane *wp)
+ {
+       struct window_copy_mode_data    *data = wp->modedata;
+ 
+       data->marginr = data->cx;
+ 
+       window_copy_update_selection(wp);
+         window_copy_redraw_screen(wp);
+ }
+ 
+ void
+ window_copy_margin_toggle(struct window_pane *wp)
+ {
+       struct window_copy_mode_data    *data = wp->modedata;
+ 
+       /* We're in block-copy mode when either margin is not -1.
+        * In that case, we set them to -1.
+        */
+       if (data->marginr != -1 || data->marginl != -1) {
+               data->marginr = -1;
+               data->marginl = -1;
+       } else {
+               /* We're switching from non-block-copy to
+                * block-copy; set the margins to the x values of
+                * the start and end positions.  If we haven't
+                * started yet, do nothing.
+                */
+               if ( data->selx ) {
+                       if( data->cx < data->selx ) {
+                               data->marginl = data->cx;
+                               data->marginr = data->selx;
+                       } else {
+                               data->marginl = data->selx;
+                               data->marginr = data->cx;
+                       }
+               }
+       }
+ 
+       window_copy_update_selection(wp);
+         window_copy_redraw_screen(wp);
+ }
+ 
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to