From: moshee Date: Wed, 12 Nov 2014 20:55:45 +0000 (-0800) Subject: Execute command once per selection range. Resolve #2. X-Git-Tag: v0.3.0~1 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0cde85081ad0a5bf6b6bbb9f2cfdfdb30a370846;p=atom-ax-pipe.git Execute command once per selection range. Resolve #2. --- diff --git a/lib/pipe.coffee b/lib/pipe.coffee index 94b5627..a85b634 100644 --- a/lib/pipe.coffee +++ b/lib/pipe.coffee @@ -22,23 +22,30 @@ module.exports = if history.length > 300 history.shift() - range = editor.getSelectedBufferRange() - stdout = '' - stderr = '' - commandString = "cd '#{atom.project.path}' && #{commandString}" - proc = spawn process.env.SHELL, ["-l", "-c", commandString] + properties = { reversed: true, invalidate: 'never' } - proc.stdout.on 'data', (text) -> - stdout += text + for range in editor.getSelectedBufferRanges() + marker = editor.markBufferRange range, properties + processRange marker, editor, commandString - proc.stderr.on 'data', (text) -> - stderr += text + view.focus() - proc.on 'close', (code) -> - editor.setTextInBufferRange(range, stderr || stdout) - editor.setSelectedBufferRange(new Range(range.start, range.start)) - view.focus() +processRange = (marker, editor, commandString) -> + stdout = '' + stderr = '' + + proc = spawn process.env.SHELL, ["-l", "-c", commandString] + + proc.stdout.on 'data', (text) -> + stdout += text + + proc.stderr.on 'data', (text) -> + stderr += text + + proc.on 'close', (code) -> + text = stderr || stdout + editor.setTextInBufferRange(marker.getBufferRange(), text) - proc.stdin.write(editor.getSelectedText()) - proc.stdin.end() + proc.stdin.write(editor.getTextInBufferRange(marker.getBufferRange())) + proc.stdin.end()