Index: uspace/app/edit/edit.c
===================================================================
--- uspace/app/edit/edit.c	(revision 8f6bffdd5f07c465191c6c37d5347f89fc317817)
+++ uspace/app/edit/edit.c	(revision ad780544d441f9ddecd38ab48b2e79bcea7123cb)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2009 Jiri Svoboda
+ * Copyright (c) 2012 Martin Sucha
  * All rights reserved.
  *
@@ -49,4 +50,5 @@
 
 #include "sheet.h"
+#include "search.h"
 
 enum redraw_flags {
@@ -83,4 +85,7 @@
 	 */
 	int ideal_column;
+	
+	char *previous_search;
+	bool previous_search_reverse;
 } pane_t;
 
@@ -91,5 +96,5 @@
 typedef struct {
 	char *file_name;
-	sheet_t sh;
+	sheet_t *sh;
 } doc_t;
 
@@ -126,6 +131,7 @@
 static int file_save_range(char const *fname, spt_t const *spos,
     spt_t const *epos);
-static char *filename_prompt(char const *prompt, char const *init_value);
 static char *range_get_str(spt_t const *spos, spt_t const *epos);
+
+static char *prompt(char const *prompt, char const *init_value);
 
 static void pane_text_display(void);
@@ -139,17 +145,22 @@
 static void delete_char_after(void);
 static void caret_update(void);
-static void caret_move(int drow, int dcolumn, enum dir_spec align_dir);
-static void caret_move_word_left(void);
-static void caret_move_word_right(void);
+static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir, bool select);
+static void caret_move_absolute(int row, int column, enum dir_spec align_dir, bool select);
+static void caret_move(spt_t spt, bool select, bool update_ideal_column);
+static void caret_move_word_left(bool select);
+static void caret_move_word_right(bool select);
+static void caret_go_to_line_ask(void);
 
 static bool selection_active(void);
 static void selection_sel_all(void);
 static void selection_sel_range(spt_t pa, spt_t pb);
-static void selection_sel_prev_word(void);
-static void selection_sel_next_word(void);
 static void selection_get_points(spt_t *pa, spt_t *pb);
 static void selection_delete(void);
 static void selection_copy(void);
 static void insert_clipboard_data(void);
+
+static void search(char *pattern, bool reverse);
+static void search_prompt(bool reverse);
+static void search_repeat(void);
 
 static void pt_get_sof(spt_t *pt);
@@ -160,4 +171,7 @@
 static bool pt_is_delimiter(spt_t *pt);
 static bool pt_is_punctuation(spt_t *pt);
+static spt_t pt_find_word_left(spt_t spt);
+static spt_t pt_find_word_left(spt_t spt);
+
 static int tag_cmp(tag_t const *a, tag_t const *b);
 static int spt_cmp(spt_t const *a, spt_t const *b);
@@ -170,8 +184,6 @@
 {
 	kbd_event_t ev;
-	coord_t coord;
 	bool new_file;
-
-	spt_t pt;
+	int rc;
 
 	con = console_init(stdin, stdout);
@@ -186,11 +198,15 @@
 
 	/* Start with an empty sheet. */
-	sheet_init(&doc.sh);
+	rc = sheet_create(&doc.sh);
+	if (rc != EOK) {
+		printf("Out of memory.\n");
+		return -1;
+	}
 
 	/* Place caret at the beginning of file. */
-	coord.row = coord.column = 1;
-	sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt);
-	sheet_place_tag(&doc.sh, &pt, &pane.caret_pos);
-	pane.ideal_column = coord.column;
+	spt_t sof;
+	pt_get_sof(&sof);
+	sheet_place_tag(doc.sh, &sof, &pane.caret_pos);
+	pane.ideal_column = 1;
 
 	if (argc == 2) {
@@ -208,10 +224,10 @@
 		new_file = true;
 
+	/* Place selection start tag. */
+	sheet_place_tag(doc.sh, &sof, &pane.sel_start);
+
 	/* Move to beginning of file. */
-	caret_move(-ED_INFTY, -ED_INFTY, dir_before);
-
-	/* Place selection start tag. */
-	tag_get_pt(&pane.caret_pos, &pt);
-	sheet_place_tag(&doc.sh, &pt, &pane.sel_start);
+	pt_get_sof(&sof);
+	caret_move(sof, true, true);
 
 	/* Initial display */
@@ -361,4 +377,5 @@
 static void key_handle_ctrl(kbd_event_t const *ev)
 {
+	spt_t pt;
 	switch (ev->key) {
 	case KC_Q:
@@ -392,15 +409,26 @@
 		selection_sel_all();
 		break;
-	case KC_W:
-		if (selection_active())
-			break;
-		selection_sel_prev_word();
-		selection_delete();
-		break;
 	case KC_RIGHT:
-		caret_move_word_right();
+		caret_move_word_right(false);
 		break;
 	case KC_LEFT:
-		caret_move_word_left();
+		caret_move_word_left(false);
+		break;
+	case KC_L:
+		caret_go_to_line_ask();
+		break;
+	case KC_F:
+		search_prompt(false);
+		break;
+	case KC_N:
+		search_repeat();
+		break;
+	case KC_HOME:
+		pt_get_sof(&pt);
+		caret_move(pt, false, true);
+		break;
+	case KC_END:
+		pt_get_eof(&pt);
+		caret_move(pt, false, true);
 		break;
 	default:
@@ -411,10 +439,22 @@
 static void key_handle_shift_ctrl(kbd_event_t const *ev)
 {
+	spt_t pt;
 	switch(ev->key) {
 	case KC_LEFT:
-		selection_sel_prev_word();
+		caret_move_word_left(true);
 		break;
 	case KC_RIGHT:
-		selection_sel_next_word();
+		caret_move_word_right(true);
+		break;
+	case KC_F:
+		search_prompt(true);
+		break;
+	case KC_HOME:
+		pt_get_sof(&pt);
+		caret_move(pt, true, true);
+		break;
+	case KC_END:
+		pt_get_eof(&pt);
+		caret_move(pt, true, true);
 		break;
 	default:
@@ -423,56 +463,29 @@
 }
 
-static void key_handle_movement(unsigned int key, bool select)
-{
-	spt_t pt;
-	spt_t caret_pt;
+/** Move caret while preserving or resetting selection. */
+static void caret_move(spt_t new_caret_pt, bool select, bool update_ideal_column)
+{
+	spt_t old_caret_pt, old_sel_pt;
 	coord_t c_old, c_new;
 	bool had_sel;
 
 	/* Check if we had selection before. */
-	tag_get_pt(&pane.caret_pos, &caret_pt);
-	tag_get_pt(&pane.sel_start, &pt);
-	had_sel = !spt_equal(&caret_pt, &pt);
-
-	switch (key) {
-	case KC_LEFT:
-		caret_move(0, -1, dir_before);
-		break;
-	case KC_RIGHT:
-		caret_move(0, 0, dir_after);
-		break;
-	case KC_UP:
-		caret_move(-1, 0, dir_before);
-		break;
-	case KC_DOWN:
-		caret_move(+1, 0, dir_before);
-		break;
-	case KC_HOME:
-		caret_move(0, -ED_INFTY, dir_before);
-		break;
-	case KC_END:
-		caret_move(0, +ED_INFTY, dir_before);
-		break;
-	case KC_PAGE_UP:
-		caret_move(-pane.rows, 0, dir_before);
-		break;
-	case KC_PAGE_DOWN:
-		caret_move(+pane.rows, 0, dir_before);
-		break;
-	default:
-		break;
-	}
+	tag_get_pt(&pane.caret_pos, &old_caret_pt);
+	tag_get_pt(&pane.sel_start, &old_sel_pt);
+	had_sel = !spt_equal(&old_caret_pt, &old_sel_pt);
+
+	/* Place tag of the caret */
+	sheet_remove_tag(doc.sh, &pane.caret_pos);
+	sheet_place_tag(doc.sh, &new_caret_pt, &pane.caret_pos);
 
 	if (select == false) {
 		/* Move sel_start to the same point as caret. */
-		sheet_remove_tag(&doc.sh, &pane.sel_start);
-		tag_get_pt(&pane.caret_pos, &pt);
-		sheet_place_tag(&doc.sh, &pt, &pane.sel_start);
-	}
-
+		sheet_remove_tag(doc.sh, &pane.sel_start);
+		sheet_place_tag(doc.sh, &new_caret_pt, &pane.sel_start);
+	}
+
+	spt_get_coord(&new_caret_pt, &c_new);
 	if (select) {
-		tag_get_pt(&pane.caret_pos, &pt);
-		spt_get_coord(&caret_pt, &c_old);
-		spt_get_coord(&pt, &c_new);
+		spt_get_coord(&old_caret_pt, &c_old);
 
 		if (c_old.row == c_new.row)
@@ -485,4 +498,41 @@
 		pane.rflags |= REDRAW_TEXT;
 	}
+	
+	if (update_ideal_column)
+		pane.ideal_column = c_new.column;
+	
+	caret_update();
+}
+
+static void key_handle_movement(unsigned int key, bool select)
+{
+	switch (key) {
+	case KC_LEFT:
+		caret_move_relative(0, -1, dir_before, select);
+		break;
+	case KC_RIGHT:
+		caret_move_relative(0, 0, dir_after, select);
+		break;
+	case KC_UP:
+		caret_move_relative(-1, 0, dir_before, select);
+		break;
+	case KC_DOWN:
+		caret_move_relative(+1, 0, dir_before, select);
+		break;
+	case KC_HOME:
+		caret_move_relative(0, -ED_INFTY, dir_after, select);
+		break;
+	case KC_END:
+		caret_move_relative(0, +ED_INFTY, dir_before, select);
+		break;
+	case KC_PAGE_UP:
+		caret_move_relative(-pane.rows, 0, dir_before, select);
+		break;
+	case KC_PAGE_DOWN:
+		caret_move_relative(+pane.rows, 0, dir_before, select);
+		break;
+	default:
+		break;
+	}
 }
 
@@ -520,5 +570,5 @@
 	char *fname;
 	
-	fname = filename_prompt("Save As", old_fname);
+	fname = prompt("Save As", old_fname);
 	if (fname == NULL) {
 		status_display("Save cancelled.");
@@ -535,6 +585,6 @@
 }
 
-/** Ask for a file name. */
-static char *filename_prompt(char const *prompt, char const *init_value)
+/** Ask for a string. */
+static char *prompt(char const *prompt, char const *init_value)
 {
 	kbd_event_t ev;
@@ -657,5 +707,5 @@
 
 	do {
-		sheet_copy_out(&doc.sh, &sp, epos, buf, BUF_SIZE, &bep);
+		sheet_copy_out(doc.sh, &sp, epos, buf, BUF_SIZE, &bep);
 		bytes = str_size(buf);
 
@@ -692,5 +742,5 @@
 
 	while (true) {
-		sheet_copy_out(&doc.sh, &sp, epos, &buf[bpos], buf_size - bpos,
+		sheet_copy_out(doc.sh, &sp, epos, &buf[bpos], buf_size - bpos,
 		    &bep);
 		bytes = str_size(&buf[bpos]);
@@ -714,5 +764,5 @@
 	int sh_rows, rows;
 
-	sheet_get_num_rows(&doc.sh, &sh_rows);
+	sheet_get_num_rows(doc.sh, &sh_rows);
 	rows = min(sh_rows - pane.sh_row + 1, pane.rows);
 
@@ -784,13 +834,13 @@
 		rbc.row = pane.sh_row + i;
 		rbc.column = pane.sh_column;
-		sheet_get_cell_pt(&doc.sh, &rbc, dir_before, &rb);
+		sheet_get_cell_pt(doc.sh, &rbc, dir_before, &rb);
 
 		/* Ending point for row display */
 		rec.row = pane.sh_row + i;
 		rec.column = pane.sh_column + pane.columns;
-		sheet_get_cell_pt(&doc.sh, &rec, dir_before, &re);
+		sheet_get_cell_pt(doc.sh, &rec, dir_before, &re);
 
 		/* Copy the text of the row to the buffer. */
-		sheet_copy_out(&doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep);
+		sheet_copy_out(doc.sh, &rb, &re, row_buf, ROW_BUF_SIZE, &dep);
 
 		/* Display text from the buffer. */
@@ -842,6 +892,6 @@
 		/* Fill until the end of display area. */
 
-		if (str_length(row_buf) < (unsigned) scr_columns)
-			fill = scr_columns - str_length(row_buf);
+		if ((unsigned)s_column - 1 < scr_columns)
+			fill = scr_columns - (s_column - 1);
 		else
 			fill = 0;
@@ -861,14 +911,17 @@
 	spt_t caret_pt;
 	coord_t coord;
+	int last_row;
 
 	tag_get_pt(&pane.caret_pos, &caret_pt);
 	spt_get_coord(&caret_pt, &coord);
 
+	sheet_get_num_rows(doc.sh, &last_row);
+
 	const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>";
 
 	console_set_pos(con, 0, scr_rows - 1);
 	console_set_style(con, STYLE_INVERTED);
-	int n = printf(" %d, %d: File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
-	    "Ctrl-E Save As", coord.row, coord.column, fname);
+	int n = printf(" %d, %d (%d): File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
+	    "Ctrl-E Save As", coord.row, coord.column, last_row, fname);
 	
 	int pos = scr_columns - 1 - n;
@@ -906,5 +959,5 @@
 	cbuf[offs] = '\0';
 
-	(void) sheet_insert(&doc.sh, &pt, dir_before, cbuf);
+	(void) sheet_insert(doc.sh, &pt, dir_before, cbuf);
 
 	pane.rflags |= REDRAW_ROW;
@@ -923,7 +976,7 @@
 
 	coord.column -= 1;
-	sheet_get_cell_pt(&doc.sh, &coord, dir_before, &sp);
-
-	(void) sheet_delete(&doc.sh, &sp, &ep);
+	sheet_get_cell_pt(doc.sh, &coord, dir_before, &sp);
+
+	(void) sheet_delete(doc.sh, &sp, &ep);
 
 	pane.rflags |= REDRAW_ROW;
@@ -941,8 +994,8 @@
 	spt_get_coord(&sp, &sc);
 
-	sheet_get_cell_pt(&doc.sh, &sc, dir_after, &ep);
+	sheet_get_cell_pt(doc.sh, &sc, dir_after, &ep);
 	spt_get_coord(&ep, &ec);
 
-	(void) sheet_delete(&doc.sh, &sp, &ep);
+	(void) sheet_delete(doc.sh, &sp, &ep);
 
 	pane.rflags |= REDRAW_ROW;
@@ -991,5 +1044,5 @@
 }
 
-/** Change the caret position.
+/** Relatively move caret position.
  *
  * Moves caret relatively to the current position. Looking at the first
@@ -997,6 +1050,9 @@
  * to a new character cell, and thus a new character. Then we either go to the
  * point before the the character or after it, depending on @a align_dir.
+ *
+ * @param select true if the selection tag should stay where it is
  */
-static void caret_move(int drow, int dcolumn, enum dir_spec align_dir)
+static void caret_move_relative(int drow, int dcolumn, enum dir_spec align_dir,
+    bool select)
 {
 	spt_t pt;
@@ -1016,9 +1072,9 @@
 		else {
 			coord.row--;
-			sheet_get_row_width(&doc.sh, coord.row, &coord.column);
+			sheet_get_row_width(doc.sh, coord.row, &coord.column);
 		}
 	}
 	if (drow > 0) {
-		sheet_get_num_rows(&doc.sh, &num_rows);
+		sheet_get_num_rows(doc.sh, &num_rows);
 		if (coord.row > num_rows) coord.row = num_rows;
 	}
@@ -1033,47 +1089,231 @@
 	 * coordinates. The character can be wider than one cell (e.g. tab).
 	 */
-	sheet_get_cell_pt(&doc.sh, &coord, align_dir, &pt);
-	sheet_remove_tag(&doc.sh, &pane.caret_pos);
-	sheet_place_tag(&doc.sh, &pt, &pane.caret_pos);
+	sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt);
 
 	/* For non-vertical movement set the new value for @c ideal_column. */
-	if (!pure_vertical) {
-		spt_get_coord(&pt, &coord);
-		pane.ideal_column = coord.column;
-	}
-
-	caret_update();
-}
-
-static void caret_move_word_left(void) 
-{
+	caret_move(pt, select, !pure_vertical);
+}
+
+/** Absolutely move caret position.
+ *
+ * Moves caret to a specified position. We get to a new character cell, and
+ * thus a new character. Then we either go to the point before the the character
+ * or after it, depending on @a align_dir.
+ *
+ * @param select true if the selection tag should stay where it is
+ */
+static void caret_move_absolute(int row, int column, enum dir_spec align_dir,
+    bool select)
+{
+	coord_t coord;
+	coord.row = row;
+	coord.column = column;
+	
 	spt_t pt;
-
+	sheet_get_cell_pt(doc.sh, &coord, align_dir, &pt);
+	
+	caret_move(pt, select, true);
+}
+
+/** Find beginning of a word to the left of spt */
+static spt_t pt_find_word_left(spt_t spt) 
+{
 	do {
-		caret_move(0, -1, dir_before);
-
-		tag_get_pt(&pane.caret_pos, &pt);
-
-		sheet_remove_tag(&doc.sh, &pane.sel_start);
-		sheet_place_tag(&doc.sh, &pt, &pane.sel_start);
-	} while (!pt_is_word_beginning(&pt));
-
-	pane.rflags |= REDRAW_TEXT;
-}
-
-static void caret_move_word_right(void) 
+		spt_prev_char(spt, &spt);
+	} while (!pt_is_word_beginning(&spt));
+	return spt;
+}
+
+/** Find beginning of a word to the right of spt */
+static spt_t pt_find_word_right(spt_t spt) 
+{
+	do {
+		spt_next_char(spt, &spt);
+	} while (!pt_is_word_beginning(&spt));
+	return spt;
+}
+
+static void caret_move_word_left(bool select) 
 {
 	spt_t pt;
-
-	do {
-		caret_move(0, 0, dir_after);
-
-		tag_get_pt(&pane.caret_pos, &pt);
-
-		sheet_remove_tag(&doc.sh, &pane.sel_start);
-		sheet_place_tag(&doc.sh, &pt, &pane.sel_start);
-	} while (!pt_is_word_beginning(&pt));
-
-	pane.rflags |= REDRAW_TEXT;
+	tag_get_pt(&pane.caret_pos, &pt);
+	spt_t word_left = pt_find_word_left(pt);
+	caret_move(word_left, select, true);
+}
+
+static void caret_move_word_right(bool select) 
+{
+	spt_t pt;
+	tag_get_pt(&pane.caret_pos, &pt);
+	spt_t word_right = pt_find_word_right(pt);
+	caret_move(word_right, select, true);
+}
+
+/** Ask for line and go to it. */
+static void caret_go_to_line_ask(void)
+{
+	char *sline;
+	
+	sline = prompt("Go to line", "");
+	if (sline == NULL) {
+		status_display("Go to line cancelled.");
+		return;
+	}
+	
+	char *endptr;
+	int line = strtol(sline, &endptr, 10);
+	if (*endptr != '\0') {
+		free(sline);
+		status_display("Invalid number entered.");
+		return;
+	}
+	free(sline);
+	
+	caret_move_absolute(line, pane.ideal_column, dir_before, false);
+}
+
+/* Search operations */
+static int search_spt_producer(void *data, wchar_t *ret)
+{
+	assert(data != NULL);
+	assert(ret != NULL);
+	spt_t *spt = data;
+	*ret = spt_next_char(*spt, spt);
+	return EOK;
+}
+
+static int search_spt_reverse_producer(void *data, wchar_t *ret)
+{
+	assert(data != NULL);
+	assert(ret != NULL);
+	spt_t *spt = data;
+	*ret = spt_prev_char(*spt, spt);
+	return EOK;
+}
+
+static int search_spt_mark(void *data, void **mark)
+{
+	assert(data != NULL);
+	assert(mark != NULL);
+	spt_t *spt = data;
+	spt_t *new = calloc(1, sizeof(spt_t));
+	*mark = new;
+	if (new == NULL)
+		return ENOMEM;
+	*new = *spt;
+	return EOK;
+}
+
+static void search_spt_mark_free(void *data)
+{
+	free(data);
+}
+
+static search_ops_t search_spt_ops = {
+	.equals = char_exact_equals,
+	.producer = search_spt_producer,
+	.mark = search_spt_mark,
+	.mark_free = search_spt_mark_free,
+};
+
+static search_ops_t search_spt_reverse_ops = {
+	.equals = char_exact_equals,
+	.producer = search_spt_reverse_producer,
+	.mark = search_spt_mark,
+	.mark_free = search_spt_mark_free,
+};
+
+/** Ask for line and go to it. */
+static void search_prompt(bool reverse)
+{
+	char *pattern;
+	
+	const char *prompt_text = "Find next";
+	if (reverse)
+		prompt_text = "Find previous";
+	
+	const char *default_value = "";
+	if (pane.previous_search)
+		default_value = pane.previous_search;
+	
+	pattern = prompt(prompt_text, default_value);
+	if (pattern == NULL) {
+		status_display("Search cancelled.");
+		return;
+	}
+	
+	if (pane.previous_search)
+		free(pane.previous_search);
+	pane.previous_search = pattern;
+	pane.previous_search_reverse = reverse;
+	
+	search(pattern, reverse);
+}
+
+static void search_repeat(void)
+{
+	if (pane.previous_search == NULL) {
+		status_display("No previous search to repeat.");
+		return;
+	}
+	
+	search(pane.previous_search, pane.previous_search_reverse);
+}
+
+static void search(char *pattern, bool reverse)
+{
+	status_display("Searching...");
+	
+	spt_t sp, producer_pos;
+	tag_get_pt(&pane.caret_pos, &sp);
+	
+	/* Start searching on the position before/after caret */
+	if (!reverse) {
+		spt_next_char(sp, &sp);
+	}
+	else {
+		spt_prev_char(sp, &sp);
+	}
+	producer_pos = sp;
+	
+	search_ops_t ops = search_spt_ops;
+	if (reverse)
+		ops = search_spt_reverse_ops;
+	
+	search_t *search = search_init(pattern, &producer_pos, ops, reverse);
+	if (search == NULL) {
+		status_display("Failed initializing search.");
+		return;
+	}
+	
+	match_t match;
+	int rc = search_next_match(search, &match);
+	if (rc != EOK) {
+		status_display("Failed searching.");
+		search_fini(search);
+	}
+	
+	if (match.end) {
+		status_display("Match found.");
+		assert(match.end != NULL);
+		spt_t *end = match.end;
+		caret_move(*end, false, true);
+		while (match.length > 0) {
+			match.length--;
+			if (reverse) {
+				spt_next_char(*end, end);
+			}
+			else {
+				spt_prev_char(*end, end);
+			}
+		}
+		caret_move(*end, true, true);
+		free(end);
+	}
+	else {
+		status_display("Not found.");
+	}
+	
+	search_fini(search);
 }
 
@@ -1115,7 +1355,7 @@
 
 	if (rel < 0)
-		sheet_delete(&doc.sh, &pa, &pb);
+		sheet_delete(doc.sh, &pa, &pb);
 	else
-		sheet_delete(&doc.sh, &pb, &pa);
+		sheet_delete(doc.sh, &pb, &pa);
 
 	if (ca.row == cb.row)
@@ -1139,45 +1379,11 @@
 static void selection_sel_range(spt_t pa, spt_t pb)
 {
-	sheet_remove_tag(&doc.sh, &pane.sel_start);
-	sheet_place_tag(&doc.sh, &pa, &pane.sel_start);
-	sheet_remove_tag(&doc.sh, &pane.caret_pos);
-	sheet_place_tag(&doc.sh, &pb, &pane.caret_pos);
+	sheet_remove_tag(doc.sh, &pane.sel_start);
+	sheet_place_tag(doc.sh, &pa, &pane.sel_start);
+	sheet_remove_tag(doc.sh, &pane.caret_pos);
+	sheet_place_tag(doc.sh, &pb, &pane.caret_pos);
 
 	pane.rflags |= REDRAW_TEXT;
 	caret_update();
-}
-
-/** Add the previous word to the selection */
-static void selection_sel_prev_word(void)
-{
-	spt_t cpt, wpt, spt, ept;
-
-	selection_get_points(&spt, &ept);
-
-	tag_get_pt(&pane.caret_pos, &cpt);
-	caret_move_word_left();
-	tag_get_pt(&pane.caret_pos, &wpt);
-
-	if (spt_cmp(&spt, &cpt) == 0)
-		selection_sel_range(ept, wpt);
-	else
-		selection_sel_range(spt, wpt);
-}
-
-/** Add the next word to the selection */
-static void selection_sel_next_word(void)
-{
-	spt_t cpt, wpt, spt, ept;
-
-	selection_get_points(&spt, &ept);
-
-	tag_get_pt(&pane.caret_pos, &cpt);
-	caret_move_word_right();
-	tag_get_pt(&pane.caret_pos, &wpt);
-
-	if (spt_cmp(&ept, &cpt) == 0)
-		selection_sel_range(spt, wpt);
-	else
-		selection_sel_range(ept, wpt);
 }
 
@@ -1225,5 +1431,5 @@
 
 	coord.row = coord.column = 1;
-	sheet_get_cell_pt(&doc.sh, &coord, dir_before, pt);
+	sheet_get_cell_pt(doc.sh, &coord, dir_before, pt);
 }
 
@@ -1234,9 +1440,9 @@
 	int num_rows;
 
-	sheet_get_num_rows(&doc.sh, &num_rows);
+	sheet_get_num_rows(doc.sh, &num_rows);
 	coord.row = num_rows + 1;
 	coord.column = 1;
 
-	sheet_get_cell_pt(&doc.sh, &coord, dir_after, pt);
+	sheet_get_cell_pt(doc.sh, &coord, dir_after, pt);
 }
 
@@ -1249,5 +1455,5 @@
 	coord.column = 1;
 
-	sheet_get_cell_pt(&doc.sh, &coord, dir_before, spt);
+	sheet_get_cell_pt(doc.sh, &coord, dir_before, spt);
 }
 
@@ -1259,8 +1465,8 @@
 
 	spt_get_coord(cpt, &coord);
-	sheet_get_row_width(&doc.sh, coord.row, &row_width);
+	sheet_get_row_width(doc.sh, coord.row, &row_width);
 	coord.column = row_width - 1;
 
-	sheet_get_cell_pt(&doc.sh, &coord, dir_after, ept);
+	sheet_get_cell_pt(doc.sh, &coord, dir_after, ept);
 }
 
@@ -1288,5 +1494,5 @@
 
 	coord.column -= 1;
-	sheet_get_cell_pt(&doc.sh, &coord, dir_before, &lp);
+	sheet_get_cell_pt(doc.sh, &coord, dir_before, &lp);
 
 	return pt_is_delimiter(&lp)
@@ -1310,5 +1516,5 @@
 
 	coord.column += 1;
-	sheet_get_cell_pt(&doc.sh, &coord, dir_after, &rp);
+	sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp);
 
 	ch = range_get_str(pt, &rp);
@@ -1336,5 +1542,5 @@
 
 	coord.column += 1;
-	sheet_get_cell_pt(&doc.sh, &coord, dir_after, &rp);
+	sheet_get_cell_pt(doc.sh, &coord, dir_after, &rp);
 
 	ch = range_get_str(pt, &rp);
