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

From: Stefan Kangas <[email-masked]>
Date: Sat, 13 Jan 2024 01:08:49 -0600

Simen Heggestøyl <[email-masked]> writes:

>>> +(unless noninteractive
>>> +  (add-hook 'kill-emacs-hook #'comint-write-input-ring))
>>
>> I'm not so sure about this part.  If this is correct, why should it be
>> defined here, and not, say, in comint.el?  It seems like a separate,
>> unrelated change.  What am I missing?
>
> Usually comint-derived modes use a process sentinel to listen to some
> external process and call `comint-write-input-ring' when the process
> exists, which works both the buffer is killed or Emacs itself is quit.
>
> For IELM there is no such process to listen to, so I hook into
> `kill-buffer-hook' and `kill-emacs-hook' to achieve the same things.

I'm not against adding a hook to `kill-emacs-hook', but it should be
added when you start IELM and not on top-level.  We want to avoid any
side effects from merely loading a file.

I don't think this will work in its current form either: AFAICT,
`comint-write-input-ring' saves it for the current buffer, and that's
not guaranteed to be the *ielm* buffer when `kill-emacs-hook' runs.

So you'd want to first switch to that buffer, I think.  It could also
have been renamed meanwhile, so I think you want to save the actual
buffer and not it's name (i.e. use `get-buffer').