summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-03-22 19:10:43 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-03-22 19:10:43 +0000
commit87576228346e3b893f1233e77d2741a42d274013 (patch)
tree0db4267a6ebecba81831fac19c52bc2b12ede633 /usr.bin/tmux
parenteab57f966bd5524c4855ceb254df2fa73c62daa8 (diff)
Add vi-style "jump" commands for copy mode, from Micah Cowan.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/mode-key.c15
-rw-r--r--usr.bin/tmux/tmux.120
-rw-r--r--usr.bin/tmux/tmux.h6
-rw-r--r--usr.bin/tmux/window-copy.c121
4 files changed, 156 insertions, 6 deletions
diff --git a/usr.bin/tmux/mode-key.c b/usr.bin/tmux/mode-key.c
index 72af34477cd..379620da4b9 100644
--- a/usr.bin/tmux/mode-key.c
+++ b/usr.bin/tmux/mode-key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mode-key.c,v 1.34 2010/03/02 00:32:41 nicm Exp $ */
+/* $OpenBSD: mode-key.c,v 1.35 2010/03/22 19:10:42 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -88,6 +88,10 @@ struct mode_key_cmdstr mode_key_cmdstr_copy[] = {
{ MODEKEYCOPY_GOTOLINE, "goto-line" },
{ MODEKEYCOPY_HISTORYBOTTOM, "history-bottom" },
{ MODEKEYCOPY_HISTORYTOP, "history-top" },
+ { MODEKEYCOPY_JUMP, "jump-forward" },
+ { MODEKEYCOPY_JUMPAGAIN, "jump-again" },
+ { MODEKEYCOPY_JUMPREVERSE, "jump-reverse" },
+ { MODEKEYCOPY_JUMPBACK, "jump-backward" },
{ MODEKEYCOPY_LEFT, "cursor-left" },
{ MODEKEYCOPY_RECTANGLETOGGLE, "rectangle-toggle" },
{ MODEKEYCOPY_MIDDLELINE, "middle-line" },
@@ -177,6 +181,8 @@ struct mode_key_tree mode_key_tree_vi_choice;
const struct mode_key_entry mode_key_vi_copy[] = {
{ ' ', 0, MODEKEYCOPY_STARTSELECTION },
{ '$', 0, MODEKEYCOPY_ENDOFLINE },
+ { ',', 0, MODEKEYCOPY_JUMPREVERSE },
+ { ';', 0, MODEKEYCOPY_JUMPAGAIN },
{ '/', 0, MODEKEYCOPY_SEARCHDOWN },
{ '0', 0, MODEKEYCOPY_STARTOFLINE },
{ '1', 0, MODEKEYCOPY_STARTNUMBERPREFIX },
@@ -192,6 +198,7 @@ const struct mode_key_entry mode_key_vi_copy[] = {
{ '?', 0, MODEKEYCOPY_SEARCHUP },
{ 'B', 0, MODEKEYCOPY_PREVIOUSSPACE },
{ 'E', 0, MODEKEYCOPY_NEXTSPACEEND },
+ { 'F', 0, MODEKEYCOPY_JUMPBACK },
{ 'G', 0, MODEKEYCOPY_HISTORYBOTTOM },
{ 'H', 0, MODEKEYCOPY_TOPLINE },
{ 'J', 0, MODEKEYCOPY_SCROLLDOWN },
@@ -213,6 +220,7 @@ const struct mode_key_entry mode_key_vi_copy[] = {
{ '^', 0, MODEKEYCOPY_BACKTOINDENTATION },
{ 'b', 0, MODEKEYCOPY_PREVIOUSWORD },
{ 'e', 0, MODEKEYCOPY_NEXTWORDEND },
+ { 'f', 0, MODEKEYCOPY_JUMP },
{ 'g', 0, MODEKEYCOPY_HISTORYTOP },
{ 'h', 0, MODEKEYCOPY_LEFT },
{ 'j', 0, MODEKEYCOPY_DOWN },
@@ -290,6 +298,8 @@ struct mode_key_tree mode_key_tree_emacs_choice;
/* emacs copy mode keys. */
const struct mode_key_entry mode_key_emacs_copy[] = {
{ ' ', 0, MODEKEYCOPY_NEXTPAGE },
+ { ',', 0, MODEKEYCOPY_JUMPREVERSE },
+ { ';', 0, MODEKEYCOPY_JUMPAGAIN },
{ '1' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX },
{ '2' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX },
{ '3' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX },
@@ -301,6 +311,8 @@ const struct mode_key_entry mode_key_emacs_copy[] = {
{ '9' | KEYC_ESCAPE, 0, MODEKEYCOPY_STARTNUMBERPREFIX },
{ '<' | KEYC_ESCAPE, 0, MODEKEYCOPY_HISTORYTOP },
{ '>' | KEYC_ESCAPE, 0, MODEKEYCOPY_HISTORYBOTTOM },
+ { 'F', 0, MODEKEYCOPY_JUMPBACK },
+ { 'N', 0, MODEKEYCOPY_SEARCHREVERSE },
{ 'R' | KEYC_ESCAPE, 0, MODEKEYCOPY_TOPLINE },
{ 'R', 0, MODEKEYCOPY_RECTANGLETOGGLE },
{ '\000' /* C-Space */, 0, MODEKEYCOPY_STARTSELECTION },
@@ -319,6 +331,7 @@ const struct mode_key_entry mode_key_emacs_copy[] = {
{ '\033' /* Escape */, 0, MODEKEYCOPY_CANCEL },
{ 'N', 0, MODEKEYCOPY_SEARCHREVERSE },
{ 'b' | KEYC_ESCAPE, 0, MODEKEYCOPY_PREVIOUSWORD },
+ { 'f', 0, MODEKEYCOPY_JUMP },
{ 'f' | KEYC_ESCAPE, 0, MODEKEYCOPY_NEXTWORDEND },
{ 'g', 0, MODEKEYCOPY_GOTOLINE },
{ 'm' | KEYC_ESCAPE, 0, MODEKEYCOPY_BACKTOINDENTATION },
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index d4db23b4ecd..c18d880fcdb 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.156 2010/03/22 19:07:52 nicm Exp $
+.\" $Id: tmux.1,v 1.157 2010/03/22 19:10:42 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -610,7 +610,7 @@ The keys available depend on whether emacs or vi mode is selected
.Ic mode-keys
option).
The following keys are supported as appropriate for the mode:
-.Bl -column "FunctionXXXXXXXXXXXXXX" "viXXXXXXXXXX" "emacs" -offset indent
+.Bl -column "FunctionXXXXXXXXXXXXXXXXX" "viXXXXXXXXXX" "emacs" -offset indent
.It Sy "Function" Ta Sy "vi" Ta Sy "emacs"
.It Li "Back to indentation" Ta "^" Ta "M-m"
.It Li "Bottom of history" Ta "G" Ta "M-<"
@@ -629,6 +629,10 @@ The following keys are supported as appropriate for the mode:
.It Li "Go to line" Ta ":" Ta "g"
.It Li "Half page down" Ta "C-d" Ta "M-Down"
.It Li "Half page up" Ta "C-u" Ta "M-Up"
+.It Li "Jump forward" Ta "f" Ta "f"
+.It Li "Jump backward" Ta "F" Ta "F"
+.It Li "Jump again" Ta ";" Ta ";"
+.It Li "Jump again in reverse" Ta "," Ta ","
.It Li "Next page" Ta "C-f" Ta "Page down"
.It Li "Next space" Ta "W" Ta ""
.It Li "Next space, end of word" Ta "E" Ta ""
@@ -666,6 +670,18 @@ next word and previous word to the start of the previous word.
The three next and previous space keys work similarly but use a space alone as
the word separator.
.Pp
+The jump commands enable quick movement within a line.
+For instance, typing
+.Ql f
+followed by
+.Ql /
+will move the cursor to the next
+.Ql /
+character on the current line.
+A
+.Ql \&;
+will then jump to the next occurrence.
+.Pp
Commands in copy mode may be prefaced by an optional repeat count.
With vi key bindings, a prefix is entered using the number keys; with
emacs, the Alt (meta) key and a number begins prefix entry.
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 4ae525ebe49..0280868e068 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.211 2010/03/22 19:07:52 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.212 2010/03/22 19:10:42 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -459,6 +459,10 @@ enum mode_key_cmd {
MODEKEYCOPY_HALFPAGEUP,
MODEKEYCOPY_HISTORYBOTTOM,
MODEKEYCOPY_HISTORYTOP,
+ MODEKEYCOPY_JUMP,
+ MODEKEYCOPY_JUMPAGAIN,
+ MODEKEYCOPY_JUMPREVERSE,
+ MODEKEYCOPY_JUMPBACK,
MODEKEYCOPY_LEFT,
MODEKEYCOPY_MIDDLELINE,
MODEKEYCOPY_NEXTPAGE,
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index b7f9b95e9ab..9c2a658e961 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.51 2010/03/14 23:31:23 nicm Exp $ */
+/* $Id: window-copy.c,v 1.52 2010/03/22 19:10:42 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -65,6 +65,8 @@ void window_copy_cursor_left(struct window_pane *);
void window_copy_cursor_right(struct window_pane *);
void window_copy_cursor_up(struct window_pane *, int);
void window_copy_cursor_down(struct window_pane *, int);
+void window_copy_cursor_jump(struct window_pane *);
+void window_copy_cursor_jump_back(struct window_pane *);
void window_copy_cursor_next_word(struct window_pane *, const char *);
void window_copy_cursor_next_word_end(struct window_pane *, const char *);
void window_copy_cursor_previous_word(struct window_pane *, const char *);
@@ -86,6 +88,8 @@ enum window_copy_input_type {
WINDOW_COPY_NUMERICPREFIX,
WINDOW_COPY_SEARCHUP,
WINDOW_COPY_SEARCHDOWN,
+ WINDOW_COPY_JUMPFORWARD,
+ WINDOW_COPY_JUMPBACK,
WINDOW_COPY_GOTOLINE,
};
@@ -115,6 +119,9 @@ struct window_copy_mode_data {
enum window_copy_input_type searchtype;
char *searchstr;
+
+ enum window_copy_input_type jumptype;
+ char jumpchar;
};
struct screen *
@@ -147,6 +154,9 @@ window_copy_init(struct window_pane *wp)
wp->flags |= PANE_FREEZE;
bufferevent_disable(wp->event, EV_READ|EV_WRITE);
+ data->jumptype = WINDOW_COPY_OFF;
+ data->jumpchar = '\0';
+
s = &data->screen;
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
if (options_get_number(&wp->window->options, "mode-mouse"))
@@ -242,7 +252,24 @@ window_copy_key(struct window_pane *wp, struct client *c, int key)
if (np == 0)
np = 1;
- if (data->inputtype == WINDOW_COPY_NUMERICPREFIX) {
+ if (data->inputtype == WINDOW_COPY_JUMPFORWARD
+ || data->inputtype == WINDOW_COPY_JUMPBACK) {
+ /* Ignore keys with modifiers. */
+ if ((key & 0xff00) == 0) {
+ data->jumpchar = key;
+ if (data->inputtype == WINDOW_COPY_JUMPFORWARD) {
+ for (; np != 0; np--)
+ window_copy_cursor_jump(wp);
+ } else {
+ for (; np != 0; np--)
+ window_copy_cursor_jump_back(wp);
+ }
+ }
+ data->jumptype = data->inputtype;
+ data->inputtype = WINDOW_COPY_OFF;
+ window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
+ return;
+ } if (data->inputtype == WINDOW_COPY_NUMERICPREFIX) {
if (window_copy_key_numeric_prefix(wp, key) == 0)
return;
data->inputtype = WINDOW_COPY_OFF;
@@ -407,6 +434,36 @@ window_copy_key(struct window_pane *wp, struct client *c, int key)
for (; np != 0; np--)
window_copy_cursor_previous_word(wp, word_separators);
break;
+ case MODEKEYCOPY_JUMP:
+ data->inputtype = WINDOW_COPY_JUMPFORWARD;
+ data->inputprompt = "Jump Forward";
+ *data->inputstr = '\0';
+ window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
+ return; /* skip numprefix reset */
+ case MODEKEYCOPY_JUMPAGAIN:
+ if (data->jumptype == WINDOW_COPY_JUMPFORWARD) {
+ for (; np != 0; np--)
+ window_copy_cursor_jump(wp);
+ } else if (data->jumptype == WINDOW_COPY_JUMPBACK) {
+ for (; np != 0; np--)
+ window_copy_cursor_jump_back(wp);
+ }
+ break;
+ case MODEKEYCOPY_JUMPREVERSE:
+ if (data->jumptype == WINDOW_COPY_JUMPFORWARD) {
+ for (; np != 0; np--)
+ window_copy_cursor_jump_back(wp);
+ } else if (data->jumptype == WINDOW_COPY_JUMPBACK) {
+ for (; np != 0; np--)
+ window_copy_cursor_jump(wp);
+ }
+ break;
+ case MODEKEYCOPY_JUMPBACK:
+ data->inputtype = WINDOW_COPY_JUMPBACK;
+ data->inputprompt = "Jump Back";
+ *data->inputstr = '\0';
+ window_copy_redraw_lines(wp, screen_size_y(s) - 1, 1);
+ return; /* skip numprefix reset */
case MODEKEYCOPY_SEARCHUP:
data->inputtype = WINDOW_COPY_SEARCHUP;
data->inputprompt = "Search Up";
@@ -420,6 +477,8 @@ window_copy_key(struct window_pane *wp, struct client *c, int key)
switch (data->searchtype) {
case WINDOW_COPY_OFF:
case WINDOW_COPY_GOTOLINE:
+ case WINDOW_COPY_JUMPFORWARD:
+ case WINDOW_COPY_JUMPBACK:
case WINDOW_COPY_NUMERICPREFIX:
break;
case WINDOW_COPY_SEARCHUP:
@@ -524,6 +583,8 @@ window_copy_key_input(struct window_pane *wp, int key)
switch (data->inputtype) {
case WINDOW_COPY_OFF:
+ case WINDOW_COPY_JUMPFORWARD:
+ case WINDOW_COPY_JUMPBACK:
case WINDOW_COPY_NUMERICPREFIX:
break;
case WINDOW_COPY_SEARCHUP:
@@ -1381,6 +1442,62 @@ window_copy_cursor_down(struct window_pane *wp, int scroll_only)
}
void
+window_copy_cursor_jump(struct window_pane *wp)
+{
+ struct window_copy_mode_data *data = wp->modedata;
+ struct screen *base_s = &wp->base;
+ const struct grid_cell *gc;
+ uint px, py, xx;
+
+ px = data->cx + 1;
+ py = screen_hsize(base_s) + data->cy - data->oy;
+ xx = window_copy_find_length(wp, py);
+
+ while (px < xx) {
+ gc = grid_peek_cell(base_s->grid, px, py);
+ if ((gc->flags & (GRID_FLAG_PADDING|GRID_FLAG_UTF8)) == 0
+ && gc->data == data->jumpchar) {
+
+ window_copy_update_cursor(wp, px, data->cy);
+ if (window_copy_update_selection(wp))
+ window_copy_redraw_lines(wp, data->cy, 1);
+ return;
+ }
+ px++;
+ }
+}
+
+void
+window_copy_cursor_jump_back(struct window_pane *wp)
+{
+ struct window_copy_mode_data *data = wp->modedata;
+ struct screen *base_s = &wp->base;
+ const struct grid_cell *gc;
+ uint px, py;
+
+ px = data->cx;
+ py = screen_hsize(base_s) + data->cy - data->oy;
+
+ if (px > 0)
+ px--;
+
+ for (;;) {
+ gc = grid_peek_cell(base_s->grid, px, py);
+ if ((gc->flags & (GRID_FLAG_PADDING|GRID_FLAG_UTF8)) == 0
+ && gc->data == data->jumpchar) {
+
+ window_copy_update_cursor(wp, px, data->cy);
+ if (window_copy_update_selection(wp))
+ window_copy_redraw_lines(wp, data->cy, 1);
+ return;
+ }
+ if (px == 0)
+ break;
+ px--;
+ }
+}
+
+void
window_copy_cursor_next_word(struct window_pane *wp, const char *separators)
{
struct window_copy_mode_data *data = wp->modedata;