I like to use Emacs' shell mode, but it has a few deficiencies. One of those is that it's not smart enough to open a new buffer when a shell command tries to invoke an editor. For example with the environment variable VISUAL
set to vim
I get the following from svn propedit
:
$ svn propedit svn:externals . "svn-prop.tmp" 2L, 149C[1;1H ~ [4;1H~ [5;1H~ [6;1H~ [7;1H~ ...
(It may be hard to tell from the representation, but it's a horrible, ugly mess.)
With VISUAL
set to "emacs -nw"
, I get
$ 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
(It works with VISUAL
set to just emacs
, but only from inside an Emacs X window, not inside a terminal session.)
Is there a way to get shell mode to do the right thing here and open up a new buffer on behalf of the command line process?
Not entirely true.
ansi-term
can run an emacs fine (although I usually run mg for commit logs, in the rare event I don't commit from emacs directly).eshell
can also run an emacs if you start ascreen
first and run it from within there.I wanted to do something similar for merging in an emacs shell via mercurial. Thanks to the posters here, i found the way. two steps:
add: (start-server) in your .emacs file (remember to load-file after your change)
in your hgrc:
You can attach to an Emacs session through
emacsclient
. First, start the emacs server withor add
(server-start)
to your.emacs
. Then,Edit away.
Note:
emacs
andemacsclient
must agree. If you have multiple versions of Emacs installed, make sure you invoke the version ofemacsclient
corresponding to the version of Emacs running the server.(server-start)
is in your.emacs
), the buffer will be created in the last frame to start the server.When I have (start-server) in my .emacs I get this error....
....I am using GNU Emacs 22.1.1
And this is the version of Mac OS-X I am using:
Note that m-x ansi-term appears to allow me to successfully hg commit inside of its shell. However, that shell does not let me scroll through the buffer with e.g. c-p or c-n so I would prefer to us m-x shell.
There's emacsclient, gnuserv, and in Emacs 23, multi-tty that are all useful for this. Actually I think in Emacs 23, emacsclient has all of the interesting functionality of gnuserv.
Along with using emacs client/server, I am using this script to invoke emacs.
This will start emacs if it is not running yet, or just open a new emacs buffer in the running emacs (using gnuclient). It runs in the background by default, but can be run in the foreground for processes that expect some input. For example, I am using this as my source control editor, when entering a change list description. I have "SVN_EDITOR=emacs sync", so I can do "svn commit" in an emacs shell, and it will open the svn editor in a new emacs buffer in the same emacs. When I close the buffer, "svn commit" continues. Pretty useful.