On Wed, Jan 20, 2010 at 07:04:21PM +0000, Nicholas Marriott wrote:
> > +   { MODEKEYCOPY_MARGIN_LEFT, "left-margin" },
> > +   { MODEKEYCOPY_MARGIN_RIGHT, "right-margin" },
> > +   { MODEKEYCOPY_MARGIN_TOGGLE, "square-copy-toggle" },
> 
> Not critical but can you sort these?

Done.

> >  screen_set_selection(struct screen *s,
> > -    u_int sx, u_int sy, u_int ex, u_int ey, struct grid_cell *gc)
> > +    u_int sx, u_int sy, u_int ex, u_int ey, int marginl, int marginr, 
> > struct grid_cell *gc)
> 
> Wrap at 80 characters if possible (so after the last , as well).

Not sure what the paranthetical comment means, but wrapped
everywhere I could find.

BTW, to find more:

for file in *.c *.h               
do
  echo "******************** $file"
  cat $file |  sed 's/\t/        /g' | grep '^.{81}'
done

> >  {
> >     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,7 +282,12 @@ screen_check_selection(struct screen *s,
> >  {
> >     struct screen_sel       *sel = &s->sel;
> >  
> > -   if (!sel->flag || py < sel->sy || py > sel->ey)
> > +   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)
> > +            )
> 
> This is a bit unreadable. Definitely move the comment outside the if, 

The comment wasn't even supposed to be there.  -_-

> and since this is a bunch of ||s it could be split up into several
> ifs to make it clearer.
> 
> I think it might not be better with a specific rectflag or
> marginflag member or something rather than overloading -1 to mean
> "we're not a rectangle". Is marginl ever -1 and marginr not?
> 
> Then these two could be u_int as well.
> 
> What do you think?

I had been pondering that as well.  I'll do it that way; you're
right that the current method is getting too messy (and the vi-mode
fixes will only make it worse, I'm afraid; copying isn't the only
thing vi does differently).

> >  
> >     if (!s->sel.flag)
> >             return;
> > @@ -863,17 +882,31 @@ window_copy_copy_selection(struct window
> >     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;
> > +
> 
> This is pretty hard to read as well. I think it would be better as:
> 
>       if (data->marginr != -1 && data->marginl != -1) {
>               ...
>       } else {
>               ...
>       }
> 
> Also one big comment at the top covering all four variables might be nicer 
> than
> five comments.

*nod*

> > +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 ) {
> 
> What are you checking for here? Do you mean selflag? selx can be zero even if
> the selection is active.

I did, yes, but if it's zero, it has no effect here, so it's still a
valid test.  selflag is better, though.  Fixing.

New version attached.  Not quite as thoroughly tested, but seems to
be working just fine.

-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/
? .mode-key.c.swp
? .screen.c.swp
? .tmux.h.swp
? .window-copy.c.swp
Index: mode-key.c
===================================================================
RCS file: /cvsroot/tmux/tmux/mode-key.c,v
retrieving revision 1.36
diff -u -r1.36 mode-key.c
--- mode-key.c  4 Dec 2009 22:14:47 -0000       1.36
+++ mode-key.c  21 Jan 2010 07:42:17 -0000
@@ -85,6 +85,9 @@
        { MODEKEYCOPY_ENDOFLINE, "end-of-line" },
        { MODEKEYCOPY_GOTOLINE, "goto-line" },
        { MODEKEYCOPY_LEFT, "cursor-left" },
+       { MODEKEYCOPY_MARGIN_LEFT, "left-margin" },
+       { MODEKEYCOPY_MARGIN_RIGHT, "right-margin" },
+       { MODEKEYCOPY_MARGIN_TOGGLE, "square-copy-toggle" },
        { MODEKEYCOPY_MIDDLELINE, "middle-line" },
        { MODEKEYCOPY_NEXTPAGE, "page-down" },
        { MODEKEYCOPY_NEXTWORD, "next-word" },
@@ -186,6 +189,9 @@
        { '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,6 +282,9 @@
        { '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 -u -r1.98 screen.c
--- screen.c    5 Jan 2010 23:54:53 -0000       1.98
+++ screen.c    21 Jan 2010 07:42:17 -0000
@@ -228,13 +228,18 @@
 /* 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)
+    u_int sx, u_int sy, u_int ex, u_int ey, u_int block_mode,
+    u_int marginl, u_int marginr, struct grid_cell *gc)
 {
        struct screen_sel       *sel = &s->sel;
 
        memcpy(&sel->cell, gc, sizeof sel->cell);
        sel->flag = 1;
 
+       sel->block_mode = block_mode;
+       sel->marginl = marginl;
+       sel->marginr = marginr;
+
        /* starting line < ending line -- downward selection. */
        if (sy < ey) {
                sel->sx = sx; sel->sy = sy;
@@ -282,6 +287,12 @@
        if (!sel->flag || py < sel->sy || py > sel->ey)
                return (0);
 
+       if (sel->block_mode && px < sel->marginl)
+               return (0);
+
+       if (sel->block_mode && px > sel->marginr - 1)
+               return (0);
+
        if (py == sel->sy && py == sel->ey) {
                if (px < sel->sx || px > sel->ex)
                        return (0);
Index: tmux.h
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.h,v
retrieving revision 1.536
diff -u -r1.536 tmux.h
--- tmux.h      8 Jan 2010 16:31:35 -0000       1.536
+++ tmux.h      21 Jan 2010 07:42:18 -0000
@@ -455,6 +455,9 @@
        MODEKEYCOPY_HALFPAGEDOWN,
        MODEKEYCOPY_HALFPAGEUP,
        MODEKEYCOPY_LEFT,
+       MODEKEYCOPY_MARGIN_LEFT,
+       MODEKEYCOPY_MARGIN_RIGHT,
+       MODEKEYCOPY_MARGIN_TOGGLE,
        MODEKEYCOPY_MIDDLELINE,
        MODEKEYCOPY_NEXTPAGE,
        MODEKEYCOPY_NEXTWORD,
@@ -672,6 +675,10 @@
        u_int            ex;
        u_int            ey;
 
+       u_int            block_mode;
+       u_int            marginl;
+       u_int            marginr;
+
        struct grid_cell cell;
 };
 
@@ -1762,7 +1769,8 @@
 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 *);
+            struct screen *, u_int, u_int, u_int, 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);
 
Index: window-copy.c
===================================================================
RCS file: /cvsroot/tmux/tmux/window-copy.c,v
retrieving revision 1.94
diff -u -r1.94 window-copy.c
--- window-copy.c       4 Dec 2009 22:14:47 -0000       1.94
+++ window-copy.c       21 Jan 2010 07:42:19 -0000
@@ -67,6 +67,9 @@
 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,6 +97,10 @@
        u_int           selx;
        u_int           sely;
 
+       u_int           block_mode; /* are we in block mode? */
+       u_int           marginl; /* left margin for block copying */
+       u_int           marginr; /* right margin for block copying */
+
        u_int           cx;
        u_int           cy;
 
@@ -125,6 +132,10 @@
        data->lastcx = 0;
        data->lastsx = 0;
 
+       data->block_mode = 0;
+       data->marginl = 0;
+       data->marginr = 0;
+
        data->inputtype = WINDOW_COPY_OFF;
        data->inputprompt = NULL;
        data->inputstr = xstrdup("");
@@ -351,6 +362,15 @@
                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,7 +841,8 @@
        sy = screen_hsize(s) + sy;
 
        screen_set_selection(
-           s, sx, sy, data->cx, screen_hsize(s) + data->cy, &gc);
+           s, sx, sy, data->cx, screen_hsize(s) + data->cy, 
+            data->block_mode, data->marginl, data->marginr, &gc);
        return (1);
 }
 
@@ -831,8 +852,9 @@
        struct window_copy_mode_data    *data = wp->modedata;
        struct screen                   *s = &data->screen;
        char                            *buf;
-       size_t                           off;
-       u_int                            i, xx, yy, sx, sy, ex, ey, limit;
+       size_t                           off;
+       u_int                            i, xx, yy, sx, sy, ex, ey, limit;
+       u_int                            realsx, realex, realEx, realSx;
 
        if (!s->sel.flag)
                return;
@@ -863,17 +885,38 @@
        if (ex > xx)
                ex = xx;
 
+       /***
+        * Incorporate magins for block-copy if necessary; four
+        * kinds: start of first line (realsx), end of last line
+        * (realex), start (realSx) and end (realEx) of all other
+        * lines.
+        ***/
+       if( data->block_mode ) {
+               realex = data->marginr < ex ? data->marginr : ex;
+               realEx = data->marginr < xx ? data->marginr : xx;
+               realsx = data->marginl > sx ? data->marginl : sx;
+               realSx = data->marginl > 0  ? data->marginl : 0;
+       } else {
+               realex = ex;
+               realEx = xx;
+               realsx = sx;
+               realSx = 0;
+       }
+
        /* Copy the lines. */
-       if (sy == ey)
-               window_copy_copy_line(wp, &buf, &off, sy, sx, ex);
-       else {
+       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, sx, xx);
+               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, 0, xx);
+                               window_copy_copy_line(wp, &buf, &off, i,
+                                               realSx, realEx);
                }
-               window_copy_copy_line(wp, &buf, &off, ey, 0, ex);
+               window_copy_copy_line(wp, &buf, &off, ey, realSx, realex);
        }
 
        /* Don't bother if no data. */
@@ -1287,3 +1330,58 @@
        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->block_mode = 1;
+       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->block_mode = 1;
+       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;
+       struct screen                   *s = &data->screen;
+
+       if (data->block_mode) {
+               data->block_mode = 0;
+       } else {
+               data->block_mode = 1;
+               /* 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 ( s->sel.flag ) {
+                       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