Commit 2d551de0 authored by hjk's avatar hjk

fakevim: make recognition of ex command names similar to vi's

parent e7e0ead0
......@@ -302,6 +302,11 @@ ExCommand::ExCommand(const QString &c, const QString &a, const Range &r)
: cmd(c), hasBang(false), args(a), range(r), count(1)
{}
bool ExCommand::matches(const QString &min, const QString &full) const
{
return cmd.startsWith(min) && full.startsWith(cmd);
}
QDebug operator<<(QDebug ts, const ExCommand &cmd)
{
return ts << cmd.cmd << ' ' << cmd.args << ' ' << cmd.range;
......@@ -3133,8 +3138,8 @@ bool FakeVimHandler::Private::handleExMapCommand(const ExCommand &cmd0) // :map
bool FakeVimHandler::Private::handleExHistoryCommand(const ExCommand &cmd)
{
// :history
if (cmd.cmd != "his" && cmd.cmd != "history")
// :his[tory]
if (!cmd.matches("his", "history"))
return false;
if (cmd.args.isEmpty()) {
......@@ -3155,9 +3160,8 @@ bool FakeVimHandler::Private::handleExHistoryCommand(const ExCommand &cmd)
bool FakeVimHandler::Private::handleExRegisterCommand(const ExCommand &cmd)
{
// :reg and :di[splay]
if (cmd.cmd != "reg" && cmd.cmd != "registers"
&& cmd.cmd != "di" && cmd.cmd != "display")
// :reg[isters] and :di[splay]
if (!cmd.matches("reg", "registers") && !cmd.matches("di", "display"))
return false;
QByteArray regs = cmd.args.toLatin1();
......@@ -3183,8 +3187,8 @@ bool FakeVimHandler::Private::handleExRegisterCommand(const ExCommand &cmd)
bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
{
// :set
if (cmd.cmd != "se" && cmd.cmd != "set")
// :se[t]
if (!cmd.matches("se", "set"))
return false;
showBlackMessage(QString());
......@@ -3224,8 +3228,8 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
bool FakeVimHandler::Private::handleExNormalCommand(const ExCommand &cmd)
{
// :normal
if (cmd.cmd != "norm" && cmd.cmd != "normal")
// :norm[al]
if (!cmd.matches("norm", "normal"))
return false;
//qDebug() << "REPLAY NORMAL: " << quoteUnprintable(reNormal.cap(3));
replay(cmd.args, 1);
......@@ -3234,8 +3238,8 @@ bool FakeVimHandler::Private::handleExNormalCommand(const ExCommand &cmd)
bool FakeVimHandler::Private::handleExDeleteCommand(const ExCommand &cmd)
{
// :delete
if (cmd.cmd != "d" && cmd.cmd != "delete")
// :d[elete]
if (!cmd.matches("d", "delete"))
return false;
setCurrentRange(cmd.range);
......@@ -3314,8 +3318,8 @@ bool FakeVimHandler::Private::handleExWriteCommand(const ExCommand &cmd)
bool FakeVimHandler::Private::handleExReadCommand(const ExCommand &cmd)
{
// :read
if (cmd.cmd != "r" && cmd.cmd != "read")
// :r[ead]
if (!cmd.matches("r", "read"))
return false;
beginEditBlock();
......
......@@ -64,6 +64,8 @@ struct ExCommand
ExCommand(const QString &cmd, const QString &args = QString(),
const Range &range = Range());
bool matches(const QString &min, const QString &full) const;
QString cmd;
bool hasBang;
QString args;
......
......@@ -910,7 +910,8 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
QTC_ASSERT(editorManager(), return);
*handled = true;
if (cmd.cmd == "w" || cmd.cmd == "write") {
if (cmd.matches("w", "write")) {
// :w[rite]
Core::IEditor *editor = m_editorToHandler.key(handler);
const QString fileName = handler->currentFileName();
if (editor && editor->file()->fileName() == fileName) {
......@@ -929,8 +930,8 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
} else {
handler->showRedMessage(tr("File not saved"));
}
} else if (cmd.cmd == "wa" || cmd.cmd == "wall") {
// :wa
} else if (cmd.matches("wa", "wall")) {
// :w[all]
FileManager *fm = ICore::instance()->fileManager();
QList<IFile *> toSave = fm->modifiedFiles();
QList<IFile *> failed = fm->saveModifiedFilesSilently(toSave);
......@@ -938,24 +939,24 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
handler->showBlackMessage(tr("Saving succeeded"));
else
handler->showRedMessage(tr("%n files not saved", 0, failed.size()));
} else if (cmd.cmd == "q" || cmd.cmd == "quit") {
} else if (cmd.matches("q", "quit")) {
// :q[uit]
emit delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
} else if (cmd.cmd == "qa" || cmd.cmd == "qall") {
// :qa
} else if (cmd.matches("qa", "qall")) {
// :qa[ll]
emit delayedQuitAllRequested(cmd.hasBang);
} else if (cmd.cmd == "sp" || cmd.cmd == "split") {
} else if (cmd.matches("sp", "split")) {
// :sp[lit]
triggerAction(Core::Constants::SPLIT);
} else if (cmd.cmd == "vs" || cmd.cmd == "vsplit") {
} else if (cmd.matches("vs", "vsplit")) {
// :vs[plit]
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
} else if (cmd.cmd == "mak" || cmd.cmd == "make") {
} else if (cmd.matches("mak", "make")) {
// :mak[e][!] [arguments]
triggerAction(ProjectExplorer::Constants::BUILD);
} else if (cmd.cmd == "se" || cmd.cmd == "set") {
} else if (cmd.matches("se", "set")) {
if (cmd.args.isEmpty()) {
// :set
// :se[t]
showSettingsDialog();
} else if (cmd.args == "ic" || cmd.args == "ignorecase") {
// :set noic
......@@ -966,21 +967,20 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
setActionChecked(Find::Constants::CASE_SENSITIVE, true);
*handled = false; // Let the handler see it as well.
}
} else if (cmd.cmd == "n" || cmd.cmd == "next") {
} else if (cmd.matches("n", "next")) {
// :n[ext]
switchToFile(currentFile() + cmd.count);
} else if (cmd.cmd == "prev" || cmd.cmd == "previous"
|| cmd.cmd == "N" || cmd.cmd == "Next") {
// :prev[ious]
} else if (cmd.matches("prev", "previous") || cmd.matches("N", "Next")) {
// :prev[ious], :N[ext]
switchToFile(currentFile() - cmd.count);
} else if (cmd.cmd == "bn" || cmd.cmd == "bnext") {
} else if (cmd.matches("bn", "bnext")) {
// :bn[ext]
switchToFile(currentFile() + cmd.count);
} else if (cmd.cmd == "bp" || cmd.cmd == "bprevious"
|| cmd.cmd == "bN" || cmd.cmd == "bNext") {
// :bp[revious]
} else if (cmd.matches("bp", "bprevious") || cmd.matches("bN", "bNext")) {
// :bp[revious], :bN[ext]
switchToFile(currentFile() - cmd.count);
} else if (cmd.cmd == "on" || cmd.cmd == "only") {
} else if (cmd.matches("on", "only")) {
// :on[ly]
//triggerAction(Core::Constants::REMOVE_ALL_SPLITS);
triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT);
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment