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.
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:
[merge-tools] emacs.executable = emacsclient emacs.premerge = False emacs.args = --eval "(ediff-merge-with-ancestor \"$local\" \"$other\" \"$base\" nil \"$output\")"