[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 0dd8d53: Make goto-char offer the number at point as default
From: |
Lars Ingebrigtsen |
Subject: |
master 0dd8d53: Make goto-char offer the number at point as default |
Date: |
Mon, 14 Dec 2020 11:16:47 -0500 (EST) |
branch: master
commit 0dd8d53344a822842660d2ac75108f40ba9ff0f4
Author: Daniel MartÃn <mardani29@yahoo.es>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
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).
---
doc/emacs/basic.texi | 5 ++++-
etc/NEWS | 4 ++++
lisp/subr.el | 9 +++++++++
src/editfns.c | 9 +++++++--
4 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/doc/emacs/basic.texi b/doc/emacs/basic.texi
index cd1ffbe..77c8054 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 a5e2c9c..05274a2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -258,6 +258,10 @@ 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 ed235ee..77c19c5 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 4104edd..e4c4141 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))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 0dd8d53: Make goto-char offer the number at point as default,
Lars Ingebrigtsen <=