@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
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.
(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)))))
+
\f
;; Behind display-popup-menus-p test.
(declare-function x-popup-dialog "menu.c" (position contents &optional header))
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))