protected boolean endOfLine() { while (count-- > 0) { while (buf.move(1) == 1 && buf.currChar() != '\n') ; } return true; }
protected boolean upCaseWord() { int count = Math.abs(this.count); int cursor = buf.cursor(); while (count-- > 0) { while (buf.cursor() < buf.length() && !isWord(buf.currChar())) { buf.move(1); } while (buf.cursor() < buf.length() && isWord(buf.currChar())) { buf.currChar(Character.toUpperCase(buf.currChar())); buf.move(1); } } if (this.count < 0) { buf.cursor(cursor); } return true; }
protected boolean downCaseWord() { int count = Math.abs(this.count); int cursor = buf.cursor(); while (count-- > 0) { while (buf.cursor() < buf.length() && !isWord(buf.currChar())) { buf.move(1); } while (buf.cursor() < buf.length() && isWord(buf.currChar())) { buf.currChar(Character.toLowerCase(buf.currChar())); buf.move(1); } } if (this.count < 0) { buf.cursor(cursor); } return true; }
/** * Implements the vi change character command (in move-mode "r" * followed by the character to change to). * @return <code>true</code> if it succeeded, <code>false</code> otherwise */ protected boolean viReplaceChars() { int c = readCharacter(); // EOF, ESC, or CTRL-C aborts. if (c < 0 || c == '\033' || c == '\003') { return true; } for (int i = 0; i < count; i++) { if (buf.currChar((char) c)) { if (i < count - 1) { buf.move(1); } } else { return false; } } return true; }
protected boolean capitalizeWord() { int count = Math.abs(this.count); int cursor = buf.cursor(); while (count-- > 0) { boolean first = true; while (buf.cursor() < buf.length() && !isWord(buf.currChar())) { buf.move(1); } while (buf.cursor() < buf.length() && isWord(buf.currChar()) && !isAlpha(buf.currChar())) { buf.move(1); } while (buf.cursor() < buf.length() && isWord(buf.currChar())) { buf.currChar(first ? Character.toUpperCase(buf.currChar()) : Character.toLowerCase(buf.currChar())); buf.move(1); first = false; } } if (this.count < 0) { buf.cursor(cursor); } return true; }
protected boolean viOpenLineBelow() { while (buf.move(1) == 1 && buf.currChar() != '\n') ; buf.write('\n'); return setKeyMap(VIINS); }
protected boolean viForwardBlankWord() { if (count < 0) { return callNeg(this::viBackwardBlankWord); } while (count-- > 0) { while (buf.cursor() < buf.length() && !isWhitespace(buf.currChar())) { buf.move(1); } if (isInViChangeOperation() && count == 0) { return true; } int nl = buf.currChar() == '\n' ? 1 : 0; while (buf.cursor() < buf.length() && nl < 2 && isWhitespace(buf.currChar())) { buf.move(1); nl += buf.currChar() == '\n' ? 1 : 0; } } return true; }
protected boolean viBackwardWordEnd() { if (count < 0) { return callNeg(this::viForwardWordEnd); } while (count-- > 0 && buf.cursor() > 1) { int start; if (isViAlphaNum(buf.currChar())) { start = 1; } else if (!isWhitespace(buf.currChar())) { start = 2; } else { start = 0; } while (buf.cursor() > 0) { boolean same = (start != 1) && isWhitespace(buf.currChar()); if (start != 0) { same |= isViAlphaNum(buf.currChar()); } if (same == (start == 2)) { break; } buf.move(-1); } while (buf.cursor() > 0 && isWhitespace(buf.currChar())) { buf.move(-1); } } return true; }
protected boolean viForwardWord() { if (count < 0) { return callNeg(this::backwardWord); } while (count-- > 0) { if (isViAlphaNum(buf.currChar())) { while (buf.cursor() < buf.length() && isViAlphaNum(buf.currChar())) { buf.move(1); } } else { while (buf.cursor() < buf.length() && !isViAlphaNum(buf.currChar()) && !isWhitespace(buf.currChar())) { buf.move(1); } } if (isInViChangeOperation() && count == 0) { return true; } int nl = buf.currChar() == '\n' ? 1 : 0; while (buf.cursor() < buf.length() && nl < 2 && isWhitespace(buf.currChar())) { buf.move(1); nl += buf.currChar() == '\n' ? 1 : 0; } } return true; }
protected boolean viBackwardBlankWord() { if (count < 0) { return callNeg(this::viForwardBlankWord); } while (count-- > 0) { while (buf.cursor() > 0) { buf.move(-1); if (!isWhitespace(buf.currChar())) { break; } } while (buf.cursor() > 0) { buf.move(-1); if (isWhitespace(buf.currChar())) { break; } } } return true; }
protected boolean emacsBackwardWord() { if (count < 0) { return callNeg(this::emacsForwardWord); } while (count-- > 0) { while (buf.cursor() > 0) { buf.move(-1); if (isWord(buf.currChar())) { break; } } while (buf.cursor() > 0) { buf.move(-1); if (!isWord(buf.currChar())) { break; } } } return true; }
protected boolean viFirstNonBlank() { beginningOfLine(); while (buf.cursor() < buf.length() && isWhitespace(buf.currChar())) { buf.move(1); } return true; }
protected boolean emacsForwardWord() { if (count < 0) { return callNeg(this::emacsBackwardWord); } while (count-- > 0) { while (buf.cursor() < buf.length() && !isWord(buf.currChar())) { buf.move(1); } if (isInViChangeOperation() && count == 0) { return true; } while (buf.cursor() < buf.length() && isWord(buf.currChar())) { buf.move(1); } } return true; }
protected boolean viForwardBlankWordEnd() { if (count < 0) { return false; } while (count-- > 0) { while (buf.cursor() < buf.length()) { buf.move(1); if (!isWhitespace(buf.currChar())) { break; } } while (buf.cursor() < buf.length()) { buf.move(1); if (isWhitespace(buf.currChar())) { break; } } } return true; }
protected boolean forwardWord() { if (count < 0) { return callNeg(this::backwardWord); } while (count-- > 0) { while (buf.cursor() < buf.length() && isWord(buf.currChar())) { buf.move(1); } if (isInViChangeOperation() && count == 0) { break; } while (buf.cursor() < buf.length() && !isWord(buf.currChar())) { buf.move(1); } } return true; }
/** * Pasts the yank buffer to the right of the current cursor position * and moves the cursor to the end of the pasted region. * @return <code>true</code> */ protected boolean viPutAfter() { if (yankBuffer.indexOf('\n') >= 0) { while (buf.move(1) == 1 && buf.currChar() != '\n'); buf.move(1); putString(yankBuffer); buf.move(- yankBuffer.length()); } else if (yankBuffer.length () != 0) { if (buf.cursor() < buf.length()) { buf.move(1); } for (int i = 0; i < count; i++) { putString(yankBuffer); } buf.move(-1); } 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; }
protected boolean viBackwardChar() { if (count < 0) { return callNeg(this::viForwardChar); } int lim = findbol(); if (buf.cursor() == lim) { return false; } while (count-- > 0 && buf.cursor() > 0) { buf.move(-1); if (buf.currChar() == '\n') { buf.move(1); break; } } return true; }