all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Simen Heggestøyl via Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: 67000@debbugs.gnu.org, Eli Zaretskii <eliz@gnu.org>
Subject: bug#67000: 30.0.50; [PATCH] Add support for reading/writing IELM input history
Date: Wed, 07 Feb 2024 15:02:56 +0100	[thread overview]
Message-ID: <87sf24l6cv.fsf@runbox.com> (raw)
In-Reply-To: <CADwFkmkW=vO6Y-KrtVYVr9NwiMWgfjhK51qWBt2zzt=ge4gSKw@mail.gmail.com> (Stefan Kangas's message of "Sun, 28 Jan 2024 07:09:10 -0800")

[-- Attachment #1: Type: text/plain, Size: 3116 bytes --]

Hi Stefan, thanks for your feedback. An updated patch is attached.

Stefan Kangas <stefankangas@gmail.com> writes:

> Simen Heggestøyl <simenheg@runbox.com> 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


[-- Attachment #2: 0001-Add-support-for-reading-writing-IELM-input-history.patch --]
[-- Type: text/x-diff, Size: 3365 bytes --]

From fe91c4f3aaefc109135c48ba26f8f21e87db465e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= <simenheg@runbox.com>
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 ½ (U+00BD VULGAR FRACTION ONE 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.
 
+** 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.
+
 \f
 * New Modes and Packages in Emacs 30.1
 
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)
 
+(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))
 
+;;; 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
 
 (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)
+
   ;; 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
-- 
2.39.2


  reply	other threads:[~2024-02-07 14:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-08 15:11 bug#67000: 30.0.50; [PATCH] Add support for reading/writing IELM input history Simen Heggestøyl via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-15  1:06 ` Stefan Kangas
2024-01-04  7:46   ` Simen Heggestøyl via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-05 20:17     ` Stefan Kangas
2024-01-08  7:30       ` Simen Heggestøyl via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-08 19:51         ` Stefan Kangas
2024-01-12 16:09           ` Simen Heggestøyl via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-13  7:08             ` Stefan Kangas
2024-01-19  7:48               ` Simen Heggestøyl via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-28 15:09                 ` Stefan Kangas
2024-02-07 14:02                   ` Simen Heggestøyl via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-02-10 11:28                     ` Stefan Kangas
2024-02-15  7:53                       ` Simen Heggestøyl via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sf24l6cv.fsf@runbox.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=67000@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=simenheg@runbox.com \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.