From fdfb18c16d1d38a197bc1143d2704aefa7fe9daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= Date: Wed, 8 Nov 2023 16:08:08 +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. --- etc/NEWS | 11 +++++++++++ lisp/ielm.el | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index bce33f96aee..c20d34b39ad 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1243,6 +1243,17 @@ chat buffers use by default. *** New command 'customize-dirlocals'. This command pops up a buffer to edit the settings in ".dir-locals.el". +** IELM + +--- +*** 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. + * New Modes and Packages in Emacs 30.1 diff --git a/lisp/ielm.el b/lisp/ielm.el index 777aebb70cf..cfb51b7a94e 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 "nil" 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." @@ -605,6 +612,11 @@ 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 kill-buffer-hook #'comint-write-input-ring) + (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 @@ -631,6 +643,9 @@ inferior-emacs-lisp-mode (set-marker comint-last-input-start (ielm-pm)) (set-process-filter (get-buffer-process (current-buffer)) 'comint-output-filter))) +(unless noninteractive + (add-hook 'kill-emacs-hook #'comint-write-input-ring)) + (defun ielm-get-old-input nil ;; Return the previous input surrounding point (save-excursion -- 2.42.0