diff --git a/keymaps/macro-keymap.cson b/keymaps/macro-keymap.cson index 021ffa8..ad0459c 100644 --- a/keymaps/macro-keymap.cson +++ b/keymaps/macro-keymap.cson @@ -1,6 +1,9 @@ 'atom-text-editor.vim-mode-plus.normal-mode': 'q': 'vim-mode-plus-macros:start-recording-macro' '@': 'vim-mode-plus-macros:apply-macro' + 'Q': 'vim-mode-plus-macros:append-to-macro' + 'g Q': 'vim-mode-plus-macros:apply-and-append-to-macro' + 'g @': 'vim-mode-plus-macros:put-macro-commands-as-text'; 'atom-text-editor.vim-mode-plus.normal-mode.recording-macro': 'q': 'vim-mode-plus-macros:stop-recording-macro' diff --git a/lib/vim-mode-plus-macros.js b/lib/vim-mode-plus-macros.js index c2be259..f330819 100644 --- a/lib/vim-mode-plus-macros.js +++ b/lib/vim-mode-plus-macros.js @@ -31,10 +31,13 @@ export default { this.subscriptions.add(atom.commands.add('atom-workspace', Object.assign(characterCommands, { 'vim-mode-plus-macros:start-recording-macro': () => this.startRecordingMacro(), 'vim-mode-plus-macros:stop-recording-macro': () => this.stopRecordingMacro(), - 'vim-mode-plus-macros:apply-macro': () => this.applyMacro() + 'vim-mode-plus-macros:apply-macro': () => this.applyMacro(), + 'vim-mode-plus-macros:append-to-macro': () => this.appendToMacro(), + 'vim-mode-plus-macros:apply-and-append-to-macro': () => this.applyAndAppendToMacro(), + 'vim-mode-plus-macros:put-macro-commands-as-text': () => this.putMacroCommandsAsText() }))) - atom.commands.onDidDispatch(this.logCommand) + atom.commands.onDidDispatch(this.logCommand); }, deactivate() { @@ -46,7 +49,7 @@ export default { editor.classList.add('recording-macro') commandQueue = [] // empty the queue recording = true - atom.notifications.addInfo('Recording macro') + atom.notifications.addInfo('Recording macro...') }, stopRecordingMacro() { @@ -56,13 +59,63 @@ export default { atom.notifications.addInfo('Stopped recording macro') }, + stopCurrentlyRecordingMacro() { + let editor = atom.views.getView(atom.workspace.getActiveTextEditor()) + editor.classList.remove('recording-macro') + recording = false + atom.notifications.addWarning('Currently recording macro! Stopping recording') + }, + applyMacro() { + if (recording === true) { + this.stopCurrentlyRecordingMacro(); + return + } + let editor = atom.views.getView(atom.workspace.getActiveTextEditor()) + let cursor = editor.querySelector('.cursor') atom.notifications.addInfo('Applying macro') + commandQueue.forEach(command => { + atom.commands.dispatch(cursor, command) + }) + }, + + appendToMacro() { + let editor = atom.views.getView(atom.workspace.getActiveTextEditor()) + let cursor = editor.querySelector('.cursor') + editor.classList.add('recording-macro') + recording = true + atom.notifications.addInfo('Appending to macro...') + }, + + applyAndAppendToMacro() { let editor = atom.views.getView(atom.workspace.getActiveTextEditor()) + if (recording === true) { + this.stopCurrentlyRecordingMacro(); + return + } let cursor = editor.querySelector('.cursor') commandQueue.forEach(command => { atom.commands.dispatch(cursor, command) }) + editor.classList.add('recording-macro') + recording = true + atom.notifications.addInfo('Applying then appending to macro...') + }, + + putMacroCommandsAsText() { + if (recording === true) { + this.stopCurrentlyRecordingMacro() + return + } + let editor = atom.workspace.getActiveTextEditor() + if (editor) { + editor.insertText('{\n') + commandQueue.forEach(command => { + editor.insertText(' '+command+'\n') + }) + editor.insertText('}') + } + atom.notifications.addInfo('Putting macro list of commmands') }, logCommand(event) { @@ -70,7 +123,9 @@ export default { return } const commandName = event.type - if (commandName === 'vim-mode-plus-macros:start-recording-macro') { + if (commandName === 'vim-mode-plus-macros:start-recording-macro' || + commandName === 'vim-mode-plus-macros:append-to-macro' || + commandName === 'vim-mode-plus-macros:apply-and-append-to-macro') { return } commandQueue.push(commandName)