gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:31:45 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com