From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67000: 30.0.50; [PATCH] Add support for reading/writing IELM input history Date: Fri, 12 Jan 2024 17:09:25 +0100 Message-ID: <874jfibkju.fsf@runbox.com> References: <87sf5ge0v6.fsf@runbox.com> <87a5pl1qym.fsf@runbox.com> <87y1d0p9ic.fsf@runbox.com> Reply-To: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11810"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 67000@debbugs.gnu.org, Eli Zaretskii To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jan 12 17:10:32 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rOK75-0002q3-GL for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 Jan 2024 17:10:31 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rOK6j-0007VI-Eq; Fri, 12 Jan 2024 11:10:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rOK6e-0007Ux-Sb for bug-gnu-emacs@gnu.org; Fri, 12 Jan 2024 11:10:05 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rOK6e-0000pA-7C for bug-gnu-emacs@gnu.org; Fri, 12 Jan 2024 11:10:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rOK6c-0002oW-0A for bug-gnu-emacs@gnu.org; Fri, 12 Jan 2024 11:10:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 12 Jan 2024 16:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67000 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 67000-submit@debbugs.gnu.org id=B67000.170507579410795 (code B ref 67000); Fri, 12 Jan 2024 16:10:01 +0000 Original-Received: (at 67000) by debbugs.gnu.org; 12 Jan 2024 16:09:54 +0000 Original-Received: from localhost ([127.0.0.1]:37345 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rOK6U-0002o2-3x for submit@debbugs.gnu.org; Fri, 12 Jan 2024 11:09:54 -0500 Original-Received: from mailtransmit04.runbox.com ([2a0c:5a00:149::25]:43708) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rOK6S-0002nk-5K for 67000@debbugs.gnu.org; Fri, 12 Jan 2024 11:09:53 -0500 Original-Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1rOK6M-004gTe-F9 for 67000@debbugs.gnu.org; Fri, 12 Jan 2024 17:09:46 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector1; h=Content-Type:MIME-Version:Message-ID:Date:References: In-Reply-To:Subject:Cc:To:From; bh=KSvDFEhXcPnQuniQbaxyMHBCdOnpBhxuScmZtqD9yH0=; b=bc9xdgY7VsAB4pA1J3vDF9M/ZS GxC3KtoIdRQYPxRUuLdEqRzR8aP7QF2yoXrGde0uRCi2sVueFKlFTsqXFNpz6VPs/E5TpJE+3TN6b Bw4XKDCIYEuVdGaaH66kwvgok1E5LmiKxrHrNomypLGI4eHJ9tx+q9J9UTGAM2n80bHU7V2Dvr5GD YGgCUNCBpTDg52tuyALcRFEYrxiSul82xbmAr8QoIvm37X7BRf8gmbNtZbfuQwQ7ocVYbHiPmg+gL E/Si8y2D6a+Ra0g3s6CsNGayvynn5/KS+j0l5leqfDc+XXsry2BGVy5ix06Mg3io5jysXup3FRoq0 i9hEyKCA==; Original-Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1rOK6L-0004Ye-DU; Fri, 12 Jan 2024 17:09:45 +0100 Original-Received: by submission01.runbox with esmtpsa [Authenticated ID (963757)] (TLS1.2:ECDHE_SECP256R1__RSA_SHA256__AES_256_GCM:256) (Exim 4.93) id 1rOK62-00FtKM-Kg; Fri, 12 Jan 2024 17:09:26 +0100 In-Reply-To: (Stefan Kangas's message of "Mon, 8 Jan 2024 11:51:39 -0800") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:278047 Archived-At: --=-=-= Content-Type: text/plain Stefan Kangas writes: > On closer thought, I think this should be a defcustom. > > See `lua-ts-inferior-history' and `sql-input-ring-file-name' for > example. > > I also think nil might as well be a valid value which disables history > altogether (maybe users don't want that for some reason, let's say > privacy or whatever). > > And the defcustom should be mentioned in NEWS, too. Thanks, makes sense. Updated in the attached patch! >> (defvaralias 'inferior-emacs-lisp-mode-map 'ielm-map) >> (defvar-keymap ielm-map >> :doc "Keymap for IELM mode." >> @@ -605,6 +609,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 +640,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)) >> + > > I'm not so sure about this part. If this is correct, why should it be > defined here, and not, say, in comint.el? It seems like a separate, > unrelated change. What am I missing? Usually comint-derived modes use a process sentinel to listen to some external process and call `comint-write-input-ring' when the process exists, which works both the buffer is killed or Emacs itself is quit. For IELM there is no such process to listen to, so I hook into `kill-buffer-hook' and `kill-emacs-hook' to achieve the same things. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Add-support-for-reading-writing-IELM-input-history.patch >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 --=-=-= Content-Type: text/plain -- Simen --=-=-=--