1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

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).
This commit is contained in:
Daniel Martín 2020-12-14 17:16:00 +01:00 committed by Lars Ingebrigtsen
parent 10bc4eac5b
commit 0dd8d53344
4 changed files with 24 additions and 3 deletions

View file

@ -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

View file

@ -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.

View file

@ -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))

View file

@ -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))