Subject: Re: bug#38282: 26.3; goto-line should not share input history with other commands

From: Federico Tedin <[email-masked]>
Date: Fri, 06 Dec 2019 23:14:15 +0100

> I think it makes sense for read-number to use its own history variable,
> but it should not be buffer local.  Most inputs are not naturally buffer
> local.

No problem - I've added an input history variable for `read-number', and
a buffer-local one for `goto-line'. I'm attaching a patch with my
changes.

- Fede

>From 249ccb59be23d94018a01b4f8b1577356732d1da Mon Sep 17 00:00:00 2001
From: Federico Tedin <[email-masked]>
Date: Fri, 6 Dec 2019 23:07:27 +0100
Subject: [PATCH 1/1] Make goto-line keep a separate input history per buffer

* lisp/simple.el (goto-line-history): New history variable.
(goto-line): Use new (buffer-local) variable as input history.
* lisp/subr.el (read-number-history): New history variable.
(read-number): Use the new variable as default input history.
---
 lisp/simple.el | 7 ++++++-
 lisp/subr.el   | 9 +++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 67ddab3d34..c14718de1c 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1212,6 +1212,10 @@ mark-whole-buffer
 
 ;; Counting lines, one way or another.
 
+(defvar goto-line-history nil
+  "History of values entered with `goto-line'.")
+(make-variable-buffer-local 'goto-line-history)
+
 (defun goto-line (line &optional buffer)
   "Go to LINE, counting from line 1 at beginning of buffer.
 If called interactively, a numeric prefix argument specifies
@@ -1256,7 +1260,8 @@ goto-line
 	       "")))
        ;; Read the argument, offering that number (if any) as default.
        (list (read-number (format "Goto line%s: " buffer-prompt)
-                          (list default (line-number-at-pos)))
+                          (list default (line-number-at-pos))
+                          'goto-line-history)
 	     buffer))))
   ;; Switch to the desired buffer, one way or another.
   (if buffer
diff --git a/lisp/subr.el b/lisp/subr.el
index de7d919abf..8f7a9128fa 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2518,10 +2518,15 @@ read-passwd
               ;; And of course, don't keep the sensitive data around.
               (erase-buffer))))))))
 
-(defun read-number (prompt &optional default)
+(defvar read-number-history nil
+  "The default history for the `read-number' function.")
+
+(defun read-number (prompt &optional default hist)
   "Read a numeric value in the minibuffer, prompting with PROMPT.
 DEFAULT specifies a default value to return if the user just types RET.
 The value of DEFAULT is inserted into PROMPT.
+HIST specifies a history list variable.  See `read-from-minibuffer'
+for details of the HIST argument.
 This function is used by the `interactive' code letter `n'."
   (let ((n nil)
 	(default1 (if (consp default) (car default) default)))
@@ -2535,7 +2540,7 @@ read-number
     (while
 	(progn
 	  (let ((str (read-from-minibuffer
-		      prompt nil nil nil nil
+		      prompt nil nil nil (or hist 'read-number-history)
 		      (when default
 			(if (consp default)
 			    (mapcar 'number-to-string (delq nil default))
-- 
2.17.1