Emacs Shell模式:如何将区域发送到shell?

Yar*_*tov 38 emacs

是否有一些模块或命令可以让我将当前区域发送给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)

请享用.

  • @vemv,`(setq comint-scroll-to-bottom-on-output t)`将解决你的问题. (8认同)

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)


lin*_*ver 8

我编写了一个包,用于将代码行或代码区域发送到shell进程,基本上类似于ESS用于R的内容.它还允许存在多个shell进程,并允许您选择将该区域发送到哪个进程.

看看这里:http://www.emacswiki.org/emacs/essh


小智 7

M-x append-to-buffer RET


Nem*_*emo 6

Mx shell-command-on-region

又名.

M-|

  • 这样做有所不同 - 它会提示输入shell命令并向该命令发送选择.我希望区域直接发送到shell(即,如果我突出显示"ls"并发送它,它将与将"ls"粘贴到*Shell*缓冲区中的行为相同) (5认同)