From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help 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 Message-ID: <83lfvkj6wd.fsf@gnu.org> References: <20190822213103.GA26548@protected.rcdrun.com> <20190822224604.GA10900@protected.rcdrun.com> <83o90gb9u7.fsf@gnu.org> <20190823140145.GA28153@protected.rcdrun.com> Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="182769"; mail-complaints-to="usenet@blaine.gmane.org" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 23 16:28:04 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i1AXp-000lJY-DM for geh-help-gnu-emacs@m.gmane.org; Fri, 23 Aug 2019 16:28:01 +0200 Original-Received: from localhost ([::1]:56746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AXn-0003hx-Gh for geh-help-gnu-emacs@m.gmane.org; Fri, 23 Aug 2019 10:27:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48879) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AVP-00020C-MG for help-gnu-emacs@gnu.org; Fri, 23 Aug 2019 10:25:32 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:43457) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1i1AVP-0003yl-CS for help-gnu-emacs@gnu.org; Fri, 23 Aug 2019 10:25:31 -0400 Original-Received: from [176.228.60.248] (port=3167 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1i1AVJ-0002a0-Gj for help-gnu-emacs@gnu.org; Fri, 23 Aug 2019 10:25:28 -0400 In-reply-to: <20190823140145.GA28153@protected.rcdrun.com> (message from Jean Louis on Fri, 23 Aug 2019 16:01:45 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:121354 Archived-At: > Date: Fri, 23 Aug 2019 16:01:45 +0200 > From: Jean Louis > Cc: help-gnu-emacs@gnu.org > > 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 waiting.