string	word_chars = "_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
string	space_chars = " \t";
string	unword_chars = "]-\"'\t.>=";

wr()
{	string	ch = trim(read(1));
	int	col;

	if (ch == "") {
		if (re_search(NULL, "?") <= 0) {
			beep();
			return;
			}
		ch = read(1);
		}
	else {
		inq_position(NULL, col);
		if (col == 1)
			next_char();
		}
	if (index(word_chars, ch)) {
		re_search(NULL, "^|[^" + word_chars + "]");
		re_search(NULL, "[^" + space_chars + "]");
		}
	else if (index(space_chars, ch))
		re_search(NULL, "^|[^" + space_chars + "]");
	else
		re_search(NULL, "^|[" + word_chars + space_chars + "]");
	if (index(space_chars, read(1)))
		re_search(NULL, "[^" + space_chars + "]");
}
wl()
{	string	ch0, ch1;
	string	other_char;
	int	line, col;
	int	class0, class1;
	
	inq_position(line, col);
	if (line == 1 && col == 1) {
		beep();
		return;
		}

	ch1 = read(1);
	prev_char();
	ch0 = read(1);
	if (index(word_chars, ch0))
		class0 = WORD_CHAR;
	else if (index(space_chars, ch0))
		class0 = SPACE_CHAR;
	else
		class0 = OTHER_CHAR;
	if (index(word_chars, ch1))
		class1 = WORD_CHAR;
	else if (index(space_chars, ch1))
		class1 = SPACE_CHAR;
	else
		class1 = OTHER_CHAR;
	if (class0 == class1 && class0 != SPACE_CHAR) {
		if (class0 == WORD_CHAR)
			re_search(SF_BACKWARDS, "[" + unword_char + "]");
		else
			re_search(SF_BACKWARDS, "[" + word_char + "]");
		}
	if (index(word_chars, ch)) {
		re_search(SF_BACKWARDS, "[^" + word_chars + "]");
		re_search(NULL, "[^" + space_chars + "]");
		}
	else if (index(space_chars, ch))
		re_search(NULL, "[^" + space_chars + "]");
	else
		re_search(NULL, "[" + word_chars + space_chars + "]");
	if (index(space_chars, read(1)))
		re_search(NULL, "[^" + space_chars + "]");
}
