From ddffc314876d9f1821a801f67a2eae26b1e83a70 Mon Sep 17 00:00:00 2001 From: t9md Date: Thu, 5 Oct 2017 12:42:29 +0900 Subject: [PATCH 1/3] convert and fix to work it again --- CHANGELOG.md | 5 +++ coffeelint.json | 37 --------------------- lib/main.coffee | 61 ----------------------------------- lib/main.js | 41 +++++++++++++++++++++++ lib/replace-with-execution.js | 34 +++++++++++++++++++ 5 files changed, 80 insertions(+), 98 deletions(-) delete mode 100644 coffeelint.json delete mode 100644 lib/main.coffee create mode 100644 lib/main.js create mode 100644 lib/replace-with-execution.js diff --git a/CHANGELOG.md b/CHANGELOG.md index d030089..d056ec5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.2.0 +- Maintenance: + - Convert Coffee-to-JS + - Also make vmp commands compatible with upcoming ES6-class-based-vmp-operations. + ## 0.1.3 - Fix to catch-up upstream(vim-mode-plus) change. diff --git a/coffeelint.json b/coffeelint.json deleted file mode 100644 index 532ffd9..0000000 --- a/coffeelint.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "max_line_length": { - "level": "ignore" - }, - "no_empty_param_list": { - "level": "error" - }, - "arrow_spacing": { - "level": "error" - }, - "no_interpolation_in_single_quotes": { - "level": "error" - }, - "no_debugger": { - "level": "error" - }, - "prefer_english_operator": { - "level": "error" - }, - "colon_assignment_spacing": { - "spacing": { - "left": 0, - "right": 1 - }, - "level": "ignore" - }, - "braces_spacing": { - "spaces": 0, - "level": "error" - }, - "spacing_after_comma": { - "level": "error" - }, - "no_stand_alone_at": { - "level": "error" - } -} diff --git a/lib/main.coffee b/lib/main.coffee deleted file mode 100644 index 6d22316..0000000 --- a/lib/main.coffee +++ /dev/null @@ -1,61 +0,0 @@ -{CompositeDisposable} = require 'atom' -LineEndingRegExp = /(?:\n|\r\n)$/ - -settings = - registerToSelectList: - description: 'Register as member of transformers for TransformStringBySelectList at Atom startup' - type: 'boolean' - default: false - -module.exports = - config: settings - - activate: -> - @subscriptions = new CompositeDisposable - - deactivate: -> - @subscriptions?.dispose() - [@subscriptions] = [] - - subscribe: (args...) -> - @subscriptions.add args... - - consumeVim: ({Base}) -> - TransformStringByExternalCommand = Base.getClass('TransformStringByExternalCommand') - - class ReplaceWithExecution extends TransformStringByExternalCommand - @commandPrefix: 'vim-mode-plus-user' - - # Extract command to use from selected texxt - getCommand: (selection) -> - text = selection.getText() - return null unless text = text?.trim() - [command, args...] = text.split(/\s+/) - args = args.filter((arg) -> arg.length) - {command, args} - - getStdin: (selection) -> - null - - getNewText: (text, selection) -> - stdout = @getStdout(selection) - if LineEndingRegExp.test(text) - stdout - else - stdout.replace(LineEndingRegExp, '') - - class ReplaceWithExecutionKeepOriginalText extends ReplaceWithExecution - @commandPrefix: 'vim-mode-plus-user' - getNewText: (text, selection) -> - stdout = super - stdout = "\n" + stdout unless LineEndingRegExp.test(text) - text + stdout - - if settings.registerToSelectList - ReplaceWithExecution.registerToSelectList() - ReplaceWithExecutionKeepOriginalText.registerToSelectList - - @subscribe( - ReplaceWithExecution.registerCommand() - ReplaceWithExecutionKeepOriginalText.registerCommand() - ) diff --git a/lib/main.js b/lib/main.js new file mode 100644 index 0000000..1599462 --- /dev/null +++ b/lib/main.js @@ -0,0 +1,41 @@ +const {CompositeDisposable} = require("atom") + +module.exports = { + config: { + registerToSelectList: { + description: "Register as member of transformers for TransformStringBySelectList at Atom startup", + type: "boolean", + default: false, + }, + }, + + activate() { + this.subscriptions = new CompositeDisposable() + }, + + deactivate() { + this.subscriptions.dispose() + }, + + consumeVim({Base, registerCommandFromSpec}) { + let vimCommands + + const spec = { + commandPrefix: "vim-mode-plus-user", + getClass(name) { + if (!vimCommands) vimCommands = require("./replace-with-execution")(Base) + return vimCommands[name] + }, + } + + if (atom.config.get("vim-mode-plus-replace-with-execution.registerToSelectList ")) { + ReplaceWithExecution.registerToSelectList() + ReplaceWithExecutionKeepOriginalText.registerToSelectList + } + + this.subscriptions.add( + registerCommandFromSpec("ReplaceWithExecution", spec), + registerCommandFromSpec("ReplaceWithExecutionKeepOriginalText", spec) + ) + }, +} diff --git a/lib/replace-with-execution.js b/lib/replace-with-execution.js new file mode 100644 index 0000000..7327126 --- /dev/null +++ b/lib/replace-with-execution.js @@ -0,0 +1,34 @@ +const LineEndingRegExp = /(?:\n|\r\n)$/ + +module.exports = function loadVmpCommands(Base) { + const TransformStringByExternalCommand = Base.getClass("TransformStringByExternalCommand") + + class ReplaceWithExecution extends TransformStringByExternalCommand { + // Extract command to use from selected texxt + getCommand(selection) { + const text = selection.getText().trim() + if (text) { + const [command, ...args] = text.split(/\s+/) + return {command, args: args.filter(arg => arg)} + } + } + + getStdin(selection) { + return null + } + + getNewText(text, selection) { + const newText = super.getNewText(text, selection) + return LineEndingRegExp.test(text) ? newText : newText.replace(LineEndingRegExp, "") + } + } + + class ReplaceWithExecutionKeepOriginalText extends ReplaceWithExecution { + getNewText(text, selection) { + const newText = super.getNewText(text, selection) + return text + (LineEndingRegExp.test(text) ? newText : "\n" + newText) + } + } + + return {ReplaceWithExecution, ReplaceWithExecutionKeepOriginalText} +} From 6e5579dc46f9f51991982922ee979f35d5127d69 Mon Sep 17 00:00:00 2001 From: t9md Date: Thu, 5 Oct 2017 13:01:22 +0900 Subject: [PATCH 2/3] continuation of #1, fix minor bug and eager load to registerToSelectList() --- lib/main.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1599462..1c21d54 100644 --- a/lib/main.js +++ b/lib/main.js @@ -18,19 +18,18 @@ module.exports = { }, consumeVim({Base, registerCommandFromSpec}) { - let vimCommands - + const vimCommands = require("./replace-with-execution")(Base) const spec = { commandPrefix: "vim-mode-plus-user", getClass(name) { - if (!vimCommands) vimCommands = require("./replace-with-execution")(Base) return vimCommands[name] }, } - if (atom.config.get("vim-mode-plus-replace-with-execution.registerToSelectList ")) { - ReplaceWithExecution.registerToSelectList() - ReplaceWithExecutionKeepOriginalText.registerToSelectList + if (atom.config.get("vim-mode-plus-replace-with-execution.registerToSelectList")) { + for (const name in vimCommands) { + vimCommands[name].registerToSelectList() + } } this.subscriptions.add( From 872757939bbc0e9c8df0fd6d19c3d0627536711e Mon Sep 17 00:00:00 2001 From: t9md Date: Thu, 5 Oct 2017 13:10:13 +0900 Subject: [PATCH 3/3] consolidate to main since its not lazy-loaded anyway --- lib/main.js | 45 ++++++++++++++++++++++++++++------- lib/replace-with-execution.js | 34 -------------------------- 2 files changed, 37 insertions(+), 42 deletions(-) delete mode 100644 lib/replace-with-execution.js diff --git a/lib/main.js b/lib/main.js index 1c21d54..53ac100 100644 --- a/lib/main.js +++ b/lib/main.js @@ -18,7 +18,7 @@ module.exports = { }, consumeVim({Base, registerCommandFromSpec}) { - const vimCommands = require("./replace-with-execution")(Base) + const vimCommands = loadVmpCommands(Base) const spec = { commandPrefix: "vim-mode-plus-user", getClass(name) { @@ -26,15 +26,44 @@ module.exports = { }, } - if (atom.config.get("vim-mode-plus-replace-with-execution.registerToSelectList")) { - for (const name in vimCommands) { + for (const name in vimCommands) { + if (atom.config.get("vim-mode-plus-replace-with-execution.registerToSelectList")) { vimCommands[name].registerToSelectList() } + this.subscriptions.add(registerCommandFromSpec(name, spec)) } - - this.subscriptions.add( - registerCommandFromSpec("ReplaceWithExecution", spec), - registerCommandFromSpec("ReplaceWithExecutionKeepOriginalText", spec) - ) }, } + +function loadVmpCommands(Base) { + const LineEndingRegExp = /(?:\n|\r\n)$/ + const TransformStringByExternalCommand = Base.getClass("TransformStringByExternalCommand") + + class ReplaceWithExecution extends TransformStringByExternalCommand { + getCommand(selection) { + const text = selection.getText().trim() + if (text) { + const [command, ...args] = text.split(/\s+/) + return {command, args: args.filter(arg => arg)} + } + } + + getStdin(selection) { + return null + } + + getNewText(text, selection) { + const newText = super.getNewText(text, selection) + return LineEndingRegExp.test(text) ? newText : newText.replace(LineEndingRegExp, "") + } + } + + class ReplaceWithExecutionKeepOriginalText extends ReplaceWithExecution { + getNewText(text, selection) { + const newText = super.getNewText(text, selection) + return text + (LineEndingRegExp.test(text) ? newText : "\n" + newText) + } + } + + return {ReplaceWithExecution, ReplaceWithExecutionKeepOriginalText} +} diff --git a/lib/replace-with-execution.js b/lib/replace-with-execution.js deleted file mode 100644 index 7327126..0000000 --- a/lib/replace-with-execution.js +++ /dev/null @@ -1,34 +0,0 @@ -const LineEndingRegExp = /(?:\n|\r\n)$/ - -module.exports = function loadVmpCommands(Base) { - const TransformStringByExternalCommand = Base.getClass("TransformStringByExternalCommand") - - class ReplaceWithExecution extends TransformStringByExternalCommand { - // Extract command to use from selected texxt - getCommand(selection) { - const text = selection.getText().trim() - if (text) { - const [command, ...args] = text.split(/\s+/) - return {command, args: args.filter(arg => arg)} - } - } - - getStdin(selection) { - return null - } - - getNewText(text, selection) { - const newText = super.getNewText(text, selection) - return LineEndingRegExp.test(text) ? newText : newText.replace(LineEndingRegExp, "") - } - } - - class ReplaceWithExecutionKeepOriginalText extends ReplaceWithExecution { - getNewText(text, selection) { - const newText = super.getNewText(text, selection) - return text + (LineEndingRegExp.test(text) ? newText : "\n" + newText) - } - } - - return {ReplaceWithExecution, ReplaceWithExecutionKeepOriginalText} -}