From cabbb36ae1d089e34c501c54a682ea7121899565 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 1 Mar 2025 10:27:17 +0200 Subject: [PATCH] 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. --- etc/NEWS | 8 ++++++++ lisp/ielm.el | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index 0867822a7d8..2a973b77827 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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 --- diff --git a/lisp/ielm.el b/lisp/ielm.el index b3cd02b4dc0..43529f36cd6 100644 --- a/lisp/ielm.el +++ b/lisp/ielm.el @@ -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