Created
February 22, 2015 17:13
-
-
Save ugovaretto/0339c5e3efe3fdde502a to your computer and use it in GitHub Desktop.
Send text to shell from EMACS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To auto scroll output