]> git.eshelyaron.com Git - emacs.git/commitdiff
Add support for reading/writing IELM input history (bug#67000)
authorSimen Heggestøyl <simenheg@runbox.com>
Tue, 16 Jan 2024 07:21:41 +0000 (08:21 +0100)
committerEshel Yaron <me@eshelyaron.com>
Thu, 15 Feb 2024 10:08:43 +0000 (11:08 +0100)
* lisp/ielm.el (inferior-emacs-lisp-mode): Add support for saving input
history to a file.
(ielm--history-file-name): New variable indicating IELM input history
file.
(ielm--exit): Holds a function to call when Emacs is killed to write
out the input history.
(ielm--input-history-writer): Helper function for writing the IELM
input history out to file.

* lisp/comint.el (comint-input-ring-file-name): Improve defcustom tag.

(cherry picked from commit 60cff1ac9d216e5abcb350ea5e623ab0b377c131)

etc/NEWS
lisp/comint.el
lisp/ielm.el

index 2c627512870345bdbc5e0e7ae98971b7f8458d01..35a78d90f496fe3f29dc2c09b51dbc8c97a92466 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1474,6 +1474,14 @@ characters, such as ½ (U+00BD VULGAR FRACTION ONE HALF), are also
 recognized as rational fractions.  They have been since 2004, but it
 looks like it was never mentioned in the NEWS, or even the manual.
 
+** IELM
+
+---
+*** IELM now remembers input history between sessions.
+The new user option 'ielm-history-file-name' is the name of the file
+where IELM input history will be saved.  Customize it to nil to revert
+to the old behavior of not remembering input history between sessions.
+
 \f
 * New Modes and Packages in Emacs 30.1
 
index 0a9cdb44bef40a9eb5a584195d22f32751ad9fa7..655ff30469c23563bae87cf9348fd65762316584 100644 (file)
@@ -254,7 +254,7 @@ This variable is buffer-local."
 See also `comint-read-input-ring' and `comint-write-input-ring'.
 `comint-mode' makes this a buffer-local variable.  You probably want
 to set this in a mode hook, rather than customize the default value."
-  :type '(choice (const :tag "nil" nil)
+  :type '(choice (const :tag "Disable input history" nil)
                 file)
   :group 'comint)
 
index 777aebb70cf62c9bc1a9b0ae95badd60996d4281..e583e0fe32ce2f0901c4f5e3dc2e0668e2b7184d 100644 (file)
@@ -110,6 +110,13 @@ This gives more frame width for large indented sexps, and allows functions
 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 "Disable input history" 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."
@@ -503,6 +510,17 @@ behavior of the indirect buffer."
     (funcall pp-default-function beg end)
     end))
 
+;;; Input history
+
+(defvar ielm--exit nil
+  "Function to call when Emacs is killed.")
+
+(defun ielm--input-history-writer (buf)
+  "Return a function writing IELM input history to BUF."
+  (lambda ()
+    (with-current-buffer buf
+      (comint-write-input-ring))))
+
 ;;; Major mode
 
 (define-derived-mode inferior-emacs-lisp-mode comint-mode "IELM"
@@ -605,6 +623,17 @@ Customized bindings may be defined in `ielm-map', which currently contains:
             #'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 ielm--exit (ielm--input-history-writer (current-buffer)))
+  (setq-local kill-buffer-hook
+              (lambda ()
+                (funcall ielm--exit)
+                (remove-hook 'kill-emacs-hook ielm--exit)))
+  (unless noninteractive
+    (add-hook 'kill-emacs-hook ielm--exit))
+  (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