有一些模塊或命令可以讓我將當前區域發送給Shell嗎?我想要有類似Python模式的「python-send-region」,它將選定的區域發送到當前運行的Python shell。Emacs Shell模式:如何發送區域到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)
享受。
M-x shell-command-on-region
aka。
M- |
你想讓命令自動執行,還是隻是在準備好的命令行中輸入?
M-Xappend-to-buffer
RET將進入選擇的文本到在點指定的緩衝區,但命令將不會被外殼來執行。
一個包裝函數可以自動爲緩衝區選擇*shell*
(或者根據shell模式中的當前緩衝區更智能地選擇/提示),然後調用append-to-buffer。
您可以簡單地記錄一個鍵盤宏以複製區域,切換到*shell*
,抽出並輸入(如果需要)。
F3M-瓦特C-Xb*shell*
RETC-ýRETF4
C-XC-KÑmy-execute-region-in-shell
RET
M-Xinsert-kbd-macro
RETmy-execute-region-in-shell
RET
(global-set-key (kbd "C-c e") 'my-execute-region-in-shell)
(defun shell-region (start end)
"execute region in an inferior shell"
(interactive "r")
(shell-command (buffer-substring-no-properties start end)))
這非常出色 - 可以讓我複製我最關心的Acme編輯器的功能。 – sea6ear 2012-11-12 22:58:31
的Mxappend-to-buffer
RET
修改尤爾根斯回答上方以一個特定的緩衝操作提供了以下功能,將發送區域,然後切換到緩衝區中,在另一個窗口中顯示出來,該緩衝區命名PYTHON用於說明。目標緩衝區應該已經在運行一個shell。
(defun p-send(start end)
(interactive "r") ;;Make the custom function interactive and operative on a region
(append-to-buffer (get-buffer "*PYTHON*") start end) ;;append to the buffer named *PYTHON*
(switch-to-buffer-other-window (get-buffer "*PYTHON*")) ;;switches to the buffer
(execute-kbd-macro "\C-m")) ;;sends the enter keystroke to the shell
這是this post的另一個解決方案。
只是爲了方便而複製它。打印聲明在這裏很重要。
(add-hook 'python-mode-hook
'my-python-send-statement)
(defun my-python-send-statement()
(interactive)
(local-set-key [C-return] 'my-python-send-statement)
(end-of-line)
(set-mark (line-beginning-position))
(call-interactively 'python-shell-send-region)
(python-shell-send-string "; print()"))
- 1. 在emacs中重新發送相同的區域到R shell
- 2. 如何發送^ K到shell
- 3. 如何將SIGINT發送到shell腳本?
- 4. Emacs遠程shell
- 5. 找不到Emacs shell命令
- 6. Emacs shell輸出緩衝區高度
- 7. Emacs/Python:在線緩衝區與塊緩衝區模式下運行python-shell
- 8. 顯示在Emacs Shell模式下收到的stdout
- 9. 與Emacs shell相似?
- 10. Python - 我如何從shell讀取stdin,並將stdout發送到shell和文件
- 11. emacs python-mode:指定要發送命令的哪個python shell
- 12. shell腳本:發送sed輸出到mysql?
- 13. 發送擊鍵到shell應用程序?
- 14. 如何在啓動emacs/spacemacs時自動啓動shell緩衝區
- 15. 如何在emacs中生成* shell *緩衝區?
- 16. 通過shell發送arp
- 17. 如何從Emacs運行django shell?
- 18. 如何從Emacs中運行Cygwin Bash Shell?
- 19. 如何跳轉到shell輸出的第一行? (shell等價於emacs comint-show-output)
- 20. emacs shell:輸入一次,到處運行
- 21. Emacs 24中的Python Shell?
- 22. 如何發送Python變量到shell命令?
- 23. 如何將文本發送到shell腳本中的進程?
- 24. 如何發送shell腳本(json)輸出到aws sns主題?
- 25. 用於Emacs python模式的自定義Python shell
- 26. Emacs shell模式SSH會話中的標籤完成
- 27. Emacs的shell模式顯示不希望焦炭
- 28. emacs shell模式窗口中prlctl exec的問題
- 29. Emacs:在shell腳本模式下執行代碼
- 30. 拆分窗口後Emacs shell模式顯示太寬
好問題。夥伴。我正在尋找同樣的東西,除了你的帖子以外找不到任何東西。很難相信沒有人從sh腳本中將基本行和區域發送者寫入當前shell。將搜索一下,並會寫我自己,如果不會找到。 – VitoshKa 2011-08-13 18:50:58