Emacs shell模式: how to send region to shell?

标签 emacs

是否有一些模块或命令可以让我将当前区域发送到 shell?

我想要类似 Python 模式的 python-send-region 的东西,它将选定的区域发送到当前正在运行的 Python shell。

最佳答案

好的,写了一些简单的内容。可能会花一些时间写一个完整的次要模式。

暂时以下函数将发送当前行(或区域,如果标记处于事件状态)。对我来说做得很好:

(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)

享受吧。

关于Emacs shell模式: how to send region to shell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6286579/

相关文章:

emacs - 我可以在 emacs 中编写一个 jar 装的 find-grep 脚本吗?

vim - 邪恶的 Emacs 模式 : sentence motions and other questions

emacs - 如何在 emacs 次要模式下设置评论开始和评论结束?

emacs - 如何在 Emacs 组织模式中插入带有日期和时间的日程表

emacs - 是否存在不区分大小写的标签中查找文件?

linux - 在 Emacs 中匹配括号的命令是什么?

emacs - elisp中如何确定操作系统?

emacs - 根据主要模式更改字体

python - 在 emacs python 模式中不正确地退出缩进

emacs - 在 emacs 中查找文件名匹配模式的文件