From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: ielm automatic saving of history -- bug 67000 Date: Sun, 13 Oct 2024 09:06:25 +0300 Message-ID: <86v7xwtu3i.fsf@gnu.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23786"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Madhu , Simen =?utf-8?Q?Heggest=C3=B8yl?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Oct 13 08:07:31 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1szrlL-00061B-E0 for ged-emacs-devel@m.gmane-mx.org; Sun, 13 Oct 2024 08:07:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1szrkO-0005BV-RG; Sun, 13 Oct 2024 02:06:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1szrkM-0005B7-Hs for emacs-devel@gnu.org; Sun, 13 Oct 2024 02:06:30 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1szrkL-0006jC-8O; Sun, 13 Oct 2024 02:06:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=1D4N6kyhBo1M0S3c7ynifBqt1iWGDfoSs5NVWjYapRA=; b=Yq+Hw0gws34dpuYwMmpK dkXkYxXG9cUIrpNAUZmyY5f1dvVnM2R6CKPwJhnt9Tn/ZE6E4fxxG3L1sm+pFcr028RlE4D/v5sIS KZAs3s7Gb6NtubamqcrCS0w7glOikHRWqyScM0He47BKFLDmp/O+IDcoUaK8ixP3yt4++rfaB0a2t z9dQiLBeIwJpp/gEv4SSo+LEnfwJCA3RMM/dnob7HZgUwRCpE5mwoJHRujpmbg3Zh8tyoUSRoerGg 3oTGJvw44GoHrxo0ZQ7W81ZKqUVHKshc5d8Vr6JDhR6GcHd3kFYHO80+QzYaON80LO7/H7YAdR+KV DFd8222YMqDjbw==; In-Reply-To: (message from Madhu on Sun, 13 Oct 2024 09:47:25 +0530) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:324535 Archived-At: > From: Madhu > Date: Sun, 13 Oct 2024 09:47:25 +0530 > > I see several problems with this implementation (based on opaque > closures), the worst of which is that I am unable to quit emacs, because > a closure (which tries to save the contents of a killed-buffer, is in > kill-emacs-hook, and it cannot get the coding system right) I think ielm--input-history-writer should bind coding-system-for-write to utf-8-emacs-unix around writing to the file, and it should add a file-locals section stating the encoding (for reading the history back). > 2. The way to opt out of this is to set ielm-history-file-name to nil in > user customization. In that case this code path should be avoided > altogether. If you do that, comint-write-input-ring is supposed to do nothing and return immediately. Does that not happen? However, it sounds safer to avoid adding the hooks in that case as well. > ielm--exit is a buffer local variable which gets set to > ``` > (lambda () > (with-current-buffer buf > (comint-write-input-ring))) > ``` > > and pushed onto kill-emacs-hook. Another closure gets pushed onto > kill-buffer-hook, which removes the elt in kill-emacs-hook when it > runs. > > The "worst" problem happens when ielm buffer exits without running > kill-buffer-hook How can this happen? can you show a recipe for this? ( -- historically I've used this pattern to avoid > saving history for a particular buffer, this is the way to opt out of > saving the history) but in this case it runs from the kill-emacs-hook, > and that forces me to choose a coding system to save the buffer. There > is no option to opt out. > > I don't have any suggestions on how to solve this with this design. > > 3. The default Comint functions for storing eliisp history is less than > acceptable. it stores lines, while ielm and elisp permit multi-line sexp > forms. > > personally I've used code (derived from sly so not probably fsf license) > in ielm-mode-hook to set up merge and save multiline forms using comint, > I'm attaching this file here, for reference. However the currenlty > installed implementation in (inferior-emacs-lisp-mode) does not play > well with the this: It unconditionally touches comint history variables, > my code also has to set the comint variables to use the comint history > mechanism, and these are picked up with exit hooks. > > Maybe others using the facility will have some opinions on this. My own > takeaway is it is not desirable to 1) force history saving mechanisms 2) > use opaque closures for implementing hook functions. Simen, any comments or suggestions? This feature is new in Emacs 30, so it isn't too late to improve it before we release Emacs 30.1. Thanks.