diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2009-07-12 16:15:34 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2009-07-12 16:15:34 +0000 |
commit | 22d51ec1ead8077f9528727db56e54e997da1775 (patch) | |
tree | 8c1a870eeec35123d22fa20c564676fbfea19d17 | |
parent | fa8333eddb747e9b3c2a72c4fab4308137891f49 (diff) | |
download | rtmux-22d51ec1ead8077f9528727db56e54e997da1775.tar.gz rtmux-22d51ec1ead8077f9528727db56e54e997da1775.tar.bz2 rtmux-22d51ec1ead8077f9528727db56e54e997da1775.zip |
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.
-rw-r--r-- | mode-key.c | 5 | ||||
-rw-r--r-- | status.c | 1 | ||||
-rw-r--r-- | tmux.1 | 3 | ||||
-rw-r--r-- | tmux.h | 1 | ||||
-rw-r--r-- | window-copy.c | 31 |
5 files changed, 39 insertions, 2 deletions
@@ -105,8 +105,9 @@ mode_key_lookup_vi(struct mode_key_data *mdata, int key) return (MODEKEYCMD_CHOOSE); return (MODEKEYCMD_COPYSELECTION); case '0': - case '^': return (MODEKEYCMD_STARTOFLINE); + case '^': + return (MODEKEYCMD_BACKTOINDENTATION); case '\033': return (MODEKEYCMD_CLEARSELECTION); case 'j': @@ -160,6 +161,8 @@ mode_key_lookup_emacs(struct mode_key_data *mdata, int key) return (MODEKEYCMD_CHOOSE); case '\001': return (MODEKEYCMD_STARTOFLINE); + case KEYC_ADDESC('m'): + return (MODEKEYCMD_BACKTOINDENTATION); case '\007': return (MODEKEYCMD_CLEARSELECTION); case '\027': @@ -709,6 +709,7 @@ status_prompt_key(struct client *c, int key) } break; case MODEKEYCMD_STARTOFLINE: + case MODEKEYCMD_BACKTOINDENTATION: if (c->prompt_index != 0) { c->prompt_index = 0; c->flags |= CLIENT_STATUS; @@ -306,7 +306,8 @@ option). The following keys are supported as appropriate for the mode: .Bl -column "FunctionXXXXXXXXXXXX" "viXXXXXX" "emacs" -offset indent .It Sy "Function" Ta Sy "vi" Ta Sy "emacs" -.It Li "Start of line" Ta "0 or ^" Ta "C-a" +.It Li "Start of line" Ta "0" Ta "C-a" +.It Li "Back to indentation" Ta "^" Ta "M-m" .It Li "Clear selection" Ta "Escape" Ta "C-g" .It Li "Copy selection" Ta "Enter" Ta "M-w" .It Li "Cursor down" Ta "j" Ta "Down" @@ -357,6 +357,7 @@ struct msg_resize_data { /* Editing keys. */ enum mode_key_cmd { MODEKEYCMD_BACKSPACE = 0x1000, + MODEKEYCMD_BACKTOINDENTATION, MODEKEYCMD_CHOOSE, MODEKEYCMD_CLEARSELECTION, MODEKEYCMD_COMPLETE, diff --git a/window-copy.c b/window-copy.c index fb249698..04f22a8a 100644 --- a/window-copy.c +++ b/window-copy.c @@ -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; |