[MlMt] Emacs Integration, for use as external editor

Alexandru Nedelcu groups7 at alexn.org
Tue May 16 15:53:54 EDT 2017


Hello,

I have a small bundle I worked on for integrating 
[Emacs](https://www.gnu.org/software/emacs/) with MailMate.

Project: https://github.com/alexandru/emacs.mmbundle

It assumes the [Emacs for Mac OS X](https://emacsformacosx.com/) 
distribution, but in case Emacs was installed using an alternative 
method (e.g. brew, Mac Ports, etc), then it's fine for as long as 
`emacs` and `emacsclient` binaries are found on this path:

```bash
PATH=$HOME/bin:~/Applications/Emacs.app/Contents/MacOS/bin:/Applications/Emacs.app/Contents/MacOS/bin:~/Applications/Emacs.app/Contents/MacOS:/Applications/Emacs.app/Contents/MacOS:/usr/local/bin:$PATH
```

For reference, some implementation details ...

This was surprisingly tricky to develop, because the only reasonable way 
to use Emacs as an on-demand editor is through `emacsclient`, which 
needs an Emacs server to be active. Normally this is done by starting 
Emacs at boot with `--daemon` or by doing a `(server-start)` in the 
`emacs.el` config, or you can start the client with `emacsclient 
--alternate-editor=""`, which starts a daemon if one isn't available 
already.

However starting the daemon from within a MailMate-executed script 
doesn't work because it is missing a TTY. I managed to work around that 
by starting the daemon within a `script -q`. Found the trick on 
StackOverflow somewhere.

The other problem is that starting the daemon is too slow, might take 
2-3 seconds, or even more, depending on how many plugins it has to load. 
So I was forced to display a notification by means of `osascript`, to 
let the user know that the editor is starting. But as long as a daemon 
is already active, opening a new Emacs window is instantaneous.

Cheers,

-- 
Alex Nedelcu
alexn.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freron.com/pipermail/mailmate/attachments/20170516/58509a78/attachment-0001.html>


More information about the mailmate mailing list