I'd like to pass some selected text in a buffer to a python script. The python script will process the string and print the result to stdout. This output should replace the original string that was selected. Can this be done?
To tackle this, I first pass a selected buffer to my python script. Below is the elisp function that I wrote, following a similar function to implement the command wc
(defun it ()
(interactive)
(shell-command (concat "echo "
(buffer-substring (mark) (point))
" | /Users/john/bin/t ")))
This command succeeds and prints the output in the mini-buffer. Is there an elisp-way to overwrite the selected text with this output?
(buffer-string)
, but I understand the current code is more suitable for what you finally intend to do. I think it is nicer if you format the code in different lines b.t.w., I edit you question and do it for youshell-command-on-region
, bound toM-|
fit your requirements?shell-command-on-region
. I guess it would be handy to put it in an answer instead of a comment...