Treat any amount of space and punctuation as word boundaries
This matches behaviour of, e.g. zsh -o emacs.weechat-hashes
parent
8dec54801c
commit
9c384de6db
22
edit.c
22
edit.c
|
@ -207,6 +207,10 @@ static void tabReject(void) {
|
||||||
tab.len = 0;
|
tab.len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isword(wchar_t ch) {
|
||||||
|
return !iswspace(ch) && !iswpunct(ch);
|
||||||
|
}
|
||||||
|
|
||||||
void edit(uint id, enum Edit op, wchar_t ch) {
|
void edit(uint id, enum Edit op, wchar_t ch) {
|
||||||
size_t init = pos;
|
size_t init = pos;
|
||||||
switch (op) {
|
switch (op) {
|
||||||
|
@ -215,12 +219,12 @@ void edit(uint id, enum Edit op, wchar_t ch) {
|
||||||
break; case EditPrev: if (pos) pos--;
|
break; case EditPrev: if (pos) pos--;
|
||||||
break; case EditNext: if (pos < len) pos++;
|
break; case EditNext: if (pos < len) pos++;
|
||||||
break; case EditPrevWord: {
|
break; case EditPrevWord: {
|
||||||
if (pos) pos--;
|
while (pos && !isword(buf[pos - 1])) pos--;
|
||||||
while (pos && !iswspace(buf[pos - 1])) pos--;
|
while (pos && isword(buf[pos - 1])) pos--;
|
||||||
}
|
}
|
||||||
break; case EditNextWord: {
|
break; case EditNextWord: {
|
||||||
if (pos < len) pos++;
|
while (pos < len && !isword(buf[pos])) pos++;
|
||||||
while (pos < len && !iswspace(buf[pos])) pos++;
|
while (pos < len && isword(buf[pos])) pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
break; case EditDeleteHead: delete(true, 0, pos); pos = 0;
|
break; case EditDeleteHead: delete(true, 0, pos); pos = 0;
|
||||||
|
@ -229,15 +233,17 @@ void edit(uint id, enum Edit op, wchar_t ch) {
|
||||||
break; case EditDeleteNext: delete(false, pos, 1);
|
break; case EditDeleteNext: delete(false, pos, 1);
|
||||||
break; case EditDeletePrevWord: {
|
break; case EditDeletePrevWord: {
|
||||||
if (!pos) break;
|
if (!pos) break;
|
||||||
size_t word = pos - 1;
|
size_t word = pos;
|
||||||
while (word && !iswspace(buf[word - 1])) word--;
|
while (word && !isword(buf[word - 1])) word--;
|
||||||
|
while (word && isword(buf[word - 1])) word--;
|
||||||
delete(true, word, pos - word);
|
delete(true, word, pos - word);
|
||||||
pos = word;
|
pos = word;
|
||||||
}
|
}
|
||||||
break; case EditDeleteNextWord: {
|
break; case EditDeleteNextWord: {
|
||||||
if (pos == len) break;
|
if (pos == len) break;
|
||||||
size_t word = pos + 1;
|
size_t word = pos;
|
||||||
while (word < len && !iswspace(buf[word])) word++;
|
while (word < len && !isword(buf[word])) word++;
|
||||||
|
while (word < len && isword(buf[word])) word++;
|
||||||
delete(true, pos, word - pos);
|
delete(true, pos, word - pos);
|
||||||
}
|
}
|
||||||
break; case EditPaste: {
|
break; case EditPaste: {
|
||||||
|
|
Loading…
Reference in New Issue