Subject: Re: bug#67000: 30.0.50; [PATCH] Add support for reading/writing IELM input history

From: Simen Heggestøyl <[email-masked]>
Date: Mon, 08 Jan 2024 08:30:35 +0100

Stefan Kangas <[email-masked]> writes:

> Simen Heggestøyl <[email-masked]> writes:
>
>>>> +(defvar ielm--history-file-name
>>>> +  (locate-user-emacs-file "ielm-history.el")
>>>
>>> Shouldn't that be .eld?
>>
>> Hm, the file will contain actual Lisp expressions, so I'd think that .el
>> is fitting?
>
> I'm not so sure.  We don't really intend for users to use it the way
> you'd expect from an .el file, like byte-compiling or loading it.
>
> So while these are, hopefully, valid Lisp expressions (barring typos,
> which frequently happens at a REPL), it's not really a file containing
> meaningful code either.

Okay, fair points. Updated patch attached!

-- Simen

>From a2322770acb6bceab36224989cbbe9b777312997 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <[email-masked]>
Date: Wed, 8 Nov 2023 16:08:08 +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.
---
 etc/NEWS     |  5 +++++
 lisp/ielm.el | 12 ++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index c3d777b971f..b62976143d2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1228,6 +1228,11 @@ chat buffers use by default.
 *** New command 'customize-dirlocals'.
 This command pops up a buffer to edit the settings in ".dir-locals.el".
 
+** IELM
+
+---
+*** IELM now remembers input history between sessions.
+
 
 * New Modes and Packages in Emacs 30.1
 
diff --git a/lisp/ielm.el b/lisp/ielm.el
index 777aebb70cf..6d4a11c1c28 100644
--- a/lisp/ielm.el
+++ b/lisp/ielm.el
@@ -152,6 +152,10 @@ ielm-header
 \\[describe-mode] for help.\n"
   "Message to display when IELM is started.")
 
+(defvar ielm--history-file-name
+  (locate-user-emacs-file "ielm-history.eld")
+  "Name of the file to read/write IELM input history.")
+
 (defvaralias 'inferior-emacs-lisp-mode-map 'ielm-map)
 (defvar-keymap ielm-map
   :doc "Keymap for IELM mode."
@@ -605,6 +609,11 @@ 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 kill-buffer-hook #'comint-write-input-ring)
+  (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
@@ -631,6 +640,9 @@ inferior-emacs-lisp-mode
     (set-marker comint-last-input-start (ielm-pm))
     (set-process-filter (get-buffer-process (current-buffer)) 'comint-output-filter)))
 
+(unless noninteractive
+  (add-hook 'kill-emacs-hook #'comint-write-input-ring))
+
 (defun ielm-get-old-input nil
   ;; Return the previous input surrounding point
   (save-excursion
-- 
2.39.2