我在Windows 7上使用Emacs 23.3.1。我知道我可以使用M-x shell從emacs運行shell。我想在同一時間有多個shell窗口,但第二次輸入M-x shell只是打開了相同的shell窗口。如何在Emacs上運行多個shell
有沒有辦法讓不同的shell窗口?
我在Windows 7上使用Emacs 23.3.1。我知道我可以使用M-x shell從emacs運行shell。我想在同一時間有多個shell窗口,但第二次輸入M-x shell只是打開了相同的shell窗口。如何在Emacs上運行多個shell
有沒有辦法讓不同的shell窗口?
C-ùM-X外殼將做到這一點。
它會提示輸入一個名稱爲新殼,剛打了默認返回(這將是像*shell*<2>
與ESHELL同樣適用
另一個竅門,如果你使用ESHELL。:正如的Mx ESHELL帶你回到*eshell*
(而不是開始一個新ESHELL),如果使用數字前綴參數它會帶你到ESHELL緩衝區。例如,C-3的MxESHELL將帶您到*eshell*<3>
。不幸的是,如果你使用shell(而不是eshell),這個技巧似乎不起作用(至少在我的Emacs 24.0.50.1中)。
您可以用M-x重命名緩衝區重命名shell的緩衝區。然後你將能夠啓動第二個shell。
我寧願去與馬特柯蒂斯的解決方案。用新名稱運行一個shell似乎比重命名當前的shell更容易,然後運行一個新的shell。 – S4M
在屏幕上使用類似屏幕的界面也很有用。我寫了自己的,但也有其他人,如EmacsScreen。
這將自動生成一個新的shell實例在你正在使用的任何緩衝區;它綁定到MS或類似的和即時的快樂出頭:
(defun new-shell()
(interactive)
(let (
(currentbuf (get-buffer-window (current-buffer)))
(newbuf (generate-new-buffer-name "*shell*"))
)
(generate-new-buffer newbuf)
(set-window-dedicated-p currentbuf nil)
(set-window-buffer currentbuf newbuf)
(shell newbuf)
)
)
非常感謝菲爾斯使用讓推薦重寫,即使結果是更可怕的括號...:\
經過比起四年來,我發現有些人有時仍然在看這個問題,所以我會發佈一個我寫的加載shell並請求它的名字的快速函數。這樣,如果專用於排序文件,則可以命名shell爲「sort-files」,如果專用於運行配置單元查詢,則可以命名爲「配置單元」。我現在使用的日常(在Emacs的24):
(defun create-shell()
"creates a shell with a given name"
(interactive);; "Prompt\n shell name:")
(let ((shell-name (read-string "shell name: " nil)))
(shell (concat "*" shell-name "*"))))
這將打開一個新的shell每次調用函數時,如果需要自動重命名。 添加的加是,如果你是遠程編輯文件(dired /流浪漢......),這將打開遠程主機上的外殼,並與遠程主機名自動重命名爲:
(defun ggshell (&optional buffer)
(interactive)
(let* (
(tramp-path (when (tramp-tramp-file-p default-directory)
(tramp-dissect-file-name default-directory)))
(host (tramp-file-name-real-host tramp-path))
(user (if (tramp-file-name-user tramp-path)
(format "%[email protected]" (tramp-file-name-user tramp-path)) ""))
(new-buffer-nameA (format "*shell:%s*" host))
(new-buffer-nameB (generate-new-buffer-name new-buffer-nameA))
(currentbuf (get-buffer-window (current-buffer)))
)
(generate-new-buffer new-buffer-nameB)
(set-window-dedicated-p currentbuf nil)
(set-window-buffer currentbuf new-buffer-nameB)
(shell new-buffer-nameB)
))
好的,這個工程。 C-u M-x shell問我新的shell的名字。謝謝! – S4M
S4M沒問題。我爲eshell添加了一個提示;當你問到shell的時候,我不知道你是否會發現它有用,但是具有相同問題的eshell用戶可能會覺得它很有用。 –
在這裏學到了東西,謝謝! – Giann