Save IELM input history on "C-c C-c"

* lisp/ielm.el (ielm--write-history-on-interrupt): New function.
(inferior-emacs-lisp-mode): Install it as buffer-local value of
the 'interrupt-process-functions' hook.  (Bug#76585)

* etc/NEWS: Announce the behavior change.
This commit is contained in:
Eli Zaretskii 2025-03-01 10:27:17 +02:00
parent 61320784ed
commit cabbb36ae1
2 changed files with 18 additions and 1 deletions

View file

@ -918,6 +918,14 @@ for docstrings where symbols 'nil' and 't' are in quotes.
In most cases, having it enabled leads to a large amount of false
positives.
** IELM
---
*** IELM input history is now saved also when the IELM process is killed.
When you kill the IELM process with "C-c C-c", the input history is now
saved to the file specified by 'ielm-history-file-name', just like when
you exit the Emacs session or kill the IELM buffer.
** DocView
---

View file

@ -521,6 +521,12 @@ behavior of the indirect buffer."
(with-current-buffer buf
(comint-write-input-ring))))
(defun ielm--write-history-on-interrupt (_proc _group)
"Save the IELM input history when the process is interrupted."
(funcall (ielm--input-history-writer (current-buffer)))
;; Let the rest of the hook functions run as well.
nil)
;;; Major mode
(define-derived-mode inferior-emacs-lisp-mode comint-mode "IELM"
@ -658,7 +664,10 @@ Customized bindings may be defined in `ielm-map', which currently contains:
'(rear-nonsticky t field output inhibit-line-move-field-capture t))))
(comint-output-filter (ielm-process) ielm-prompt-internal)
(set-marker comint-last-input-start (ielm-pm))
(set-process-filter (get-buffer-process (current-buffer)) 'comint-output-filter)))
(set-process-filter (get-buffer-process (current-buffer))
'comint-output-filter)
(add-hook 'interrupt-process-functions
#'ielm--write-history-on-interrupt -1 t)))
(defun ielm-get-old-input nil
;; Return the previous input surrounding point