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 10:49:04 +0300 Message-ID: <83o90gb9u7.fsf@gnu.org> References: <20190822213103.GA26548@protected.rcdrun.com> <20190822224604.GA10900@protected.rcdrun.com> Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="132643"; 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 09:52:31 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 1i14N4-000YLY-6d for geh-help-gnu-emacs@m.gmane.org; Fri, 23 Aug 2019 09:52:30 +0200 Original-Received: from localhost ([::1]:52494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i14N2-0001e5-RS for geh-help-gnu-emacs@m.gmane.org; Fri, 23 Aug 2019 03:52:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37044) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i14Jg-00082t-6T for help-gnu-emacs@gnu.org; Fri, 23 Aug 2019 03:49:02 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:54037) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1i14Jf-0007mo-HZ for help-gnu-emacs@gnu.org; Fri, 23 Aug 2019 03:49:00 -0400 Original-Received: from [176.228.60.248] (port=2495 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1i14Ja-00005A-Ta for help-gnu-emacs@gnu.org; Fri, 23 Aug 2019 03:48:55 -0400 In-reply-to: (message from Noam Postavsky on Thu, 22 Aug 2019 19:22:34 -0400) 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:121351 Archived-At: > 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. > It might be possible to use threads for waiting and get more linear > code that way Not recommended.