diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-12 16:15:35 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-12 16:15:35 +0000 |
commit | c364a2e66a6ad8a24597aec99363087a84b466c9 (patch) | |
tree | 7360b2e316001994a930c83d1ee2042888084588 /usr.bin/tmux/window-copy.c | |
parent | cce3b6f7896fd45d90f7eeefeedd71e28daabea9 (diff) |
Add a "back to indentation" key in copy mode to move the cursor to the first
non-whitespace character. ^ with vi and M-m with emacs key bindings. Another
from Kalle Olavi Niemitalo, thanks.
Diffstat (limited to 'usr.bin/tmux/window-copy.c')
-rw-r--r-- | usr.bin/tmux/window-copy.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 115a8a2b1cc..f9afc385b44 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.5 2009/07/12 16:12:34 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.6 2009/07/12 16:15:34 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -50,6 +50,7 @@ int window_copy_is_space(struct window_pane *, u_int, u_int); u_int window_copy_find_length(struct window_pane *, u_int); void window_copy_set_cursor_x(struct window_pane *, u_int); void window_copy_cursor_start_of_line(struct window_pane *); +void window_copy_cursor_back_to_indentation(struct window_pane *); void window_copy_cursor_end_of_line(struct window_pane *); void window_copy_cursor_left(struct window_pane *); void window_copy_cursor_right(struct window_pane *); @@ -207,6 +208,9 @@ window_copy_key(struct window_pane *wp, struct client *c, int key) case MODEKEYCMD_STARTOFLINE: window_copy_cursor_start_of_line(wp); break; + case MODEKEYCMD_BACKTOINDENTATION: + window_copy_cursor_back_to_indentation(wp); + break; case MODEKEYCMD_ENDOFLINE: window_copy_cursor_end_of_line(wp); break; @@ -601,6 +605,33 @@ window_copy_cursor_start_of_line(struct window_pane *wp) } void +window_copy_cursor_back_to_indentation(struct window_pane *wp) +{ + struct window_copy_mode_data *data = wp->modedata; + u_int px, py, xx; + const struct grid_cell *gc; + + px = 0; + py = screen_hsize(&wp->base) + data->cy - data->oy; + xx = window_copy_find_length(wp, py); + + /* + * Don't use window_copy_is_space because that treats some word + * delimiters as spaces. + */ + while (px < xx) { + gc = grid_peek_cell(wp->base.grid, px, py); + if (gc->flags & GRID_FLAG_UTF8) + break; + if (gc->data != ' ') + break; + px++; + } + + window_copy_set_cursor_x(wp, px); +} + +void window_copy_cursor_end_of_line(struct window_pane *wp) { struct window_copy_mode_data *data = wp->modedata; |