[Top][All Lists]

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

Re: How to reliably edit a file from within Emacs Lisp and return a stri

From: Marcin Borkowski
Subject: Re: How to reliably edit a file from within Emacs Lisp and return a string?
Date: Fri, 23 Aug 2019 23:44:06 +0200
User-agent: mu4e 1.1.0; emacs 27.0.50

On 2019-08-23, at 16:01, Jean Louis <> wrote:

> Anything, any solution is fine, but I would not like to rely on
> C-M-c, rather on killing of the buffer to which the file is
> related.

I have not followed this thread very closely, so maybe I'm
misunderstanding something.  Nevertheless, here are my 2 cents.

Cent number 1 is: I had a similar problem.  I wanted to be able to edit
something in Emacs and I wanted Emacs to do something when I finish it.
So, I created a dedicated minor mode, with C-c C-c bound to
a "finishing" function.  (I'm 99% sure I haven't blogged about it.
Should I?)

Cent number 2 is: why don't you just do the same, and rebind C-x k in
your minor mode to do something useful?  It's not bullet-proof, of
course, since you might kill the buffer in some other way, but if your
habit is one part of the problem - that should help, no?  I would even
go as far as making C-x k play the "sad trombone" sound and tell you
(possibly with dancing elephants™) that you should use C-c C-c instead
(which is a customary way of telling Emacs "I'm done with whatever I've
been doing in this buffer" - it works this way in WDired, message-mode,
Magit and many other places)?  Of course, you should then bind C-c C-c
in *your* minor mode to *your* finishing ("commit") function.

This way, instead of fixing Emacs, you would fix yourself instead - but
still, the problem would be fixed.

Bonus cent (related to emacs client/server): I have this in my init.el:

--8<---------------cut here---------------start------------->8---
(require 'server)
(if (server-running-p)
    (load-theme 'green-phosphor t)
  (setq confirm-kill-emacs #'yes-or-no-p)
  (global-set-key (kbd "C-x C-3") 'server-edit))
--8<---------------cut here---------------end--------------->8---

What this does is:
- it starts the server by default,
- if makes every other Emacs instance _not_ start the server (this
wouldn't work anyway), and make it stand out using a very distnictive
theme (so that I do not accidentally spawn another Emacs session, forget
about it and try to use it for my normal tasks),
- make exiting from my main session hard and leave exiting from other
ones easy,
- and fix the terrible C-x # binding (which requires using the control
key first and shift next).

(I blogged about this setup here:


Marcin Borkowski

reply via email to

[Prev in Thread] Current Thread [Next in Thread]