From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67000: 30.0.50; [PATCH] Add support for reading/writing IELM input history Date: Wed, 07 Feb 2024 15:02:56 +0100 Message-ID: <87sf24l6cv.fsf@runbox.com> References: <87sf5ge0v6.fsf@runbox.com> <87a5pl1qym.fsf@runbox.com> <87y1d0p9ic.fsf@runbox.com> <874jfibkju.fsf@runbox.com> <87eded2270.fsf@runbox.com> Reply-To: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37008"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 67000@debbugs.gnu.org, Eli Zaretskii To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 07 15:04:25 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1rXiXH-0009Os-Su for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Feb 2024 15:04:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rXiWn-0002FS-VG; Wed, 07 Feb 2024 09:03:53 -0500 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 1rXiWj-0002Ee-Bk for bug-gnu-emacs@gnu.org; Wed, 07 Feb 2024 09:03:52 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rXiWj-0007Mb-43 for bug-gnu-emacs@gnu.org; Wed, 07 Feb 2024 09:03:49 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rXiWw-0003uL-K9 for bug-gnu-emacs@gnu.org; Wed, 07 Feb 2024 09:04:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Feb 2024 14:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67000 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 67000-submit@debbugs.gnu.org id=B67000.170731461814983 (code B ref 67000); Wed, 07 Feb 2024 14:04:02 +0000 Original-Received: (at 67000) by debbugs.gnu.org; 7 Feb 2024 14:03:38 +0000 Original-Received: from localhost ([127.0.0.1]:55910 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rXiWX-0003tZ-9i for submit@debbugs.gnu.org; Wed, 07 Feb 2024 09:03:37 -0500 Original-Received: from mailtransmit05.runbox.com ([2a0c:5a00:149::26]:43698) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rXiWU-0003tI-0O for 67000@debbugs.gnu.org; Wed, 07 Feb 2024 09:03:36 -0500 Original-Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit05.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1rXiW8-00GxKo-SO for 67000@debbugs.gnu.org; Wed, 07 Feb 2024 15:03:12 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector1; h=Content-Type:MIME-Version:Message-ID:Date:References: In-Reply-To:Subject:Cc:To:From; bh=FuQS0XrIufku/Wgs73w66uR7PNYztVlcDxR/7Bgg0kQ=; b=2UmNqoeSthMNyIF1OMg8ClWJlT GeMiA+2HRR6tNmxkKHkSp0UnbMKORIGAVYb1vcIpwteZh9xT/rsH3VchiKrfz9dEaYyufVaGEkDuZ FX7LVL+Q16U9tugHRLGEJsifoGgP0sB/Bq4Xw1rQ0yLlLY12mgbFT35ZX7SB0FCjjnhfEhp6g4EJ+ uWwkvTitnh0zmUtL+h1yfJpH9e0Lrglyam9vLh6iZQ9SvxDXBNy+2JSgd6/dcr68UhCCS0hT+CDmW hc9JZsoe/kmz7EpZecFbrKZc+rJUSa+5/72A4fdadj0eyRmOu+5F50/D30GwLIn8LolBaZOlejFUu Tawgg6Og==; Original-Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1rXiW7-0001Rk-SP; Wed, 07 Feb 2024 15:03:12 +0100 Original-Received: by submission01.runbox with esmtpsa [Authenticated ID (963757)] (TLS1.2:ECDHE_SECP256R1__RSA_SHA256__AES_256_GCM:256) (Exim 4.93) id 1rXiVu-004X3T-HT; Wed, 07 Feb 2024 15:02:58 +0100 In-Reply-To: (Stefan Kangas's message of "Sun, 28 Jan 2024 07:09:10 -0800") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:279551 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Stefan, thanks for your feedback. An updated patch is attached. Stefan Kangas writes: > Simen Heggest=C3=B8yl writes: > >> +--- >> +*** IELM now remembers input history between sessions. >> + >> +--- >> +*** New variable 'ielm-history-file-name'. >> +If non-nil, name of the file to read/write IELM input history. Set to >> +nil to revert IELM to the old behavior of not remembering input >> +history between sessions. > > I would probably make this into one entry, like so: > > *** IELM now remembers input history between sessions. > The new user option 'ielm-history-file-name' is the name of the file > where IELM input history will be saved. Customize it to nil to revert > to the old behavior of not remembering input history between sessions. Aight, changed! >> +(defcustom ielm-history-file-name >> + (locate-user-emacs-file "ielm-history.eld") >> + "If non-nil, name of the file to read/write IELM input history." >> + :type '(choice (const :tag "nil" nil) > > The tag here should be "Disable input history" or something like that. Ok. Should it be updated for `comint-input-ring-file-name' too then (I copied it from there)? > This should read > > (defvar ielm--exit nil > > or the below docstring will instead be its value. Of course, thanks. >> + "Function to call when Emacs is killed.") >> + >> +(defun ielm--input-history-writer (buf) >> + "Return a function writing IELM input history to BUF." >> + (lambda () >> + (with-current-buffer buf >> + (comint-write-input-ring)))) >> + >> ;;; Major mode >> >> (define-derived-mode inferior-emacs-lisp-mode comint-mode "IELM" >> @@ -605,6 +623,17 @@ inferior-emacs-lisp-mode >> #'ielm-indirect-setup-hook 'append t) >> (setq comint-indirect-setup-function #'emacs-lisp-mode) >> >> + ;; Input history >> + (setq-local comint-input-ring-file-name ielm-history-file-name) >> + (setq-local ielm--exit (ielm--input-history-writer (current-buffer))) >> + (setq-local kill-buffer-hook >> + (lambda () >> + (funcall ielm--exit) >> + (remove-hook 'kill-emacs-hook ielm--exit))) >> + (unless noninteractive >> + (add-hook 'kill-emacs-hook ielm--exit)) >> + (comint-read-input-ring t) > > There are some complications here: > > You can get more than one IELM buffer using > > M-x ielm RET > M-x rename-buffer RET foo RET > M-x ielm RET > > What happens if there is more than one IELM buffer? It will save only > the history from the last one, or something like that? Yes. Though I think that's kind of expected; that's how Eshell for instance also works. > Perhaps the kill-emacs-hook should look for all buffers that are using > `ielm-mode' and save the history from all of them? It would also need to be handled in the kill-buffer hooks I guess, updating the remaining buffers' histories when one buffer is killed. Sounds kind of messy though, I think I'd prefer the more simple approach suggested here. -- Simen --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-Add-support-for-reading-writing-IELM-input-history.patch Content-Transfer-Encoding: quoted-printable >From fe91c4f3aaefc109135c48ba26f8f21e87db465e Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Simen=3D20Heggest=3DC3=3DB8yl?=3D Date: Tue, 16 Jan 2024 08:21:41 +0100 Subject: [PATCH] Add support for reading/writing IELM input history * lisp/ielm.el (inferior-emacs-lisp-mode): Add support for reading/writing input history. (ielm--history-file-name): Name of the file to read/write IELM input history. (ielm--exit): Holds a function to call when Emacs is killed to write out the input history. (ielm--input-history-writer): Helper function for writing the IELM input history out to file. --- etc/NEWS | 8 ++++++++ lisp/ielm.el | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index ee7462cb2aa..2c98a805582 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1328,6 +1328,14 @@ characters, such as =C2=BD (U+00BD VULGAR FRACTION O= NE HALF), are also recognized as rational fractions. They have been since 2004, but it looks like it was never mentioned in the NEWS, or even the manual. =20 +** IELM + +--- +*** IELM now remembers input history between sessions. +The new user option 'ielm-history-file-name' is the name of the file +where IELM input history will be saved. Customize it to nil to revert +to the old behavior of not remembering input history between sessions. + * New Modes and Packages in Emacs 30.1 =20 diff --git a/lisp/ielm.el b/lisp/ielm.el index 777aebb70cf..e583e0fe32c 100644 --- a/lisp/ielm.el +++ b/lisp/ielm.el @@ -110,6 +110,13 @@ ielm-dynamic-multiline-inputs such as `edebug-defun' to work with such inputs." :type 'boolean) =20 +(defcustom ielm-history-file-name + (locate-user-emacs-file "ielm-history.eld") + "If non-nil, name of the file to read/write IELM input history." + :type '(choice (const :tag "Disable input history" nil) + file) + :version "30.1") + (defvaralias 'inferior-emacs-lisp-mode-hook 'ielm-mode-hook) (defcustom ielm-mode-hook nil "Hooks to be run when IELM (`inferior-emacs-lisp-mode') is started." @@ -503,6 +510,17 @@ ielm--expand-ellipsis (funcall pp-default-function beg end) end)) =20 +;;; Input history + +(defvar ielm--exit nil + "Function to call when Emacs is killed.") + +(defun ielm--input-history-writer (buf) + "Return a function writing IELM input history to BUF." + (lambda () + (with-current-buffer buf + (comint-write-input-ring)))) + ;;; Major mode =20 (define-derived-mode inferior-emacs-lisp-mode comint-mode "IELM" @@ -605,6 +623,17 @@ inferior-emacs-lisp-mode #'ielm-indirect-setup-hook 'append t) (setq comint-indirect-setup-function #'emacs-lisp-mode) =20 + ;; Input history + (setq-local comint-input-ring-file-name ielm-history-file-name) + (setq-local ielm--exit (ielm--input-history-writer (current-buffer))) + (setq-local kill-buffer-hook + (lambda () + (funcall ielm--exit) + (remove-hook 'kill-emacs-hook ielm--exit))) + (unless noninteractive + (add-hook 'kill-emacs-hook ielm--exit)) + (comint-read-input-ring t) + ;; A dummy process to keep comint happy. It will never get any input (unless (comint-check-proc (current-buffer)) ;; Was cat, but on non-Unix platforms that might not exist, so --=20 2.39.2 --=-=-=--