[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: emacs save and kill buffer for (neo)mutt



On Mon 29 Apr 2019 at 10:38:40 (+0200), Pétùr wrote:
> On 12/04/19 13:00, David Wright wrote:
> > On Fri 12 Apr 2019 at 18:04:45 (+0200), Pétùr wrote:
> > > I use neomutt with emacs.
> > > 
> > > I would like to quickly save and kill a buffer in emacs. This is to
> > > avoid typing C-x C-s and, then, C-x C-c when sending an email. I want
> > > one shortcut to save and kill the buffer and be back quickly in mutt to
> > > send the email.
> > > 
> > > I tried the following inside my .emacs (binded to C-q). It works but
> > > kill also the window when inside a terminal. I am not going back to mutt
> > > after writing inside emacs (-nw) and C-q. How can I fix that?
> > 
> > I just put
> > (global-set-key [?\C-q] "\C-x\C-s\C-x\C-c")
> > into my ~/.emacs file and it works just as one would expect, both when
> > emacs is running in a separate window (which disappears) or when emacs
> > is running with -nw in an xterm (the xterm is unaffected).
> > 
> > I will finish composing this email (in emacs -nw) by typing ^q and
> > expect to be left in mutt, whereupon I shall press y to send it.
> > Is that what you wnat?
> 
> (Sorry for the late reply)
> 
> Yes, this is exactly what I want to do.
> 
> (global-set-key [?\C-q] "\C-x\C-s\C-x\C-c") works as expected when emacs
> is launched as an instance. But I use it as a daemon. When emacs is
> launched by "emacs --daemon" and called by emacsclient, your shortcut
> will kill the buffer and I am not going back to mutt. I have to dig into
> my tmp folder to retrieve the email I was trying to send.
> 
> The same behavior occures with the code I use. (see first email).
> 
> How can I prevent this?

Use the correct means of exiting emacs, perhaps. The key sequences I
have used (^X^S^X^C, and the same keys but using ^Q shortcut) will
work if the emacsclient instance is in a different frame from the
emacs server. Because I use emacs -nw for composing emails¹, and the
server was running in a different xterm, it all worked.

OTOH if you're using emacs in its own window, then typically your
email composition will jump to that same window too. In which case,
typing ^X^C will shut down the emacs server itself. You should be
using ^X# instead, to exit just that buffer. So for you, it would be
(global-set-key [?\C-q] "\C-x\C-s\C-x#")
for the definition. ^X# is meant to signal the calling program that
it's completed its editing work.

¹ Why? For historical reasons. I used to type emails on a slow,
unreliable laptop, with mutt running on a server. Opening an X
window for emacs was also slow, so I ran it non-windowed.

Cheers,
David.


Reply to: