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: Sat, 24 Aug 2019 17:51:03 +0200 Message-ID: <20190824155103.GB11684@protected.rcdrun.com> References: <83o90gb9u7.fsf@gnu.org> <20190823140145.GA28153@protected.rcdrun.com> <83lfvkj6wd.fsf@gnu.org> <20190824121924.GQ5516@protected.rcdrun.com> <83r25aiw4f.fsf@gnu.org> <20190824124120.GT5516@protected.rcdrun.com> <83mufyitye.fsf@gnu.org> <20190824141421.GB11116@protected.rcdrun.com> <20190824145512.GA11684@protected.rcdrun.com> <83h866iopc.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="33225"; 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 Sat Aug 24 17:51:24 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 1i1YK1-0008UT-Od for geh-help-gnu-emacs@m.gmane.org; Sat, 24 Aug 2019 17:51:21 +0200 Original-Received: from localhost ([::1]:38276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1YK0-0000b5-OS for geh-help-gnu-emacs@m.gmane.org; Sat, 24 Aug 2019 11:51:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60550) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1YJr-0000az-5w for help-gnu-emacs@gnu.org; Sat, 24 Aug 2019 11:51:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1YJq-0000xt-2h for help-gnu-emacs@gnu.org; Sat, 24 Aug 2019 11:51:10 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:59687) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1YJo-0000v9-KM; Sat, 24 Aug 2019 11:51:08 -0400 Original-Received: from protected.rcdrun.com ([::ffff:31.223.149.228]) (AUTH: PLAIN admin, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000320EB.000000005D615CE8.00004F9C; Sat, 24 Aug 2019 08:51:04 -0700 Original-Received: from localhost (localhost [127.0.0.1]) (uid 1001) by protected.rcdrun.com with local id 00000000000C9452.000000005D615CE7.0000314C; Sat, 24 Aug 2019 17:51:03 +0200 Content-Disposition: inline In-Reply-To: <83h866iopc.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:121367 Archived-At: * Eli Zaretskii [2019-08-24 17:11]: > > Date: Sat, 24 Aug 2019 16:55:12 +0200 > > From: Jean Louis > > Cc: help-gnu-emacs@gnu.org > > > > > (defun edit-db-field-value (table field type id value file) > > > (string-to-file-force value file) > > > (let* ((buffer (create-file-buffer file))) > > > (switch-to-buffer buffer) > > > (set-visited-file-name file) > > > (insert value) > > > (add-hook 'kill-buffer-hook `(lambda () > > > (let ((new-value (file-to-string ,file))) > > > (rcd-db-update-entry ,table ,field ,type ,id new-value))) > > > 0 t))) > > > > > > > I was just thinking it is solved, but it does not solves anything but > > that string can be read into the file. > > > > However, that way program execution does not continue. There is no > > waiting loop or something like that. > > > > It just makes sure that one field is read back into string. > > So now you need to take that string and feed it back into the > database, right? So why are you saying this is not the solution? > What else is missing? kill-buffer-hook is a hook, it does not help me to continue program execution. A database table can have many fields: page-title page-description page-body Program may iterate over fields. After each editing of title, the program moves back to the initial iteration of fields or main program loop. After editing of title, I move back to the above list. Then I edit description, I should be able to move back. If hook is installed, it just ensured to read back the string into database, but it escapes the main loop, program execution basically and there, as nothing is holding it. It could be solved if I could hold on find-file, and to know that find-file finished its job, so that Emacs Lisp can continue after find-file Jean