Hi Thanks for your mail and diff,
On Tue, Jan 19, 2010 at 07:14:51PM -0800, Robin Lee Powell wrote: > > 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. :) I've converted your diff to a unified diff below since it is much easier to reply to inline: > Index: mode-key.c > =================================================================== > RCS file: /cvsroot/tmux/tmux/mode-key.c,v > retrieving revision 1.36 > diff -u -p -r1.36 mode-key.c > --- mode-key.c 4 Dec 2009 22:14:47 -0000 1.36 > +++ mode-key.c 20 Jan 2010 18:48:19 -0000 > @@ -100,6 +100,9 @@ struct mode_key_cmdstr mode_key_cmdstr_c > { 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" }, Not critical but can you sort these? > { 0, NULL } > }; > @@ -186,6 +189,9 @@ const struct mode_key_entry mode_key_vi_ > { '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 @@ const struct mode_key_entry mode_key_ema > { '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 -p -r1.98 screen.c > --- screen.c 5 Jan 2010 23:54:53 -0000 1.98 > +++ screen.c 20 Jan 2010 18:48:19 -0000 > @@ -228,13 +228,16 @@ screen_resize_y(struct screen *s, u_int > /* 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, int marginl, int marginr, struct > grid_cell *gc) Wrap at 80 characters if possible (so after the last , as well). > { > 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, 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? > 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 -u -p -r1.536 tmux.h > --- tmux.h 8 Jan 2010 16:31:35 -0000 1.536 > +++ tmux.h 20 Jan 2010 18:48:21 -0000 > @@ -470,6 +470,9 @@ enum mode_key_cmd { > MODEKEYCOPY_STARTSELECTION, > MODEKEYCOPY_TOPLINE, > MODEKEYCOPY_UP, > + MODEKEYCOPY_MARGIN_LEFT, > + MODEKEYCOPY_MARGIN_RIGHT, > + MODEKEYCOPY_MARGIN_TOGGLE, > }; > > /* Entry in the default mode key tables. */ > @@ -672,6 +675,9 @@ struct screen_sel { > u_int ex; > u_int ey; > > + int marginl; > + int marginr; > + > struct grid_cell cell; > }; > > @@ -1762,7 +1768,8 @@ void screen_reset_tabs(struct screen *) > 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, > + 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 -u -p -r1.94 window-copy.c > --- window-copy.c 4 Dec 2009 22:14:47 -0000 1.94 > +++ window-copy.c 20 Jan 2010 18:48:22 -0000 > @@ -67,6 +67,9 @@ void window_copy_cursor_next_word(struct > 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,9 @@ struct window_copy_mode_data { > 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,6 +131,9 @@ window_copy_init(struct window_pane *wp) > data->lastcx = 0; > data->lastsx = 0; > > + data->marginl = -1; > + data->marginr = -1; > + > data->inputtype = WINDOW_COPY_OFF; > data->inputprompt = NULL; > data->inputstr = xstrdup(""); > @@ -351,6 +360,15 @@ window_copy_key(struct window_pane *wp, > 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 +839,8 @@ window_copy_update_selection(struct wind > 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->marginl, data->marginr, &gc); > return (1); > } > > @@ -832,7 +851,7 @@ window_copy_copy_selection(struct window > struct screen *s = &data->screen; > char *buf; > size_t off; > - u_int i, xx, yy, sx, sy, ex, ey, limit; > + u_int i, xx, yy, sx, sy, ex, ey, limit, > realsx, realex, realxx, realzx; Break this into two declaration lines to fit in 80 columns. > > 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. > /* 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, > realzx, realxx); > } > - window_copy_copy_line(wp, &buf, &off, ey, 0, ex); > + window_copy_copy_line(wp, &buf, &off, ey, realzx, realex); > } > > /* Don't bother if no data. */ > @@ -1287,3 +1320,58 @@ window_copy_scroll_down(struct window_pa > 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 ) { What are you checking for here? Do you mean selflag? selx can be zero even if the selection is active. > + 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