Is there some module or command that'll let me send the current region to shell?
I want to have something like Python-mode's python-send-region
which sends the selected region to the currently running Python shell.
Ok, wrote an easy bit. Will probably spend some time to write a complete minor mode.
For time being the following function will send current line (or region if the mark is active). Does quite a good job for me:
(defun sh-send-line-or-region (&optional step) (interactive ()) (let ((proc (get-process "shell")) pbuf min max command) (unless proc (let ((currbuff (current-buffer))) (shell) (switch-to-buffer currbuff) (setq proc (get-process "shell")) )) (setq pbuff (process-buffer proc)) (if (use-region-p) (setq min (region-beginning) max (region-end)) (setq min (point-at-bol) max (point-at-eol))) (setq command (concat (buffer-substring min max) "\n")) (with-current-buffer pbuff (goto-char (process-mark proc)) (insert command) (move-marker (process-mark proc) (point)) ) ;;pop-to-buffer does not work with save-current-buffer -- bug? (process-send-string proc command) (display-buffer (process-buffer proc) t) (when step (goto-char max) (next-line)) )) (defun sh-send-line-or-region-and-step () (interactive) (sh-send-line-or-region t)) (defun sh-switch-to-process-buffer () (interactive) (pop-to-buffer (process-buffer (get-process "shell")) t)) (define-key sh-mode-map [(control ?j)] 'sh-send-line-or-region-and-step) (define-key sh-mode-map [(control ?c) (control ?z)] 'sh-switch-to-process-buffer)
Enjoy.
(defun shell-region (start end) "execute region in an inferior shell" (interactive "r") (shell-command (buffer-substring-no-properties start end)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With