jmorag / kakoune.el

A very simple simulation of the kakoune editor inside of emacs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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)

Glad you've been happy with the package! I'm not seeing the garbling you're mentioning. Can you provide a minimal example?

output-2020-05-25-14:18:02

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 :)