[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: Eli Zaretskii
Subject: Re: How to reliably edit a file from within Emacs Lisp and return a string?
Date: Fri, 23 Aug 2019 17:25:22 +0300

> Date: Fri, 23 Aug 2019 16:01:45 +0200
> From: Jean Louis <>
> Cc:
> The problem in using M-C-c is the habit and Emacs nature.

I see your point, although I don't share your conclusions.  But it's
pointless to argue about that, because it's your code, and all I want
to do is help you get it right according to your preferences.

> I would be happy if I can do something like:
> (defun emacsclient-edit (file)
>   (shell-command (format "emacsclient %s " file))
>   (file-to-string file))
> But that does not work within Emacs itself. Would that work, I would be fine.

See, that's exactly the paradigm I suggest to unlearn when you
implement features, such as the one you described, entirely in Emacs.
What you need instead is to trigger something (which I don't yet think
I understand) once editing is complete.  Can you describe in more
detail what should your feature do after the user is done with editing
the file?

> It is somehow strange that I can run emacsclient from outside
> Emacs and edit file and know that emacsclient finished its job,
> and read the string from file, and that I cannot do the same from
> Emacs.

That's because Emacs is a single-threaded program, so while its single
thread waits for emacsclient, no other code in Emacs can run and serve
the emacsclient request.  Emacs is stuck waiting, period.

> Other solution is to spawn another Emacs editor, but that would
> not appear integrated within one Emacs.

That's an awful design, IMO, even though there's a very smart and
sophisticated package out there that supports exactly that.

> Is there really no solution that one can do so from within Emacs
> reliable?

I'm sure there is, but at least for me the details of the problem that
you face are not yet sufficiently clear to give a concrete advice.

> P.S. For example, I am spawning this text in emacsclient from
> mutt. Mutt is waiting until I kill this buffer. Then I go back to
> vterm or ansi-term and I can send email from mutt. This works. It is
> totally not logical that I cannot do the same from within Emacs.

It's very logical, because in the latter case it's the same program
that "waits" and should serve the editing job.  emacsclient works by
sending a request to Emacs to edit the file, and Emacs cannot serve
that request while it's waiting for emacsclient, because it's busy

reply via email to

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