all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Federico Tedin <federicotedin@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 38282@debbugs.gnu.org, Robert Pluim <rpluim@gmail.com>,
	Michael Albinus <michael.albinus@gmx.de>
Subject: bug#38282: 26.3; goto-line should not share input history with other commands
Date: Thu, 21 Nov 2019 23:06:14 +0100	[thread overview]
Message-ID: <87a78olwa1.fsf@gmail.com> (raw)
In-Reply-To: <87imndkr3f.fsf@gmail.com> (Federico Tedin's message of "Thu, 21 Nov 2019 19:43:32 +0100")

[-- Attachment #1: Type: text/plain, Size: 472 bytes --]

> It seems like `read-from-minibuffer' doesn't like having its HIST
> parameter be buffer-local (but I may have misunderstood the problem).
> I'm going to look into it more on depth these days.

Here's my first attempt at implementing this - I managed to get around
the `read-from-minibuffer' problem with some help from the Emacs
StackOverflow (but created a separate bug report for it:
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=38317). I'm attaching a
small patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2882 bytes --]

From 3994fa53d0cf210e7f109dc2059ee78a96215547 Mon Sep 17 00:00:00 2001
From: Federico Tedin <federicotedin@gmail.com>
Date: Thu, 21 Nov 2019 23:01:23 +0100
Subject: [PATCH 1/1] Make input history buffer-local for 'goto-line'

* lisp/simple.el (goto-line-history): New buffer-local variable which
holds the input history for 'goto-line'.
(goto-line): Use the new variable as input history (Bug#38282).
* etc/NEWS: Announce changes.
---
 etc/NEWS       |  5 +++++
 lisp/simple.el | 19 +++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 7a51106add..0bbb40dfa2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -589,6 +589,11 @@ If the region is active, the command joins all the lines in the
 region.  When there's no active region, the command works on the
 current and the previous or the next line, as before.
 
+---
+** 'goto-line' now keeps a separate input history for each buffer.
+Additionally, the line number input history will be kept separate from
+the input history for other commands.
+
 \f
 * Changes in Specialized Modes and Packages in Emacs 27.1
 
diff --git a/lisp/simple.el b/lisp/simple.el
index c61ccd511c..dd8e8a291a 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1212,6 +1212,11 @@ mark-whole-buffer
 
 ;; Counting lines, one way or another.
 
+(defvar goto-line-history nil
+  "Input history for `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
@@ -1253,7 +1258,14 @@ goto-line
 	    (buffer-prompt
 	     (if buffer
 		 (concat " in " (buffer-name buffer))
-	       "")))
+	       ""))
+            ;; It would be better to use `goto-line-history' as a HIST
+            ;; parameter to `read-from-minibuffer' (through
+            ;; `read-number'), but using buffer-local variables
+            ;; doesn't work for that purpose. (Bug#38317)
+            (minibuffer-history
+             (buffer-local-value 'goto-line-history (or buffer
+                                                        (current-buffer)))))
        ;; 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)))
@@ -1271,7 +1283,10 @@ goto-line
     (goto-char (point-min))
     (if (eq selective-display t)
 	(re-search-forward "[\n\C-m]" nil 'end (1- line))
-      (forward-line (1- line)))))
+      (forward-line (1- line))))
+  ;; Save the line number in the input history list.
+  (with-current-buffer (or buffer (current-buffer))
+    (add-to-history 'goto-line-history (int-to-string line))))
 
 (defun count-words-region (start end &optional arg)
   "Count the number of words in the region.
-- 
2.17.1


  reply	other threads:[~2019-11-21 22:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-19 21:48 bug#38282: 26.3; goto-line should not share input history with other commands Federico Tedin
2019-11-21 13:51 ` Lars Ingebrigtsen
2019-11-21 14:41   ` Robert Pluim
2019-11-21 15:20     ` Michael Albinus
2019-11-21 17:51       ` Lars Ingebrigtsen
2019-11-21 18:43         ` Federico Tedin
2019-11-21 22:06           ` Federico Tedin [this message]
2019-11-22  7:35             ` Eli Zaretskii
2019-11-22 12:09             ` Lars Ingebrigtsen
2019-11-23 17:05               ` Federico Tedin
2019-11-27 11:48                 ` Lars Ingebrigtsen
2019-12-06 22:14                   ` Federico Tedin
2019-12-14 11:44                     ` Eli Zaretskii
2019-12-17 21:19                       ` Federico Tedin
2019-12-24 16:39                         ` Lars Ingebrigtsen
2019-12-24 23:21                           ` Federico Tedin
2019-11-22  7:57         ` Michael Albinus
2019-11-22  8:40           ` Robert Pluim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a78olwa1.fsf@gmail.com \
    --to=federicotedin@gmail.com \
    --cc=38282@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=michael.albinus@gmx.de \
    --cc=rpluim@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.