Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement :wa[ll] command (write all) #671

Merged
merged 2 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/cmd_line/commands/wall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"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 : overwrite readonly files when bang? == true
await vscode.workspace.saveAll(false);
}
}
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c can be EOF right?

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);
}