Skip to content

Commit

Permalink
Implement :wa[ll] command (write all)
Browse files Browse the repository at this point in the history
  • Loading branch information
mleech committed Aug 30, 2016
1 parent 1185bce commit 1e4c60d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/cmd_line/commands/wall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

import * as vscode from "vscode";
import * as node from "../node";

export interface IWallCommandArguments extends node.ICommandArgs {
bang?: boolean;
range?: node.LineRange;
}

//
// Implements :wall (write all)
// http://vimdoc.sourceforge.net/htmldoc/editing.html#:wall
//
export class WallCommand extends node.CommandBase {
protected _arguments : IWallCommandArguments;

constructor(args : IWallCommandArguments) {
super();

this._name = 'wall';
this._shortName = 'wa';
this._arguments = args;
}

get arguments() : IWallCommandArguments {
return this._arguments;
}

async execute() : Promise<void> {
// TODO : ignore untitled documents
// TODO : overwrite readonly files when bang? == true
await vscode.commands.executeCommand('workbench.action.files.saveAll');
}
}
4 changes: 4 additions & 0 deletions src/cmd_line/subparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import {parseQuitCommandArgs} from './subparsers/quit';
import {parseWriteCommandArgs} from './subparsers/write';
import {parseWallCommandArgs} from './subparsers/wall';
import {parseWriteQuitCommandArgs} from './subparsers/writequit';
import * as tabCmd from './subparsers/tab';
import * as fileCmd from './subparsers/file';
Expand All @@ -13,6 +14,9 @@ export const commandParsers = {
w: parseWriteCommandArgs,
write: parseWriteCommandArgs,

wa: parseWallCommandArgs,
wall: parseWallCommandArgs,

quit: parseQuitCommandArgs,
q: parseQuitCommandArgs,

Expand Down
25 changes: 25 additions & 0 deletions src/cmd_line/subparsers/wall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use strict";

import * as node from "../commands/wall";
import {Scanner} from '../scanner';
import {VimError, ErrorCode} from '../../error';

export function parseWallCommandArgs(args : string) : node.WallCommand {
if (!args) {
return new node.WallCommand({});
}
var scannedArgs : node.IWallCommandArguments = {};
var scanner = new Scanner(args);
const c = scanner.next();
if (c === '!') {
scannedArgs.bang = true;
scanner.ignore();
} else if (c !== ' ') {
throw VimError.fromCode(ErrorCode.E488);
}
scanner.skipWhiteSpace();
if (!scanner.isAtEof) {
throw VimError.fromCode(ErrorCode.E488);
}
return new node.WallCommand(scannedArgs);
}

0 comments on commit 1e4c60d

Please sign in to comment.