簡體   English   中英

當命令嘗試以shell模式打開編輯器時,打開Emacs緩沖區

[英]Open an Emacs buffer when a command tries to open an editor in shell-mode

我喜歡使用Emacs的shell模式,但它有一些不足之處。 其中之一是,當shell命令試圖調用編輯器時,打開新緩沖區並不夠智能。 例如,將環境變量VISUAL設置為vim我從svn propedit獲得以下內容:

$ 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模式在這里做正確的事情並代表命令行進程打開一個新的緩沖區?

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

M-x server-start

或者(server-start)添加到.emacs 然后,

export VISUAL=emacsclient

編輯。

注意:

  • emacsemacsclient的版本必須達成一致。 如果安裝了多個版本的Emacs,請確保調用與運行服務器的Emacs版本對應的emacsclient版本。
  • 如果在多個Emacs進程/幀中啟動服務器(例如,因為(server-start).emacs ),將在最后一幀中創建緩沖區以啟動服務器。

有emacsclient,gnuserv,在Emacs 23中,multi-tty對此都很有用。 實際上我認為在Emacs 23中,emacsclient具有gnuserv的所有有趣功能。

當我在.emacs中有(start-server)時,我得到了這個錯誤....

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 Darwin Facilitys-MacBook-Pro.local 10.8.0

Darwin內核版本10.8.0:2011年6月7日星期二16:33:36 PDT;

root:xnu-1504.15.3~1 / RELEASE_I386 i386

請注意,mx ansi-term似乎允許我在其shell中成功提交hg。 但是,那個shell不允許我使用例如cp或cn滾動緩沖區,所以我更喜歡使用mx shell。

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

  1. 在.emacs文件中添加:(start-server)(記得在更改后加載文件)

  2. 在你的hgrc:

    \n [合並工具]\n emacs.executable = emacsclient\n emacs.premerge = False\n emacs.args = --eval“(ediff-merge-with-ancestor \\”$ local \\“\\”$ other \\“\\”$ base \\“nil \\”$ output \\“)”\n

不完全正確。 ansi-term可以運行emacs罰款(雖然我通常為提交日志運行mg,在極少數情況下我不直接從emacs提交)。 如果你先啟動一個screen並從那里運行它, eshell也可以運行emacs。

除了使用emacs客戶端/服務器,我使用此腳本來調用emacs。

這將啟動emacs,如果它還沒有運行,或者只是在運行的emacs中打開一個新的emacs緩沖區(使用gnuclient)。 它默認在后台運行,但可以在前台運行,以獲得期望輸入的進程。 例如,在輸入更改列表描述時,我將其用作源控件編輯器。 我有“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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM