是否有一些模块或命令可以让我将当前区域发送给Shell?我希望有类似Python-mode的"python-send-region",它将选定的区域发送到当前运行的Python shell.
Vit*_*hKa 41
好的,写了一点简单.可能会花一些时间来编写完整的次要模式.
暂时,以下功能将发送当前行(如果标记处于活动状态,则发送区域).对我来说做得很好:
(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)
Run Code Online (Sandbox Code Playgroud)
请享用.
Jür*_*zel 11
(defun shell-region (start end)
"execute region in an inferior shell"
(interactive "r")
(shell-command (buffer-substring-no-properties start end)))
Run Code Online (Sandbox Code Playgroud)
我编写了一个包,用于将代码行或代码区域发送到shell进程,基本上类似于ESS用于R的内容.它还允许存在多个shell进程,并允许您选择将该区域发送到哪个进程.
看看这里:http://www.emacswiki.org/emacs/essh
Mx shell-command-on-region
又名.
M-|