From fe78a75cc3d322b3b8f2df24d50dca1b1216d894 Mon Sep 17 00:00:00 2001 From: Madhu Date: Fri, 11 Oct 2024 21:16:46 +0530 Subject: [PATCH] fix some issues in the persistent ielm history mechanism MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this fixes some issues in commit 60cff1ac9d21. (bug 67000) * lisp/elm.el: (ielm-history-file-name): initially nil. (inferior-emacs-lisp-mode): do not invoke the machinery at all if ielm-history-file-name is nil. use add-hook on kill-buffer-hook instead of replacing kill-buffer-hook. bind coding-system-for-read around call to comint-read-input-ring. (ielm-input-history-writer): bind coding-system-on-write around call to comint-write-input-ring. --- lisp/ielm.el | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lisp/ielm.el b/lisp/ielm.el index f62db7510de..000ba48ba68 100644 --- a/lisp/ielm.el +++ b/lisp/ielm.el @@ -111,7 +111,8 @@ ielm-dynamic-multiline-inputs :type 'boolean) (defcustom ielm-history-file-name - (locate-user-emacs-file "ielm-history.eld") + (if t nil + (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) @@ -520,7 +521,9 @@ ielm--input-history-writer "Return a function writing IELM input history to BUF." (lambda () (with-current-buffer buf - (comint-write-input-ring)))) + (let ((coding-system-for-write 'utf-8-emacs-unix)) + ;; cannot add a file-local section when using comint. + (comint-write-input-ring))))) ;;; Major mode @@ -623,17 +626,19 @@ inferior-emacs-lisp-mode (add-hook 'comint-indirect-setup-hook #'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 + (when ielm-history-file-name + ;; Input history + (setq-local comint-input-ring-file-name ielm-history-file-name) + (setq-local ielm--exit (ielm--input-history-writer (current-buffer))) + (add-hook '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) + (remove-hook 'kill-emacs-hook ielm--exit)) + nil t) + (unless noninteractive + (add-hook 'kill-emacs-hook ielm--exit)) + (let ((coding-system-for-read 'utf-8-unix)) + (comint-read-input-ring t))) ;; A dummy process to keep comint happy. It will never get any input (unless (comint-check-proc (current-buffer)) -- 2.46.0.27.gfa3b914457