unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: kwc3iywb@vfemail.net
To: Glenn Morris <rgm@gnu.org>
Cc: 27056@debbugs.gnu.org
Subject: bug#27056: 25.2; goto-line doesn't default to current line when used interactively when the cursor isn't over a number
Date: Thu, 25 May 2017 09:41:36 +0000	[thread overview]
Message-ID: <20170525094136.GA5685@vfemail.net> (raw)
In-Reply-To: <a0fufu9lp7.fsf@fencepost.gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 248 bytes --]

On Wed, May 24, 2017 at 02:03:16PM -0400, Glenn Morris wrote:
> kwc3iywb@vfemail.net wrote:
>
> > `read-number'.  I've included the patch I used to fix this problem.
>
> It looks to me like you attached an empty file?
>

Sorry.  Here is the patch.

[-- Attachment #1.2: 0001-Make-goto-line-default-to-current-line-when-cursor-i.patch --]
[-- Type: text/x-diff, Size: 3077 bytes --]

From 0317935b8af1701de3feb8d0469e5aea17b4f38a Mon Sep 17 00:00:00 2001
From: kwc3iywb <kwc3iywb@vfemail.net>
Date: Thu, 25 May 2017 02:07:18 +0000
Subject: [PATCH] Make goto-line default to current line when cursor isn't over
 a number

* lisp/simple.el (goto-line): When used interactively, default to
  current line if the cursor isn't over a number, and remain defaulting
  to the number under the cursor and putting the current line in the
  history when the cursor is over a number.

* lisp/subr.el (read-number): Add in its description that it can accept
  a list of default values.
---
 lisp/simple.el |  4 +++-
 lisp/subr.el   | 28 +++++++++++++---------------
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index ea3a495fbc..bd865288b1 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1157,7 +1157,9 @@ rather than line counts."
 	       "")))
        ;; 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)))
+			  (if default
+			      (list default (line-number-at-pos))
+			    (line-number-at-pos)))
 	     buffer))))
   ;; Switch to the desired buffer, one way or another.
   (if buffer
diff --git a/lisp/subr.el b/lisp/subr.el
index 8d5d2a779c..d9cb62b2db 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2312,25 +2312,23 @@ by doing (clear-string STRING)."
 (defun read-number (prompt &optional default)
   "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.
+The value of DEFAULT is inserted into PROMPT.  DEFAULT can also be a
+list of numbers, in which case all the numbers are available in the
+history, and the first is the default.
 This function is used by the `interactive' code letter `n'."
+  (if (not (listp default))
+      (setq default (list default)))
   (let ((n nil)
-	(default1 (if (consp default) (car default) default)))
-    (when default1
-      (setq prompt
-	    (if (string-match "\\(\\):[ \t]*\\'" prompt)
-		(replace-match (format " (default %s)" default1) t t prompt 1)
-	      (replace-regexp-in-string "[ \t]*\\'"
-					(format " (default %s) " default1)
-					prompt t t))))
+	(default1 (car default))
+	(default-str (mapcar 'number-to-string default)))
+    (when default
+	(cl-assert (string-match "\\(\\)\\(:[[:blank:]]*\\)?\\'" prompt))
+	(setq prompt (replace-match
+		      (format " (default %s)" (car default-str))
+		      t t prompt 1)))
     (while
 	(progn
-	  (let ((str (read-from-minibuffer
-		      prompt nil nil nil nil
-		      (when default
-			(if (consp default)
-			    (mapcar 'number-to-string (delq nil default))
-			  (number-to-string default))))))
+	  (let ((str (read-string prompt nil nil default-str)))
 	    (condition-case nil
 		(setq n (cond
 			 ((zerop (length str)) default1)
-- 
2.12.2


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2017-05-25  9:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 11:19 bug#27056: 25.2; goto-line doesn't default to current line when used interactively when the cursor isn't over a number kwc3iywb
2017-05-24 18:03 ` Glenn Morris
2017-05-25  2:29   ` kwc3iywb
2017-05-25  8:52   ` kwc3iywb
2017-05-25  9:41   ` kwc3iywb [this message]
2017-05-25 10:21   ` kwc3iywb
2017-05-27  2:38   ` kwc3iywb
2017-05-27 13:13 ` Eli Zaretskii
2017-05-28  8:11   ` kwc3iywb
2017-05-28  8:18   ` kwc3iywb
2017-05-28 15:03     ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=20170525094136.GA5685@vfemail.net \
    --to=kwc3iywb@vfemail.net \
    --cc=27056@debbugs.gnu.org \
    --cc=rgm@gnu.org \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).