=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/window-copy.c,v retrieving revision 1.322 retrieving revision 1.323 diff -c -r1.322 -r1.323 *** src/usr.bin/tmux/window-copy.c 2021/04/05 08:43:48 1.322 --- src/usr.bin/tmux/window-copy.c 2021/06/10 07:56:47 1.323 *************** *** 1,4 **** ! /* $OpenBSD: window-copy.c,v 1.322 2021/04/05 08:43:48 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: window-copy.c,v 1.323 2021/06/10 07:56:47 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 128,134 **** static void window_copy_cursor_next_word_end(struct window_mode_entry *, const char *, int); static void window_copy_cursor_previous_word_pos(struct window_mode_entry *, ! const char *, int, u_int *, u_int *); static void window_copy_cursor_previous_word(struct window_mode_entry *, const char *, int); static void window_copy_scroll_up(struct window_mode_entry *, u_int); --- 128,134 ---- static void window_copy_cursor_next_word_end(struct window_mode_entry *, const char *, int); static void window_copy_cursor_previous_word_pos(struct window_mode_entry *, ! const char *, u_int *, u_int *); static void window_copy_cursor_previous_word(struct window_mode_entry *, const char *, int); static void window_copy_scroll_up(struct window_mode_entry *, u_int); *************** *** 255,261 **** SEL_LINE, /* select one line at a time */ } selflag; ! const char *ws; /* word separators */ u_int dx; /* drag start position */ u_int dy; --- 255,261 ---- SEL_LINE, /* select one line at a time */ } selflag; ! const char *separators; /* word separators */ u_int dx; /* drag start position */ u_int dy; *************** *** 1321,1327 **** tried = 1; goto retry; } ! window_copy_cursor_previous_word(wme, "}]) ", 1); } continue; } --- 1321,1327 ---- tried = 1; goto retry; } ! window_copy_cursor_previous_word(wme, close, 1); } continue; } *************** *** 1433,1440 **** tried = 1; goto retry; } ! window_copy_cursor_next_word_end(wme, "{[( ", ! 0); continue; } /* For vi, continue searching for bracket until EOL. */ --- 1433,1439 ---- tried = 1; goto retry; } ! window_copy_cursor_next_word_end(wme, open, 0); continue; } /* For vi, continue searching for bracket until EOL. */ *************** *** 1506,1512 **** u_int np = wme->prefix; for (; np != 0; np--) ! window_copy_cursor_next_word(wme, " "); return (WINDOW_COPY_CMD_NOTHING); } --- 1505,1511 ---- u_int np = wme->prefix; for (; np != 0; np--) ! window_copy_cursor_next_word(wme, ""); return (WINDOW_COPY_CMD_NOTHING); } *************** *** 1517,1523 **** u_int np = wme->prefix; for (; np != 0; np--) ! window_copy_cursor_next_word_end(wme, " ", 0); return (WINDOW_COPY_CMD_NOTHING); } --- 1516,1522 ---- u_int np = wme->prefix; for (; np != 0; np--) ! window_copy_cursor_next_word_end(wme, "", 0); return (WINDOW_COPY_CMD_NOTHING); } *************** *** 1525,1537 **** window_copy_cmd_next_word(struct window_copy_cmd_state *cs) { struct window_mode_entry *wme = cs->wme; - struct session *s = cs->s; u_int np = wme->prefix; ! const char *ws; ! ws = options_get_string(s->options, "word-separators"); for (; np != 0; np--) ! window_copy_cursor_next_word(wme, ws); return (WINDOW_COPY_CMD_NOTHING); } --- 1524,1536 ---- window_copy_cmd_next_word(struct window_copy_cmd_state *cs) { struct window_mode_entry *wme = cs->wme; u_int np = wme->prefix; ! const char *separators; ! separators = options_get_string(cs->s->options, "word-separators"); ! for (; np != 0; np--) ! window_copy_cursor_next_word(wme, separators); return (WINDOW_COPY_CMD_NOTHING); } *************** *** 1539,1551 **** window_copy_cmd_next_word_end(struct window_copy_cmd_state *cs) { struct window_mode_entry *wme = cs->wme; - struct session *s = cs->s; u_int np = wme->prefix; ! const char *ws; ! ws = options_get_string(s->options, "word-separators"); for (; np != 0; np--) ! window_copy_cursor_next_word_end(wme, ws, 0); return (WINDOW_COPY_CMD_NOTHING); } --- 1538,1550 ---- window_copy_cmd_next_word_end(struct window_copy_cmd_state *cs) { struct window_mode_entry *wme = cs->wme; u_int np = wme->prefix; ! const char *separators; ! separators = options_get_string(cs->s->options, "word-separators"); ! for (; np != 0; np--) ! window_copy_cursor_next_word_end(wme, separators, 0); return (WINDOW_COPY_CMD_NOTHING); } *************** *** 1618,1624 **** u_int np = wme->prefix; for (; np != 0; np--) ! window_copy_cursor_previous_word(wme, " ", 1); return (WINDOW_COPY_CMD_NOTHING); } --- 1617,1623 ---- u_int np = wme->prefix; for (; np != 0; np--) ! window_copy_cursor_previous_word(wme, "", 1); return (WINDOW_COPY_CMD_NOTHING); } *************** *** 1626,1638 **** window_copy_cmd_previous_word(struct window_copy_cmd_state *cs) { struct window_mode_entry *wme = cs->wme; - struct session *s = cs->s; u_int np = wme->prefix; ! const char *ws; ! ws = options_get_string(s->options, "word-separators"); for (; np != 0; np--) ! window_copy_cursor_previous_word(wme, ws, 1); return (WINDOW_COPY_CMD_NOTHING); } --- 1625,1637 ---- window_copy_cmd_previous_word(struct window_copy_cmd_state *cs) { struct window_mode_entry *wme = cs->wme; u_int np = wme->prefix; ! const char *separators; ! separators = options_get_string(cs->s->options, "word-separators"); ! for (; np != 0; np--) ! window_copy_cursor_previous_word(wme, separators, 1); return (WINDOW_COPY_CMD_NOTHING); } *************** *** 1778,1795 **** window_copy_cmd_select_word(struct window_copy_cmd_state *cs) { struct window_mode_entry *wme = cs->wme; ! struct session *s = cs->s; struct window_copy_mode_data *data = wme->data; u_int px, py, nextx, nexty; data->lineflag = LINE_SEL_LEFT_RIGHT; data->rectflag = 0; data->selflag = SEL_WORD; data->dx = data->cx; data->dy = screen_hsize(data->backing) + data->cy - data->oy; ! data->ws = options_get_string(s->options, "word-separators"); ! window_copy_cursor_previous_word(wme, data->ws, 0); px = data->cx; py = screen_hsize(data->backing) + data->cy - data->oy; data->selrx = px; --- 1777,1796 ---- window_copy_cmd_select_word(struct window_copy_cmd_state *cs) { struct window_mode_entry *wme = cs->wme; ! struct options *session_options = cs->s->options; struct window_copy_mode_data *data = wme->data; u_int px, py, nextx, nexty; + data->lineflag = LINE_SEL_LEFT_RIGHT; data->rectflag = 0; data->selflag = SEL_WORD; data->dx = data->cx; data->dy = screen_hsize(data->backing) + data->cy - data->oy; ! data->separators = options_get_string(session_options, ! "word-separators"); ! window_copy_cursor_previous_word(wme, data->separators, 0); px = data->cx; py = screen_hsize(data->backing) + data->cy - data->oy; data->selrx = px; *************** *** 1805,1812 **** nexty++; } if (px >= window_copy_find_length(wme, py) || ! !window_copy_in_set(wme, nextx, nexty, data->ws)) ! window_copy_cursor_next_word_end(wme, data->ws, 1); else { window_copy_update_cursor(wme, px, data->cy); if (window_copy_update_selection(wme, 1, 1)) --- 1806,1813 ---- nexty++; } if (px >= window_copy_find_length(wme, py) || ! !window_copy_in_set(wme, nextx, nexty, WHITESPACE)) ! window_copy_cursor_next_word_end(wme, data->separators, 1); else { window_copy_update_cursor(wme, px, data->cy); if (window_copy_update_selection(wme, 1, 1)) *************** *** 3730,3737 **** begin = 0; if (data->dy > yy || (data->dy == yy && data->dx > xx)) { /* Right to left selection. */ ! window_copy_cursor_previous_word_pos(wme, data->ws, 0, ! &xx, &yy); begin = 1; /* Reset the end. */ --- 3731,3738 ---- begin = 0; if (data->dy > yy || (data->dy == yy && data->dx > xx)) { /* Right to left selection. */ ! window_copy_cursor_previous_word_pos(wme, ! data->separators, &xx, &yy); begin = 1; /* Reset the end. */ *************** *** 3740,3748 **** } else { /* Left to right selection. */ if (xx >= window_copy_find_length(wme, yy) || ! !window_copy_in_set(wme, xx + 1, yy, data->ws)) window_copy_cursor_next_word_end_pos(wme, ! data->ws, &xx, &yy); /* Reset the start. */ data->selx = data->selrx; --- 3741,3750 ---- } else { /* Left to right selection. */ if (xx >= window_copy_find_length(wme, yy) || ! !window_copy_in_set(wme, xx + 1, yy, WHITESPACE)) { window_copy_cursor_next_word_end_pos(wme, ! data->separators, &xx, &yy); ! } /* Reset the start. */ data->selx = data->selrx; *************** *** 4666,4684 **** struct screen *back_s = data->backing; struct grid_reader gr; u_int px, py, hsize; - int keys; px = data->cx; hsize = screen_hsize(back_s); py = hsize + data->cy - data->oy; grid_reader_start(&gr, back_s->grid, px, py); ! keys = options_get_number(oo, "mode-keys"); ! if (keys == MODEKEY_VI && !grid_reader_in_set(&gr, separators)) ! grid_reader_cursor_right(&gr, 0, 0); ! grid_reader_cursor_next_word_end(&gr, separators); ! if (keys == MODEKEY_VI) grid_reader_cursor_left(&gr, 1); grid_reader_get_cursor(&gr, &px, &py); *ppx = px; *ppy = py; --- 4668,4686 ---- struct screen *back_s = data->backing; struct grid_reader gr; u_int px, py, hsize; px = data->cx; hsize = screen_hsize(back_s); py = hsize + data->cy - data->oy; grid_reader_start(&gr, back_s->grid, px, py); ! if (options_get_number(oo, "mode-keys") == MODEKEY_VI) { ! if (!grid_reader_in_set(&gr, WHITESPACE)) ! grid_reader_cursor_right(&gr, 0, 0); ! grid_reader_cursor_next_word_end(&gr, separators); grid_reader_cursor_left(&gr, 1); + } else + grid_reader_cursor_next_word_end(&gr, separators); grid_reader_get_cursor(&gr, &px, &py); *ppx = px; *ppy = py; *************** *** 4695,4701 **** struct screen *back_s = data->backing; struct grid_reader gr; u_int px, py, oldy, hsize; - int keys; px = data->cx; hsize = screen_hsize(back_s); --- 4697,4702 ---- *************** *** 4703,4714 **** oldy = data->cy; grid_reader_start(&gr, back_s->grid, px, py); ! keys = options_get_number(oo, "mode-keys"); ! if (keys == MODEKEY_VI && !grid_reader_in_set(&gr, separators)) ! grid_reader_cursor_right(&gr, 0, 0); ! grid_reader_cursor_next_word_end(&gr, separators); ! if (keys == MODEKEY_VI) grid_reader_cursor_left(&gr, 1); grid_reader_get_cursor(&gr, &px, &py); window_copy_acquire_cursor_down(wme, hsize, screen_size_y(back_s), data->oy, oldy, px, py, no_reset); --- 4704,4716 ---- oldy = data->cy; grid_reader_start(&gr, back_s->grid, px, py); ! if (options_get_number(oo, "mode-keys") == MODEKEY_VI) { ! if (!grid_reader_in_set(&gr, WHITESPACE)) ! grid_reader_cursor_right(&gr, 0, 0); ! grid_reader_cursor_next_word_end(&gr, separators); grid_reader_cursor_left(&gr, 1); + } else + grid_reader_cursor_next_word_end(&gr, separators); grid_reader_get_cursor(&gr, &px, &py); window_copy_acquire_cursor_down(wme, hsize, screen_size_y(back_s), data->oy, oldy, px, py, no_reset); *************** *** 4717,4723 **** /* Compute the previous place where a word begins. */ static void window_copy_cursor_previous_word_pos(struct window_mode_entry *wme, ! const char *separators, int already, u_int *ppx, u_int *ppy) { struct window_copy_mode_data *data = wme->data; struct screen *back_s = data->backing; --- 4719,4725 ---- /* Compute the previous place where a word begins. */ static void window_copy_cursor_previous_word_pos(struct window_mode_entry *wme, ! const char *separators, u_int *ppx, u_int *ppy) { struct window_copy_mode_data *data = wme->data; struct screen *back_s = data->backing; *************** *** 4729,4735 **** py = hsize + data->cy - data->oy; grid_reader_start(&gr, back_s->grid, px, py); ! grid_reader_cursor_previous_word(&gr, separators, already); grid_reader_get_cursor(&gr, &px, &py); *ppx = px; *ppy = py; --- 4731,4738 ---- py = hsize + data->cy - data->oy; grid_reader_start(&gr, back_s->grid, px, py); ! grid_reader_cursor_previous_word(&gr, separators, /* already= */ 0, ! /* stop_at_eol= */ 1); grid_reader_get_cursor(&gr, &px, &py); *ppx = px; *ppy = py; *************** *** 4744,4757 **** struct screen *back_s = data->backing; struct grid_reader gr; u_int px, py, oldy, hsize; px = data->cx; hsize = screen_hsize(back_s); py = hsize + data->cy - data->oy; oldy = data->cy; grid_reader_start(&gr, back_s->grid, px, py); ! grid_reader_cursor_previous_word(&gr, separators, already); grid_reader_get_cursor(&gr, &px, &py); window_copy_acquire_cursor_up(wme, hsize, data->oy, oldy, px, py); } --- 4747,4765 ---- struct screen *back_s = data->backing; struct grid_reader gr; u_int px, py, oldy, hsize; + int stop_at_eol; + stop_at_eol = + options_get_number(wme->wp->window->options, "mode-keys") + == MODEKEY_EMACS; + px = data->cx; hsize = screen_hsize(back_s); py = hsize + data->cy - data->oy; oldy = data->cy; grid_reader_start(&gr, back_s->grid, px, py); ! grid_reader_cursor_previous_word(&gr, separators, already, stop_at_eol); grid_reader_get_cursor(&gr, &px, &py); window_copy_acquire_cursor_up(wme, hsize, data->oy, oldy, px, py); } *************** *** 4893,4902 **** data->selflag = SEL_CHAR; switch (data->selflag) { case SEL_WORD: ! if (data->ws != NULL) { window_copy_update_cursor(wme, x, y); ! window_copy_cursor_previous_word_pos(wme, data->ws, 0, ! &x, &y); y -= screen_hsize(data->backing) - data->oy; } window_copy_update_cursor(wme, x, y); --- 4901,4910 ---- data->selflag = SEL_CHAR; switch (data->selflag) { case SEL_WORD: ! if (data->separators != NULL) { window_copy_update_cursor(wme, x, y); ! window_copy_cursor_previous_word_pos(wme, ! data->separators, &x, &y); y -= screen_hsize(data->backing) - data->oy; } window_copy_update_cursor(wme, x, y);