From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis 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 16:01:45 +0200 Message-ID: <20190823140145.GA28153@protected.rcdrun.com> References: <20190822213103.GA26548@protected.rcdrun.com> <20190822224604.GA10900@protected.rcdrun.com> <83o90gb9u7.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="81188"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: help-gnu-emacs@gnu.org To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 23 16:04:25 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 1i1AAu-000KsI-2O for geh-help-gnu-emacs@m.gmane.org; Fri, 23 Aug 2019 16:04:20 +0200 Original-Received: from localhost ([::1]:56438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AAs-0006Nx-C3 for geh-help-gnu-emacs@m.gmane.org; Fri, 23 Aug 2019 10:04:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45412) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1A8W-0004Uu-E0 for help-gnu-emacs@gnu.org; Fri, 23 Aug 2019 10:01:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1A8V-0000Fz-03 for help-gnu-emacs@gnu.org; Fri, 23 Aug 2019 10:01:52 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:36925) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1A8T-0000Dn-2l; Fri, 23 Aug 2019 10:01:49 -0400 Original-Received: from protected.rcdrun.com ([::ffff:31.223.149.123]) (AUTH: PLAIN admin, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000320E9.000000005D5FF1CA.00005A26; Fri, 23 Aug 2019 07:01:46 -0700 Original-Received: from localhost (localhost [127.0.0.1]) (uid 1001) by protected.rcdrun.com with local id 00000000000C9452.000000005D5FF1C9.00006F95; Fri, 23 Aug 2019 16:01:45 +0200 Content-Disposition: inline In-Reply-To: <83o90gb9u7.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.170.207.13 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:121352 Archived-At: * Eli Zaretskii [2019-08-23 09:53]: > > From: Noam Postavsky > > Date: Thu, 22 Aug 2019 19:22:34 -0400 > > Cc: GNU Emacs Help > > > > > Yes. I need to be able to run function that waits on the buffer to be > > > killed, so that I can read string from the file that related to the > > > buffer. > > > > The difficulty is the waiting part. > > I think the difficulty is the very concept of "waiting". It probably > comes from the previous implementation, where Emacs was invoked as an > external program, and then the caller would "wait" for it to exit, and > take that as a signal that editing is complete. > > This paradigm is problematic when everything is done from within > Emacs, because once editing is done, Emacs just returns to its main > command loop and waits for the next command. IOW, it's Emacs that > "waits" here, not the command which invoked the editing part. > > One way to keep the "waiting" paradigm is to use recursive-edit (which > I still don't understand why the OP dislikes: the problems with "C-c > C-c" are minor and can be easily resolved). If that is somehow not > appropriate, then my question would be "what would the 'waiting' part > do once the wait is over?" Given the answer to that, it shouldn't be > hard to devise the solution that doesn't "wait", but instead causes > something to happen after editing is complete. Just as an example, if > after editing the application should refresh some buffer, then > triggering that buffer's revert function would be all that's needed. > > My main point is that doing this from Emacs needs a certain conceptual > shift, because the command loop and the resulting "wait" are now > implicit. The problem in using M-C-c is the habit and Emacs nature. Habit: ====== Editing 200 files in one days and closing those files with C-x k, saving them in that process is hard to break to even remember to do the M-C-c to quit editing from recursive buffer. Recursive editing for database fields, without file written on the disk is somehow risky. Something can happen in Emacs, and it does happen, and the waiting for recursive edit is "out" or finished before I would like it to finish. I am using various functions, helm, inserting links, etc. it all disturbs such waiting. That is Emacs nature, it has many other things running around. 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. 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. Other solution is to spawn another Emacs editor, but that would not appear integrated within one Emacs. Is there really no solution that one can do so from within Emacs reliable? I could use recursive-edit, if it will give me certainty that from Emacs Lisp I can know when buffer have been killed to read the string. 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. Jean 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.