private int findbol() { int x = buf.cursor(); while (x > 0 && buf.atChar(x - 1) != '\n') { x--; } return x; }
private int findeol() { int x = buf.cursor(); while (x < buf.length() && buf.atChar(x) != '\n') { x++; } return x; }
protected boolean copyPrevWord() { if (count <= 0) { return false; } int t1, t0 = buf.cursor(); while (true) { t1 = t0; while (t0 > 0 && !isWord(buf.atChar(t0 - 1))) { t0--; } while (t0 > 0 && isWord(buf.atChar(t0 - 1))) { t0--; } if (--count == 0) { break; } if (t0 == 0) { return false; } } buf.write(buf.substring(t0, t1)); return true; }
protected boolean backwardDeleteWord() { if (count < 0) { return callNeg(this::deleteWord); } int cursor = buf.cursor(); while (count-- > 0) { while (cursor > 0 && !isWord(buf.atChar(cursor - 1))) { cursor--; } while (cursor > 0 && isWord(buf.atChar(cursor - 1))) { cursor--; } } buf.backspace(buf.cursor() - cursor); return true; }
protected boolean viBackwardKillWord() { if (count < 0) { return false; } int lim = findbol(); int x = buf.cursor(); while (count-- > 0) { while (x > lim && isWhitespace(buf.atChar(x - 1))) { x--; } if (x > lim) { if (isViAlphaNum(buf.atChar(x - 1))) { while (x > lim && isViAlphaNum(buf.atChar(x - 1))) { x--; } } else { while (x > lim && !isViAlphaNum(buf.atChar(x - 1)) && !isWhitespace(buf.atChar(x - 1))) { x--; } } } } killRing.addBackwards(buf.substring(x, buf.cursor())); buf.backspace(buf.cursor() - x); return true; }
public boolean backwardKillLine() { if (count < 0) { return callNeg(this::killLine); } if (buf.cursor() == 0) { return false; } int cp = buf.cursor(); int beg = cp; while (count-- > 0) { if (beg == 0) { break; } if (buf.atChar(beg - 1) == '\n') { beg--; } else { while (beg > 0 && buf.atChar(beg - 1) != 0 && buf.atChar(beg - 1) != '\n') { beg--; } } } int num = cp - beg; String killed = buf.substring(cp - beg, cp); buf.cursor(beg); buf.delete(num); killRing.add(killed); return true; }
/** * Kill the buffer ahead of the current cursor position. * * @return true if successful */ public boolean killLine() { if (count < 0) { return callNeg(this::backwardKillLine); } if (buf.cursor() == buf.length()) { return false; } int cp = buf.cursor(); int len = cp; while (count-- > 0) { if (buf.atChar(len) == '\n') { len++; } else { while (buf.atChar(len) != 0 && buf.atChar(len) != '\n') { len++; } } } int num = len - cp; String killed = buf.substring(cp, cp + num); buf.delete(num); killRing.add(killed); return true; }
protected boolean transposeWords() { int lstart = buf.cursor() - 1; int lend = buf.cursor(); while (buf.atChar(lstart) != 0 && buf.atChar(lstart) != '\n') { lstart--; while (buf.atChar(lend) != 0 && buf.atChar(lend) != '\n') { lend++; if (!isDelimiter(buf.atChar(lstart))) { words++; inWord = true; if (isDelimiter(buf.atChar(i))) { inWord = false; } else { while (sta1 > lstart && !isDelimiter(buf.atChar(sta1 - 1))) { sta1--; while (end1 < lend && !isDelimiter(buf.atChar(++end1))); if (neg) { end2 = sta1 - 1; while (end2 > lstart && isDelimiter(buf.atChar(end2 - 1))) { end2--; while (isDelimiter(buf.atChar(++sta2))); end2 = sta2; while (end2 < lend && !isDelimiter(buf.atChar(++end2))); } else {
protected boolean deleteWord() { if (count < 0) { return callNeg(this::backwardDeleteWord); } int x = buf.cursor(); while (count-- > 0) { while (x < buf.length() && !isWord(buf.atChar(x))) { x++; } while (x < buf.length() && isWord(buf.atChar(x))) { x++; } } buf.delete(x - buf.cursor()); return true; }
protected boolean backwardKillWord() { if (count < 0) { return callNeg(this::killWord); } int x = buf.cursor(); while (count-- > 0) { while (x > 0 && !isWord(buf.atChar(x - 1))) { x--; } while (x > 0 && isWord(buf.atChar(x - 1))) { x--; } } killRing.addBackwards(buf.substring(x, buf.cursor())); buf.backspace(buf.cursor() - x); return true; }
protected boolean killWord() { if (count < 0) { return callNeg(this::backwardKillWord); } int x = buf.cursor(); while (count-- > 0) { while (x < buf.length() && !isWord(buf.atChar(x))) { x++; } while (x < buf.length() && isWord(buf.atChar(x))) { x++; } } killRing.add(buf.substring(buf.cursor(), x)); buf.delete(x - buf.cursor()); return true; }
/** * Switches the case of the current character from upper to lower * or lower to upper as necessary and advances the cursor one * position to the right. * @return <code>true</code> if it succeeded, <code>false</code> otherwise */ protected boolean viSwapCase() { for (int i = 0; i < count; i++) { if (buf.cursor() < buf.length()) { int ch = buf.atChar(buf.cursor()); ch = switchCase(ch); buf.currChar(ch); buf.move(1); } else { return false; } } return true; }
int end = buf.cursor(); if (start < end) { while (start > 0 && buf.atChar(start - 1) != '\n') { start--; while (end < buf.length() - 1 && buf.atChar(end + 1) != '\n') { end++; while (end > 0 && buf.atChar(end - 1) != '\n') { end--; while (start < buf.length() && buf.atChar(start) != '\n') { start++;