-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
WriteQuit #354
WriteQuit #354
Changes from all commits
8cfe6a1
21ad786
0077b86
18205f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use strict"; | ||
|
||
import * as vscode from "vscode"; | ||
import * as node from "../node"; | ||
import * as error from "../../error"; | ||
import {ModeHandler} from "../../mode/modeHandler"; | ||
|
||
// | ||
// Implements :writequit | ||
// http://vimdoc.sourceforge.net/htmldoc/editing.html#write-quit | ||
// | ||
export interface IWriteQuitCommandArguments extends node.ICommandArgs { | ||
// arguments | ||
// [++opt] | ||
opt? : string; | ||
optValue? : string; | ||
// wq! [++opt] | ||
bang? : boolean; | ||
// wq [++opt] {file} | ||
file? : string; | ||
// wq! [++opt] {file} | ||
// [range]wq[!] [++opt] [file] | ||
range?: node.LineRange; | ||
} | ||
|
||
export class WriteQuitCommand extends node.CommandBase { | ||
protected _arguments : IWriteQuitCommandArguments; | ||
|
||
constructor(args : IWriteQuitCommandArguments) { | ||
super(); | ||
this._name = "writequit"; | ||
this._shortName = "wq"; | ||
this._arguments = args; | ||
} | ||
|
||
get arguments() : IWriteQuitCommandArguments { | ||
return this._arguments; | ||
} | ||
|
||
// Writing command. Taken as a basis from the "write.ts" file. | ||
execute(modeHandler : ModeHandler) : void { | ||
var filename : RegExp = new RegExp("Untitled-[0-9]*"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this approach is tightly coupled to how VSCode names untitled documents - if they ever change, then saving will break. Is there any other way to check this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll take a look There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was one of the ways I found right through the API. I don't know where else I could get it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also it’s how we use it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh, if there's really no other way, we can just merge it. It's not that bad. |
||
if (!this.activeTextEditor.document.isDirty) { | ||
if (filename.test(this.activeTextEditor.document.fileName)) { | ||
vscode.commands.executeCommand("workbench.action.files.saveAs"); | ||
} else { | ||
vscode.commands.executeCommand("workbench.action.files.save"); | ||
} | ||
vscode.commands.executeCommand('workbench.action.closeActiveEditor'); | ||
} else { | ||
throw error.VimError.fromCode(error.ErrorCode.E208); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"use strict"; | ||
|
||
import {WriteQuitCommand, IWriteQuitCommandArguments} from '../commands/writequit'; | ||
import {Scanner} from '../scanner'; | ||
|
||
export function parseWriteQuitCommandArgs(args : string) : WriteQuitCommand { | ||
if (!args) { | ||
return new WriteQuitCommand({}); | ||
} | ||
var scannedArgs : IWriteQuitCommandArguments = {}; | ||
var scanner = new Scanner(args); | ||
while (true) { | ||
scanner.skipWhiteSpace(); | ||
if (scanner.isAtEof) { | ||
break; | ||
} | ||
let c = scanner.next(); | ||
switch (c) { | ||
case '!': | ||
// :writequit! | ||
scannedArgs.bang = true; | ||
scanner.ignore(); | ||
continue; | ||
case '+': | ||
// :writequit ++opt=value | ||
scanner.expect('+'); | ||
scanner.ignore(); | ||
scanner.expectOneOf(['bin', 'nobin', 'ff', 'enc']); | ||
scannedArgs.opt = scanner.emit(); | ||
scanner.expect('='); | ||
scanner.ignore(); | ||
while (!scanner.isAtEof) { | ||
let c = scanner.next(); | ||
if (c !== ' ' || c !== '\t') { | ||
continue; | ||
} | ||
scanner.backup(); | ||
continue; | ||
} | ||
let value = scanner.emit(); | ||
if (!value) { | ||
throw new Error("Expected value for option."); | ||
} | ||
scannedArgs.optValue = value; | ||
continue; | ||
default: | ||
throw new Error("Not implemented"); | ||
} | ||
} | ||
// TODO: parse the stuff (it's really not). | ||
// ++bin ++nobin ++ff ++enc =VALUE | ||
return new WriteQuitCommand(scannedArgs); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from lines 69, 77, this is the same as what's in
write.ts
. Any way we can just call that function instead? Maybe we can change theexecute
signature to abool
to indicate a success and if the write access was successful, go on and do the quit side of things?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we can't just use
vscode.commands.executeCommand("workbench.action.files.save")
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this to save the file or to save a new file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Save. Maybe there's another one for save as?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
workbench.action.files.saveAs
command.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could that then be used to save the file as a specific name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this command is triggered, a pop up window will show up for user to type file name and location, so we don't need to pass file name to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can try it by adding below binding to your keybinding configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome thanks man. I'll take a look tomorrow. Actually just installing Manjaro on my desktop on a different hard drive tonight. Giving i3wm a shot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍