From fbc9c59b9eb02d49f426341ee32334784d224ce4 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Wed, 17 Feb 2021 21:15:51 +0000 Subject: [PATCH] Make goto-line-history buffer local only when so customized * lisp/simple.el (goto-line-history-local): New customizable option. (goto-line-history): Define this simply with defvar, not defvar-local. (goto-line-read-args): Handle goto-line-history-local, and changes to it. * doc/emacs/basic.texi (Moving Point): Add a paragraph about goto-line-history-local. * etc/NEWS: Add an item under "Editing Changes in Emacs 28.1". --- doc/emacs/basic.texi | 5 +++++ etc/NEWS | 5 +++++ lisp/simple.el | 19 ++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/emacs/basic.texi b/doc/emacs/basic.texi index 8bf52d5dd30..4a34fd36c5d 100644 --- a/doc/emacs/basic.texi +++ b/doc/emacs/basic.texi @@ -331,6 +331,11 @@ a plain prefix argument. Alternatively, you can use the command @code{goto-line-relative} to move point to the line relative to the accessible portion of the narrowed buffer. +@code{goto-line} has its own history list (@pxref{Minibuffer +History}). You can have either a single list shared between all +buffers (the default) or a separate list for each buffer, by +customizing the user option @code{goto-line-history-local}. + @item M-g @key{TAB} @kindex M-g TAB @findex move-to-column diff --git a/etc/NEWS b/etc/NEWS index b96bcd9eccd..7665d4740f9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -345,6 +345,11 @@ trying to be non-destructive. This command opens a new buffer called "*Memory Report*" and gives a summary of where Emacs is using memory currently. ++++ +** The history list for the 'goto-line' command is now a single list +for all buffers by default. You can configure a separate list for +each buffer by customizing the user option 'goto-line-history-local'. + ** Outline +++ diff --git a/lisp/simple.el b/lisp/simple.el index e54cbed7a76..363a0f26d5d 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -1278,7 +1278,19 @@ that uses or sets the mark." ;; Counting lines, one way or another. -(defvar-local goto-line-history nil +(defcustom goto-line-history-local nil + "If this option is nil, `goto-line-history' is shared between all buffers. +if it is non-nil, each buffer has its own value of this history list. + +Note that on changing from non-nil to nil, the former contents of +`goto-line-history' for each buffer are discarded on use of +`goto-line' in that buffer." + :group 'editing + :type 'boolean + :safe #'booleanp + :version "28.1") + +(defvar goto-line-history nil "History of values entered with `goto-line'.") (defun goto-line-read-args (&optional relative) @@ -1296,6 +1308,11 @@ that uses or sets the mark." (if buffer (concat " in " (buffer-name buffer)) ""))) + ;; Has the buffer locality of `goto-line-history' changed? + (cond ((and goto-line-history-local (not (local-variable-p 'goto-line-history))) + (make-local-variable 'goto-line-history)) + ((and (not goto-line-history-local) (local-variable-p 'goto-line-history)) + (kill-local-variable 'goto-line-history))) ;; Read the argument, offering that number (if any) as default. (list (read-number (format "Goto%s line%s: " (if (buffer-narrowed-p) -- 2.39.2