summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-02-22 20:41:17 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-02-22 20:41:17 +0000
commit4660e2ea587412c1d405544cd62ce0c2d92e2cb1 (patch)
treec9a62dd00c93e355a6af4383f517d72af19b8a27 /usr.bin/tmux
parent7fb8f346a12c8c48a5fe2da61fbc86cbd9dee9c2 (diff)
Option to set the characters considered word separators in copy mode, from
Micah Cowan.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-set-option.c3
-rw-r--r--usr.bin/tmux/tmux.119
-rw-r--r--usr.bin/tmux/tmux.c3
-rw-r--r--usr.bin/tmux/window-copy.c94
4 files changed, 74 insertions, 45 deletions
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c
index 42ee6ae583e..3751c02ebc8 100644
--- a/usr.bin/tmux/cmd-set-option.c
+++ b/usr.bin/tmux/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-option.c,v 1.34 2010/02/08 00:14:38 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.35 2010/02/22 20:41:16 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -165,6 +165,7 @@ const struct set_option_entry set_window_option_table[] = {
{ "window-status-current-format", SET_OPTION_STRING, 0, 0, NULL },
{ "window-status-fg", SET_OPTION_COLOUR, 0, 0, NULL },
{ "window-status-format", SET_OPTION_STRING, 0, 0, NULL },
+ { "word-separators", SET_OPTION_STRING, 0, 0, NULL },
{ "xterm-keys", SET_OPTION_FLAG, 0, 0, NULL },
{ NULL, 0, 0, 0, NULL }
};
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 5c3f1d4c2d4..5c4fd96102e 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.153 2010/02/17 21:12:06 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.154 2010/02/22 20:41:16 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: February 17 2010 $
+.Dd $Mdocdate: February 22 2010 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -649,11 +649,13 @@ The following keys are supported as appropriate for the mode:
.Pp
The next and previous word keys use space and the
.Ql - ,
-.Ql _ ,
-.Ql \&"
+.Ql _
and
.Ql @
-characters as word delimiters.
+characters as word delimiters by default, but this can be adjusted by
+setting the
+.Em word-separators
+window option.
Next word moves to the start of the next word, next word end to the end of the
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
@@ -2031,6 +2033,13 @@ Like
.Ar window-status-format ,
but is the format used when the window is the current window.
.Pp
+.It Ic word-separators Ar string
+Sets the window's conception of what characters are considered word
+separators, for the purposes of the next and previous word commands in
+copy mode.
+The default is
+.Ql \ -_@ .
+.Pp
.It Xo Ic xterm-keys
.Op Ic on | off
.Xc
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index dd9549b121c..711a5ab1348 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.72 2010/02/08 00:14:38 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.73 2010/02/22 20:41:16 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -418,6 +418,7 @@ main(int argc, char **argv)
options_set_number(wo, "window-status-fg", 8);
options_set_string(wo, "window-status-format", "#I:#W#F");
options_set_string(wo, "window-status-current-format", "#I:#W#F");
+ options_set_string(wo, "word-separators", " -_@");
options_set_number(wo, "xterm-keys", 0);
options_set_number(wo, "remain-on-exit", 0);
options_set_number(wo, "synchronize-panes", 0);
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index 9ecbb5d95d5..030557019d2 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.47 2010/02/22 20:28:21 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.48 2010/02/22 20:41:16 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -226,7 +226,7 @@ window_copy_resize(struct window_pane *wp, u_int sx, u_int sy)
void
window_copy_key(struct window_pane *wp, struct client *c, int key)
{
- const char *word_separators = " -_@";
+ const char *word_separators;
struct window_copy_mode_data *data = wp->modedata;
struct screen *s = &data->screen;
u_int n;
@@ -356,15 +356,21 @@ window_copy_key(struct window_pane *wp, struct client *c, int key)
window_copy_cursor_next_word_end(wp, " ");
break;
case MODEKEYCOPY_NEXTWORD:
+ word_separators =
+ options_get_string(&wp->window->options, "word-separators");
window_copy_cursor_next_word(wp, word_separators);
break;
case MODEKEYCOPY_NEXTWORDEND:
+ word_separators =
+ options_get_string(&wp->window->options, "word-separators");
window_copy_cursor_next_word_end(wp, word_separators);
break;
case MODEKEYCOPY_PREVIOUSSPACE:
window_copy_cursor_previous_word(wp, " ");
break;
case MODEKEYCOPY_PREVIOUSWORD:
+ word_separators =
+ options_get_string(&wp->window->options, "word-separators");
window_copy_cursor_previous_word(wp, word_separators);
break;
case MODEKEYCOPY_SEARCHUP:
@@ -1271,30 +1277,36 @@ window_copy_cursor_next_word(struct window_pane *wp, const char *separators)
struct window_copy_mode_data *data = wp->modedata;
struct screen *base_s = &wp->base;
u_int px, py, xx, yy;
+ int expected = 0;
px = data->cx;
py = screen_hsize(base_s) + data->cy - data->oy;
xx = window_copy_find_length(wp, py);
yy = screen_hsize(base_s) + screen_size_y(base_s) - 1;
- /* Are we in a word? Skip it! */
- while (!window_copy_in_set(wp, px, py, separators))
- px++;
-
- /* Find the start of a word. */
- while (px > xx || window_copy_in_set(wp, px, py, separators)) {
- /* Past the end of the line? Nothing but spaces. */
- if (px > xx) {
- if (py == yy)
- return;
- window_copy_cursor_down(wp, 0);
- px = 0;
-
- py = screen_hsize(base_s) + data->cy - data->oy;
- xx = window_copy_find_length(wp, py);
- } else
- px++;
- }
+ /*
+ * First skip past any nonword characters and then any word characters.
+ *
+ * expected is initially set to 0 for the former and then 1 for the
+ * latter.
+ */
+ do {
+ while (px > xx ||
+ window_copy_in_set(wp, px, py, separators) == expected) {
+ /* Move down if we're past the end of the line. */
+ if (px > xx) {
+ if (py == yy)
+ return;
+ window_copy_cursor_down(wp, 0);
+ px = 0;
+
+ py = screen_hsize(base_s) + data->cy - data->oy;
+ xx = window_copy_find_length(wp, py);
+ } else
+ px++;
+ }
+ expected = !expected;
+ } while (expected == 1);
window_copy_update_cursor(wp, px, data->cy);
if (window_copy_update_selection(wp))
@@ -1307,30 +1319,36 @@ window_copy_cursor_next_word_end(struct window_pane *wp, const char *separators)
struct window_copy_mode_data *data = wp->modedata;
struct screen *base_s = &wp->base;
u_int px, py, xx, yy;
+ int expected = 1;
px = data->cx;
py = screen_hsize(base_s) + data->cy - data->oy;
xx = window_copy_find_length(wp, py);
yy = screen_hsize(base_s) + screen_size_y(base_s) - 1;
- /* Are we on spaces? Skip 'em! */
- while (px > xx || window_copy_in_set(wp, px, py, separators)) {
- /* Nothing but spaces past the end of the line, so move down. */
- if (px > xx) {
- if (py == yy)
- return;
- window_copy_cursor_down(wp, 0);
- px = 0;
-
- py = screen_hsize(base_s) + data->cy - data->oy;
- xx = window_copy_find_length(wp, py);
- } else
- px++;
- }
-
- /* Find the end of this word. */
- while (!window_copy_in_set(wp, px, py, separators))
- px++;
+ /*
+ * First skip past any word characters, then any nonword characters.
+ *
+ * expected is initially set to 1 for the former and then 0 for the
+ * latter.
+ */
+ do {
+ while (px > xx ||
+ window_copy_in_set(wp, px, py, separators) == expected) {
+ /* Move down if we're past the end of the line. */
+ if (px > xx) {
+ if (py == yy)
+ return;
+ window_copy_cursor_down(wp, 0);
+ px = 0;
+
+ py = screen_hsize(base_s) + data->cy - data->oy;
+ xx = window_copy_find_length(wp, py);
+ } else
+ px++;
+ }
+ expected = !expected;
+ } while (expected == 0);
window_copy_update_cursor(wp, px, data->cy);
if (window_copy_update_selection(wp))