Index: uspace/app/edit/edit.c
===================================================================
--- uspace/app/edit/edit.c	(revision 8190e6374ca3cbd6ae6511780cbf11f5d24417e2)
+++ uspace/app/edit/edit.c	(revision 00413c5c7dfd26adbc32dc9cc467868315f9c621)
@@ -36,5 +36,4 @@
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <sys/types.h>
 #include <vfs/vfs.h>
@@ -45,5 +44,4 @@
 #include <align.h>
 #include <macros.h>
-#include <clipboard.h>
 #include <bool.h>
 
@@ -75,7 +73,4 @@
 	tag_t caret_pos;
 
-	/** Start of selection */
-	tag_t sel_start;
-
 	/** 
 	 * Ideal column where the caret should try to get. This is used
@@ -98,5 +93,4 @@
 static bool done;
 static pane_t pane;
-static bool cursor_visible;
 
 static int scr_rows, scr_columns;
@@ -107,24 +101,10 @@
 #define ED_INFTY 65536
 
-/** Maximum filename length that can be entered. */
-#define INFNAME_MAX_LEN 128
-
-static void cursor_show(void);
-static void cursor_hide(void);
-static void cursor_setvis(bool visible);
-
 static void key_handle_unmod(console_event_t const *ev);
 static void key_handle_ctrl(console_event_t const *ev);
-static void key_handle_shift(console_event_t const *ev);
-static void key_handle_movement(unsigned int key, bool shift);
-
 static int file_save(char const *fname);
-static void file_save_as(void);
 static int file_insert(char *fname);
 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 void pane_text_display(void);
 static void pane_row_display(void);
@@ -132,5 +112,4 @@
 static void pane_status_display(void);
 static void pane_caret_display(void);
-
 static void insert_char(wchar_t c);
 static void delete_char_before(void);
@@ -138,18 +117,6 @@
 static void caret_update(void);
 static void caret_move(int drow, int dcolumn, enum dir_spec align_dir);
-
-static bool selection_active(void);
-static void selection_sel_all(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 pt_get_sof(spt_t *pt);
 static void pt_get_eof(spt_t *pt);
-static int tag_cmp(tag_t const *a, tag_t const *b);
-static int spt_cmp(spt_t const *a, spt_t const *b);
-static int coord_cmp(coord_t const *a, coord_t const *b);
-
 static void status_display(char const *str);
 
@@ -183,15 +150,15 @@
 
 	if (argc == 2) {
-		doc.file_name = str_dup(argv[1]);
+		doc.file_name = argv[1];
 	} else if (argc > 1) {
 		printf("Invalid arguments.\n");
 		return -2;
 	} else {
-		doc.file_name = NULL;
+		doc.file_name = "/edit.txt";
 	}
 
 	new_file = false;
 
-	if (doc.file_name == NULL || file_insert(doc.file_name) != EOK)
+	if (file_insert(doc.file_name) != EOK)
 		new_file = true;
 
@@ -199,19 +166,12 @@
 	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);
-
 	/* Initial display */
-	cursor_visible = true;
-
-	cursor_hide();
 	console_clear(con);
 	pane_text_display();
 	pane_status_display();
-	if (new_file && doc.file_name != NULL)
-		status_display("File not found. Starting empty file.");
+	if (new_file)
+		status_display("File not found. Created empty file.");
 	pane_caret_display();
-	cursor_show();
+
 
 	done = false;
@@ -224,12 +184,7 @@
 			/* Handle key press. */
 			if (((ev.mods & KM_ALT) == 0) &&
-			    ((ev.mods & KM_SHIFT) == 0) &&
 			     (ev.mods & KM_CTRL) != 0) {
 				key_handle_ctrl(&ev);
-			} else if (((ev.mods & KM_ALT) == 0) &&
-			    ((ev.mods & KM_CTRL) == 0) &&
-			     (ev.mods & KM_SHIFT) != 0) {
-				key_handle_shift(&ev);
-			} else if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
+			} else if ((ev.mods & (KM_CTRL | KM_ALT)) == 0) {
 				key_handle_unmod(&ev);
 			}
@@ -237,6 +192,4 @@
 
 		/* Redraw as necessary. */
-
-		cursor_hide();
 
 		if (pane.rflags & REDRAW_TEXT)
@@ -248,6 +201,5 @@
 		if (pane.rflags & REDRAW_CARET)
 			pane_caret_display();
-
-		cursor_show();
+			
 	}
 
@@ -255,22 +207,4 @@
 
 	return 0;
-}
-
-static void cursor_show(void)
-{
-	cursor_setvis(true);
-}
-
-static void cursor_hide(void)
-{
-	cursor_setvis(false);
-}
-
-static void cursor_setvis(bool visible)
-{
-	if (cursor_visible != visible) {
-		console_cursor_visibility(con, visible);
-		cursor_visible = visible;
-	}
 }
 
@@ -280,35 +214,41 @@
 	switch (ev->key) {
 	case KC_ENTER:
-		selection_delete();
 		insert_char('\n');
 		caret_update();
 		break;
 	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:
-		key_handle_movement(ev->key, false);
+		caret_move(+pane.rows, 0, dir_before);
 		break;
 	case KC_BACKSPACE:
-		if (selection_active())
-			selection_delete();
-		else
-			delete_char_before();
+		delete_char_before();
 		caret_update();
 		break;
 	case KC_DELETE:
-		if (selection_active())
-			selection_delete();
-		else
-			delete_char_after();
+		delete_char_after();
 		caret_update();
 		break;
 	default:
 		if (ev->c >= 32 || ev->c == '\t') {
-			selection_delete();
 			insert_char(ev->c);
 			caret_update();
@@ -318,28 +258,4 @@
 }
 
-/** Handle Shift-key combination. */
-static void key_handle_shift(console_event_t const *ev)
-{
-	switch (ev->key) {
-	case KC_LEFT:
-	case KC_RIGHT:
-	case KC_UP:
-	case KC_DOWN:
-	case KC_HOME:
-	case KC_END:
-	case KC_PAGE_UP:
-	case KC_PAGE_DOWN:
-		key_handle_movement(ev->key, true);
-		break;
-	default:
-		if (ev->c >= 32 || ev->c == '\t') {
-			selection_delete();
-			insert_char(ev->c);
-			caret_update();
-		}
-		break;
-	}
-}
-
 /** Handle Ctrl-key combination. */
 static void key_handle_ctrl(console_event_t const *ev)
@@ -350,29 +266,5 @@
 		break;
 	case KC_S:
-		if (doc.file_name != NULL)
-			file_save(doc.file_name);
-		else
-			file_save_as();
-		break;
-	case KC_E:
-		file_save_as();
-		break;
-	case KC_C:
-		selection_copy();
-		break;
-	case KC_V:
-		selection_delete();
-		insert_clipboard_data();
-		pane.rflags |= REDRAW_TEXT;
-		caret_update();
-		break;
-	case KC_X:
-		selection_copy();
-		selection_delete();
-		pane.rflags |= REDRAW_TEXT;
-		caret_update();
-		break;
-	case KC_A:
-		selection_sel_all();
+		(void) file_save(doc.file_name);
 		break;
 	default:
@@ -381,67 +273,4 @@
 }
 
-static void key_handle_movement(unsigned int key, bool select)
-{
-	spt_t pt;
-	spt_t caret_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;
-	}
-
-	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);
-	}
-
-	if (select) {
-		tag_get_pt(&pane.caret_pos, &pt);
-		spt_get_coord(&caret_pt, &c_old);
-		spt_get_coord(&pt, &c_new);
-
-		if (c_old.row == c_new.row)
-			pane.rflags |= REDRAW_ROW;
-		else
-			pane.rflags |= REDRAW_TEXT;
-
-	} else if (had_sel == true) {
-		/* Redraw because text was unselected. */
-		pane.rflags |= REDRAW_TEXT;
-	}
-}
 
 /** Save the document. */
@@ -456,104 +285,7 @@
 
 	rc = file_save_range(fname, &sp, &ep);
-
-	switch (rc) {
-	case EINVAL:
-		status_display("Error opening file!");
-		break;
-	case EIO:
-		status_display("Error writing data!");
-		break;
-	default:
-		status_display("File saved.");
-		break;
-	}
+	status_display("File saved.");
 
 	return rc;
-}
-
-/** Change document name and save. */
-static void file_save_as(void)
-{
-	char *old_fname, *fname;
-	int rc;
-
-	old_fname = (doc.file_name != NULL) ? doc.file_name : "";
-	fname = filename_prompt("Save As", old_fname);
-	if (fname == NULL) {
-		status_display("Save cancelled.");
-		return;
-	}
-
-	rc = file_save(fname);
-	if (rc != EOK)
-		return;
-
-	if (doc.file_name != NULL)
-		free(doc.file_name);
-	doc.file_name = fname;
-}
-
-/** Ask for a file name. */
-static char *filename_prompt(char const *prompt, char const *init_value)
-{
-	console_event_t ev;
-	char *str;
-	wchar_t buffer[INFNAME_MAX_LEN + 1];
-	int max_len;
-	int nc;
-	bool done;
-
-	asprintf(&str, "%s: %s", prompt, init_value);
-	status_display(str);
-	console_goto(con, 1 + str_length(str), scr_rows - 1);
-	free(str);
-
-	console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
-
-	max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt));
-	str_to_wstr(buffer, max_len + 1, init_value);
-	nc = wstr_length(buffer);
-	done = false;
-
-	while (!done) {
-		console_get_event(con, &ev);
-
-		if (ev.type == KEY_PRESS) {
-			/* Handle key press. */
-			if (((ev.mods & KM_ALT) == 0) &&
-			     (ev.mods & KM_CTRL) != 0) {
-				;
-			} else if ((ev.mods & (KM_CTRL | KM_ALT)) == 0) {
-				switch (ev.key) {
-				case KC_ESCAPE:
-					return NULL;
-				case KC_BACKSPACE:
-					if (nc > 0) {
-						putchar('\b');
-						fflush(stdout);
-						--nc;
-					}
-					break;
-				case KC_ENTER:
-					done = true;
-					break;
-				default:
-					if (ev.c >= 32 && nc < max_len) {
-						putchar(ev.c);
-						fflush(stdout);
-						buffer[nc++] = ev.c;
-					}
-					break;
-				}
-			}
-		}
-	}
-
-	buffer[nc] = '\0';
-	str = wstr_to_astr(buffer);
-
-	console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
-
-	return str;
 }
 
@@ -627,44 +359,7 @@
 	} while (!spt_equal(&bep, epos));
 
-	if (fclose(f) != EOK)
-		return EIO;
+	fclose(f);
 
 	return EOK;
-}
-
-/** Return contents of range as a new string. */
-static char *range_get_str(spt_t const *spos, spt_t const *epos)
-{
-	char *buf;
-	spt_t sp, bep;
-	size_t bytes;
-	size_t buf_size, bpos;
-
-	buf_size = 1;
-
-	buf = malloc(buf_size);
-	if (buf == NULL)
-		return NULL;
-
-	bpos = 0;
-	sp = *spos;
-
-	while (true) {
-		sheet_copy_out(&doc.sh, &sp, epos, &buf[bpos], buf_size - bpos,
-		    &bep);
-		bytes = str_size(&buf[bpos]);
-		bpos += bytes;
-		sp = bep;
-
-		if (spt_equal(&bep, epos))
-			break;
-
-		buf_size *= 2;
-		buf = realloc(buf, buf_size);
-		if (buf == NULL)
-			return NULL;
-	}
-
-	return buf;
 }
 
@@ -713,5 +408,5 @@
 {
 	int i, j, fill;
-	spt_t rb, re, dep, pt;
+	spt_t rb, re, dep;
 	coord_t rbc, rec;
 	char row_buf[ROW_BUF_SIZE];
@@ -719,19 +414,4 @@
 	size_t pos, size;
 	unsigned s_column;
-	coord_t csel_start, csel_end, ctmp;
-
-	/* Determine selection start and end. */
-
-	tag_get_pt(&pane.sel_start, &pt);
-	spt_get_coord(&pt, &csel_start);
-
-	tag_get_pt(&pane.caret_pos, &pt);
-	spt_get_coord(&pt, &csel_end);
-
-	if (coord_cmp(&csel_start, &csel_end) > 0) {
-		ctmp = csel_start;
-		csel_start = csel_end;
-		csel_end = ctmp;
-	}
 
 	/* Draw rows from the sheet. */
@@ -754,28 +434,9 @@
 		/* Display text from the buffer. */
 
-		if (coord_cmp(&csel_start, &rbc) <= 0 &&
-		    coord_cmp(&rbc, &csel_end) < 0) {
-			fflush(stdout);
-			console_set_color(con, COLOR_BLACK, COLOR_RED, 0);
-			fflush(stdout);
-		}
-
 		console_goto(con, 0, i);
 		size = str_size(row_buf);
 		pos = 0;
-		s_column = pane.sh_column;
+		s_column = 1;
 		while (pos < size) {
-			if (csel_start.row == rbc.row && csel_start.column == s_column) {
-				fflush(stdout);
-				console_set_color(con, COLOR_BLACK, COLOR_RED, 0);
-				fflush(stdout);
-			}
-	
-			if (csel_end.row == rbc.row && csel_end.column == s_column) {
-				fflush(stdout);
-				console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
-				fflush(stdout);
-			}
-	
 			c = str_decode(row_buf, &pos, size);
 			if (c != '\t') {
@@ -792,10 +453,4 @@
 		}
 
-		if (csel_end.row == rbc.row && csel_end.column == s_column) {
-			fflush(stdout);
-			console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
-			fflush(stdout);
-		}
-
 		/* Fill until the end of display area. */
 
@@ -808,5 +463,4 @@
 			putchar(' ');
 		fflush(stdout);
-		console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
 	}
 
@@ -819,5 +473,4 @@
 	spt_t caret_pt;
 	coord_t coord;
-	char *fname;
 	int n;
 
@@ -825,10 +478,8 @@
 	spt_get_coord(&caret_pt, &coord);
 
-	fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>";
-
 	console_goto(con, 0, scr_rows - 1);
 	console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
-	n = printf(" %d, %d: File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
-	    "Ctrl-E Save As", coord.row, coord.column, fname);
+	n = printf(" %d, %d: File '%s'. Ctrl-S Save  Ctrl-Q Quit",
+	    coord.row, coord.column, doc.file_name);
 	printf("%*s", scr_columns - 1 - n, "");
 	fflush(stdout);
@@ -997,102 +648,4 @@
 }
 
-/** Check for non-empty selection. */
-static bool selection_active(void)
-{
-	return (tag_cmp(&pane.caret_pos, &pane.sel_start) != 0);
-}
-
-static void selection_get_points(spt_t *pa, spt_t *pb)
-{
-	spt_t pt;
-
-	tag_get_pt(&pane.sel_start, pa);
-	tag_get_pt(&pane.caret_pos, pb);
-
-	if (spt_cmp(pa, pb) > 0) {
-		pt = *pa;
-		*pa = *pb;
-		*pb = pt;
-	}
-}
-
-/** Delete selected text. */
-static void selection_delete(void)
-{
-	spt_t pa, pb;
-	coord_t ca, cb;
-	int rel;
-
-	tag_get_pt(&pane.sel_start, &pa);
-	tag_get_pt(&pane.caret_pos, &pb);
-	spt_get_coord(&pa, &ca);
-	spt_get_coord(&pb, &cb);
-	rel = coord_cmp(&ca, &cb);
-
-	if (rel == 0)
-		return;
-
-	if (rel < 0)
-		sheet_delete(&doc.sh, &pa, &pb);
-	else
-		sheet_delete(&doc.sh, &pb, &pa);
-
-	if (ca.row == cb.row)
-		pane.rflags |= REDRAW_ROW;
-	else
-		pane.rflags |= REDRAW_TEXT;
-}
-
-static void selection_sel_all(void)
-{
-	spt_t spt, ept;
-
-	pt_get_sof(&spt);
-	pt_get_eof(&ept);
-	sheet_remove_tag(&doc.sh, &pane.sel_start);
-	sheet_place_tag(&doc.sh, &spt, &pane.sel_start);
-	sheet_remove_tag(&doc.sh, &pane.caret_pos);
-	sheet_place_tag(&doc.sh, &ept, &pane.caret_pos);
-
-	pane.rflags |= REDRAW_TEXT;
-	caret_update();
-}
-
-static void selection_copy(void)
-{
-	spt_t pa, pb;
-	char *str;
-
-	selection_get_points(&pa, &pb);
-	str = range_get_str(&pa, &pb);
-	if (str == NULL || clipboard_put_str(str) != EOK) {
-		status_display("Copying to clipboard failed!");
-	}
-	free(str);
-}
-
-static void insert_clipboard_data(void)
-{
-	char *str;
-	size_t off;
-	wchar_t c;
-	int rc;
-
-	rc = clipboard_get_str(&str);
-	if (rc != EOK || str == NULL)
-		return;
-
-	off = 0;
-
-	while (true) {
-		c = str_decode(str, &off, STR_NO_LIMIT);
-		if (c == '\0')
-			break;
-
-		insert_char(c);
-	}
-
-	free(str);
-}
 
 /** Get start-of-file s-point. */
@@ -1116,35 +669,4 @@
 
 	sheet_get_cell_pt(&doc.sh, &coord, dir_after, pt);
-}
-
-/** Compare tags. */
-static int tag_cmp(tag_t const *a, tag_t const *b)
-{
-	spt_t pa, pb;
-
-	tag_get_pt(a, &pa);
-	tag_get_pt(b, &pb);
-
-	return spt_cmp(&pa, &pb);
-}
-
-/** Compare s-points. */
-static int spt_cmp(spt_t const *a, spt_t const *b)
-{
-	coord_t ca, cb;
-
-	spt_get_coord(a, &ca);
-	spt_get_coord(b, &cb);
-
-	return coord_cmp(&ca, &cb);
-}
-
-/** Compare coordinats. */
-static int coord_cmp(coord_t const *a, coord_t const *b)
-{
-	if (a->row - b->row != 0)
-		return a->row - b->row;
-
-	return a->column - b->column;
 }
 
