Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Send text to shell from EMACS
(defun sh-send-line-or-region (&optional step)
(interactive ())
(let ((proc (get-process "shell"))
pbuf min max command)
(unless proc
(let ((currbuff (current-buffer)))
(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)
(defun sh-send-line-or-region-and-step ()
(sh-send-line-or-region t))
(defun sh-switch-to-process-buffer ()
(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)
Copy link

ugovaretto commented Feb 22, 2015

To auto scroll output

(setq comint-scroll-to-bottom-on-output t)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment