From: Daniel Martín Date: Mon, 14 Dec 2020 16:16:00 +0000 (+0100) Subject: Make goto-char offer the number at point as default X-Git-Tag: emacs-28.0.90~4714 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0dd8d53344a822842660d2ac75108f40ba9ff0f4;p=emacs.git Make goto-char offer the number at point as default * lisp/subr.el (read-natnum-interactive): New function to read natural numbers for interactive functions. * src/editfns.c (Fgoto_char): Call read-natnum-interactive from the interactive definition of goto-char to offer the number at point as default. Also expand the docstring to document this new interactive behavior. * doc/emacs/basic.texi (Moving Point): Expand the Emacs manual to document this new behavior. * etc/NEWS: And announce it (bug#45199). --- diff --git a/doc/emacs/basic.texi b/doc/emacs/basic.texi index cd1ffbebd7c..77c80547462 100644 --- a/doc/emacs/basic.texi +++ b/doc/emacs/basic.texi @@ -310,7 +310,10 @@ Scroll one screen backward, and move point onscreen if necessary @kindex M-g c @findex goto-char Read a number @var{n} and move point to buffer position @var{n}. -Position 1 is the beginning of the buffer. +Position 1 is the beginning of the buffer. If point is on or just +after a number in the buffer, that is the default for @var{n}. Just +type @key{RET} in the minibuffer to use it. You can also specify +@var{n} by giving @kbd{M-g c} a numeric prefix argument. @item M-g M-g @itemx M-g g diff --git a/etc/NEWS b/etc/NEWS index a5e2c9cf26a..05274a2d6c6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -257,6 +257,10 @@ When 'widen-automatically' is non-nil, 'goto-line' widens the narrowed buffer to be able to move point to the inaccessible portion. 'goto-line-relative' is bound to 'C-x n g'. ++++ +** When called interactively, 'goto-char' now offers the number at +point as default. + +++ ** When 'suggest-key-bindings' is non-nil, the completion list of 'M-x' shows equivalent key bindings for all commands that have them. diff --git a/lisp/subr.el b/lisp/subr.el index ed235ee1f72..77c19c5bbf3 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2820,6 +2820,15 @@ There is no need to explicitly add `help-char' to CHARS; (message "%s%s" prompt (char-to-string char)) char)) +(defun goto-char--read-natnum-interactive (prompt) + "Get a natural number argument, optionally prompting with PROMPT. +If there is a natural number at point, use it as default." + (if (and current-prefix-arg (not (consp current-prefix-arg))) + (list (prefix-numeric-value current-prefix-arg)) + (let* ((number (number-at-point)) + (default (and (natnump number) number))) + (list (read-number prompt default))))) + ;; Behind display-popup-menus-p test. (declare-function x-popup-dialog "menu.c" (position contents &optional header)) diff --git a/src/editfns.c b/src/editfns.c index 4104edd77fd..e4c4141ef5e 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -188,11 +188,16 @@ DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0, return build_marker (current_buffer, PT, PT_BYTE); } -DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ", +DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, + "(goto-char--read-natnum-interactive \"Go to char: \")", doc: /* Set point to POSITION, a number or marker. Beginning of buffer is position (point-min), end is (point-max). -The return value is POSITION. */) +The return value is POSITION. + +If called interactively, a numeric prefix argument specifies +POSITION; without a numeric prefix argument, read POSITION from the +minibuffer. The default value is the number at point (if any). */) (register Lisp_Object position) { if (MARKERP (position))