]> git.eshelyaron.com Git - emacs.git/commitdiff
Save IELM input history on "C-c C-c"
authorEli Zaretskii <eliz@gnu.org>
Sat, 1 Mar 2025 08:27:17 +0000 (10:27 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 4 Mar 2025 20:57:03 +0000 (21:57 +0100)
* 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.

(cherry picked from commit cabbb36ae1d089e34c501c54a682ea7121899565)

lisp/ielm.el

index b3cd02b4dc0b8733d09e39be7c53520648ad969d..43529f36cd6f14b1c8379e3ae139a2efc61e39cd 100644 (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