From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#67000: 30.0.50; [PATCH] Add support for reading/writing IELM input history Date: Sun, 28 Jan 2024 07:09:10 -0800 Message-ID: References: <87sf5ge0v6.fsf@runbox.com> <87a5pl1qym.fsf@runbox.com> <87y1d0p9ic.fsf@runbox.com> <874jfibkju.fsf@runbox.com> <87eded2270.fsf@runbox.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8606"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 67000@debbugs.gnu.org, Eli Zaretskii To: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 28 16:10:28 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 1rU6nk-0001zO-HT for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 28 Jan 2024 16:10:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rU6nJ-0008Fl-Gi; Sun, 28 Jan 2024 10:10:01 -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 1rU6nC-0008E4-V8 for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2024 10:09:55 -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 1rU6nC-0004v1-Mx for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2024 10:09:54 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rU6nK-0007nI-D3 for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2024 10:10:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 28 Jan 2024 15:10:02 +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.170645456829914 (code B ref 67000); Sun, 28 Jan 2024 15:10:02 +0000 Original-Received: (at 67000) by debbugs.gnu.org; 28 Jan 2024 15:09:28 +0000 Original-Received: from localhost ([127.0.0.1]:58188 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rU6ml-0007mP-QK for submit@debbugs.gnu.org; Sun, 28 Jan 2024 10:09:28 -0500 Original-Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]:53545) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rU6mj-0007m9-Gz for 67000@debbugs.gnu.org; Sun, 28 Jan 2024 10:09:26 -0500 Original-Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-55cc182da17so1828440a12.3 for <67000@debbugs.gnu.org>; Sun, 28 Jan 2024 07:09:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706454551; x=1707059351; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date :mime-version:references:in-reply-to:from:from:to:cc:subject:date :message-id:reply-to; bh=VYDWxn41aJTk6z9hpAy8mIU9HrzwMk38AymAtGx2rYU=; b=lJXL2dZQTYem5EG5m/W5fL8uVYyyULi+hKnzPW3AXSQGW+mzd1SKIJFVB5R20pdoXB aUmgj6qrH02IMaah35+7b57uNsboyGlBvPM2j/RyzQ7ZpnNHOst/KVgeoI9gJ4qN+4aF ahoVGW8sG7dPI2yNOzRbyoCg1XYb9zqDj8kj8ke6Ja1Se7sK+ToFiu6rZTXFQqMHgD+1 2gscrvLRzOyAT/FwP9FYXHtT8qpCG+3ankhjig0cpbojE8m+drouc/qhgA0lt/Qkj1YL kT882TphBSv8YgWK8Gg6g6xbg9H02WkVlbWwWbHkebO+54HDo/f7xp1unhd4/RZD6wMo weHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706454551; x=1707059351; h=content-transfer-encoding:cc:to:subject:message-id:date :mime-version:references:in-reply-to:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=VYDWxn41aJTk6z9hpAy8mIU9HrzwMk38AymAtGx2rYU=; b=YXd87Sa9yxTUak4ZeAj2JBsF6Os7C3MNUTD/DfSd7zF9aY/QSxRUpW67lm5cNqbG5C U4TjnvhnUSOt8yRYVdiz1ljhu/YzuqUFYehoHAlZo6V8WMd7Q4fxw+Diyy9dnAPp54uD 2RYL2yuS9RHvrQYl8j5gj2hirZ5Cav4joKuc1q38lAdJ48gBvq82ktOfsPOmmmIVke8W BwlXja4neHMocveeIkUMEWPsDD2t/7oOzxD+xS2zoTlT2Xfh2govZPg6877Xeg5AU/TF 4km8joN6viAqcLc29IkkEK48Wc5EW3Mq3hLtLgM+ot6/04Ax3B3j9jQqpj7lmS95awOc 9ReQ== X-Gm-Message-State: AOJu0Yxe3P0ArN4H7FnFAk1R9NhPE/rSIBJJQg5sXfvfSffcGawhKkLl PZJcV2rdSI8KC1U+BdX43nqbTPeToRlmTiZW9TAJv4q0LYArUbJWgRGZ92atxuhhDmvaNnrJmMI 3yFIhqk4TdZscwCgsGDpMo12WKRE= X-Google-Smtp-Source: AGHT+IHB3AUGkb3xkRLvpyGeKbCLuTJFs6+cF1EGfm0qvqpeW+5D788OBpGFx13aGj/JYfAWvFA4ekzLzI0ht8JlC6E= X-Received: by 2002:a05:6402:2692:b0:55c:85be:f280 with SMTP id w18-20020a056402269200b0055c85bef280mr2663898edd.9.1706454551099; Sun, 28 Jan 2024 07:09:11 -0800 (PST) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sun, 28 Jan 2024 07:09:10 -0800 In-Reply-To: <87eded2270.fsf@runbox.com> 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:279090 Archived-At: Simen Heggest=C3=B8yl writes: > Right, good catch. New attempt in the attached patch! Thanks, please find some comments below. > +--- > +*** 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. I would probably make this into one entry, like so: *** 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. > +(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) The tag here should be "Disable input history" or something like that. > + 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 @@ ielm--expand-ellipsis > (funcall pp-default-function beg end) > end)) > > +;;; Input history > + > +(defvar ielm--exit This should read (defvar ielm--exit nil or the below docstring will instead be its value. > + "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 @@ 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 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) There are some complications here: You can get more than one IELM buffer using M-x ielm RET M-x rename-buffer RET foo RET M-x ielm RET What happens if there is more than one IELM buffer? It will save only the history from the last one, or something like that? Perhaps the kill-emacs-hook should look for all buffers that are using `ielm-mode' and save the history from all of them? > + > ;; 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 > -- > 2.39.2 > > > -- Simen