Implement shell commmand interaction
jakobwuhrer opened this issue · comments
hi, I've been happily using kakoune.el for a while now, but I'm kinda missing kakoune-like shell interaction compatible with multiple cursors (the kakoune normal mode ! and | commands)
I've taken a go at implementing them, but it garbles the cursors in ways I don't understand - would you mind taking a look?
(defun kakoune-shell-pipe ()
"Run a shell command on each of the current regions
separately and replace the current regions with its output"
(interactive)
(let ((command (read-string "Pipe: ")))
(mc/for-each-cursor-ordered
(shell-command-on-region (mc/cursor-beg cursor)
(mc/cursor-end cursor)
command
nil
1))))
(defun kakoune-shell-command ()
"Run a shell command on each of the current regions
separately and its output before the respective regions"
(interactive)
(mc/save-excursion
(let ((command (read-string "Pipe: ")))
(mc/for-each-cursor-ordered
(mc/save-excursion
(goto-char (mc/cursor-beg cursor))
(insert
(with-output-to-string
(shell-command-on-region (mc/cursor-beg cursor)
(mc/cursor-end cursor)
command
standard-output))))))))
(this implementation is also missing some "smart" code deciding whether to insert trailing newlines, but I'm planning to do that once the basics work)
I've been using this a bit over the past couple weeks, and it's working fine for me, so I'm closing the issue and merging these functions. Feel free to reopen if you have an example of cursor munging :)