From 0317935b8af1701de3feb8d0469e5aea17b4f38a Mon Sep 17 00:00:00 2001 From: kwc3iywb 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