2008-09-22 71 views
18

我喜歡使用Emacs的shell模式,但它有一些缺陷。其中之一是,當shell命令嘗試調用編輯器時,它不夠聰明打開新的緩衝區。例如與環境變量VISUAL設置爲vim我得到了來自svn propedit如下:當一個命令嘗試以shell模式打開一個編輯器時打開一個Emacs緩衝區

 
$ svn propedit svn:externals . 
"svn-prop.tmp" 2L, 149C[1;1H 
~                    [4;1H~                    [5;1H~                    [6;1H~                    [7;1H~    
... 

(這可能是難以從表現出來,但它是一個可怕的,醜陋的爛攤子。)

隨着VISUAL設置爲"emacs -nw",我得到

 
$ svn propedit svn:externals . 
emacs: Terminal type "dumb" is not powerful enough to run Emacs. 
It lacks the ability to position the cursor. 
If that is not the actual type of terminal you have, 
use the Bourne shell command `TERM=... export TERM' (C-shell: 
`setenv TERM ...') to specify the correct type. It may be necessary 
to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.svn: system('emacs -nw svn-prop.tmp') returned 256 

(它的工作原理與VISUAL集只是emacs,但只能從一個Emacs X窗口內,不在終端會話中。)

有沒有辦法讓shell模式在這裏做正確的事情並代表命令行進程打開一個新的緩衝區?

回答

19

您可以通過emacsclient附加到Emacs會話。首先,啓動emacs的服務器

M-x server-start 

或添加(server-start).emacs。然後,

export VISUAL=emacsclient 

編輯了。

注:

  • emacsemacsclient版本必須一致。如果您安裝了多個Emacs版本,請確保您調用對應於運行服務器的Emacs版本的emacsclient版本。
  • 如果您以多個Emacs進程/框架啓動服務器(例如,因爲(server-start)位於您的.emacs中),將在最後一幀中創建緩衝區以啓動服務器。
+0

$ svn propedit svn:忽略。 等待Emacs ... -error未知&_command:&_ ABSPATH/TO/REPO/svn&-prop.tmp 沒有更改屬性的svn:ignore'on'。' – 2008-09-22 18:34:50

3

還有emacsclient,gnuserv和Emacs 23,multi-tty,這些都對此有用。其實我認爲在Emacs 23中,emacsclient具有gnuserv的所有有趣功能。

0

不完全如此。 ansi-term可以運行一個emacs罰款(雖然我通常運行mg提交日誌,在罕見的情況下,我不直接從emacs提交)。 eshell也可以運行一個emacs,如果你先啓動一個screen並從那裏運行它。

0

隨着使用emacs客戶端/服務器,我使用這個腳本來調用emacs。

這將啓動emacs,如果它尚未運行,或者只是在運行的emacs(使用gnuclient)中打開一個新的emacs緩衝區。它在默認情況下在後臺運行,但可以在前臺運行需要某些輸入的進程。例如,當輸入更改列表描述時,我將其用作我的源代碼控制編輯器。我有「SVN_EDITOR = emacs sync」,所以我可以在emacs shell中執行「svn commit」,它會在同一個emacs中的新emacs緩衝區中打開svn編輯器。當我關閉緩衝區時,「svn commit」繼續。非常有用。

 
#!/bin/sh 

if [ -z $EMACS_CMD ]; then 
    EMACS_CMD="/usr/bin/emacs" 
fi 

if [ -z $GNUCLIENT_CMD ]; then 
    GNUCLIENT_CMD="/usr/bin/gnuclient" 
fi 

if [ "$1" = "sync" ]; then 
    shift 1 
    sync=true 
else 
    sync=false 
fi 

cmd="${EMACS_CMD} $*" 
lsof $EMACS_CMD | grep $USER >/dev/null 2>&1 
if [ "$?" -ne "1" ]; then 
    cmd="${GNUCLIENT_CMD} $*" 
fi 

if [ $sync = "true" ]; then 
    $cmd 
else 
    $cmd & 
fi 

0

我想通過mercurial在emacs shell中進行類似的合併。感謝這裏的海報,我找到了方法。兩個步驟:

  1. 附加:(啓動服務器)在你的.emacs文件(記得要加載文件的更改後)

  2. 在hgrc:

     
    [merge-tools] 
    emacs.executable = emacsclient 
    emacs.premerge = False 
    emacs.args = --eval "(ediff-merge-with-ancestor \"$local\" \"$other\" \"$base\" nil \"$output\")" 
    

0

當我有(啓動服務器)在我的.emacs我得到這個錯誤....

Debugger entered--Lisp error: (void-function start-server) 
    (start-server) 
    eval-buffer(#<buffer *load*> nil "/Users/jarrold/.emacs" nil t) ; Reading at buffer position 22768 
    load-with-code-conversion("/Users/jarrold/.emacs" "/Users/jarrold/.emacs" t t) 
    load("~/.emacs" t t) 
    #[nil "^H\205\276^@ \306=\203^Q^@\307^H\310Q\202A^@ \311=\2033^@\312\307\313\314#\203#^@\315\202A^@\312\307\$ 
    command-line() 
    normal-top-level() 

....我使用的是GNU Emacs 22.1.1

這是否爲Mac OS-X的版本,我使用:

shandemo 511 $ UNAME -a達爾文Facilitys-的MacBook,Pro.local 10.8.0

Darwin內核版本10.8。 0:星期二6月6日16:33:36 PDT 2011;

根:XNU-1504.15.3〜1/RELEASE_I386 I386

注意,M-X ANSI-術語似乎允許我順利汞柱它的外殼的內部提交。但是,該shell不讓我滾動瀏覽緩衝區,例如c-p或c-n,所以我更喜歡我們的m-x shell。

相關問題