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

前端之家收集整理的这篇文章主要介绍了Emacs Shell模式:如何将区域发送到shell?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否有一些模块或命令,让我将当前区域发送到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)

请享用。

原文链接:https://www.f2er.com/bash/388885.html

猜你在找的Bash相关文章