unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Unknown <unknown@unknown.invalid>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 45199@debbugs.gnu.org
Subject: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at point as default
Date: Sun, 13 Dec 2020 02:23:13 +0100	[thread overview]
Message-ID: <m1ft4a8poe.fsf@yahoo.es> (raw)
In-Reply-To: <87o8iy975l.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sat, 12 Dec 2020 20:05:42 +0100")

[-- Attachment #1: Type: text/plain, Size: 471 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> writes:
>
> I think it would be better to put this in a helper function in subr.el,
> for instance.
>
> And there's also `number-at-point', could perhaps be used here?

Oh, I forgot about number-at-point.  It extracts numbers that don't make
sense here (like floating point or negative numbers), but we can easily
filter them with natnump.  I've attached a new patch; do you feel it's
still necessary to extract the logic in a helper?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-goto-char-offer-the-number-at-point-as-default.patch --]
[-- Type: text/x-patch, Size: 3065 bytes --]

From 499618f25e78cb1ab9803e44123b249b40b9d4eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <mardani29@yahoo.es>
Date: Sat, 12 Dec 2020 17:10:05 +0100
Subject: [PATCH] Make goto-char offer the number at point as default

* src/editfns.c (Fgoto_char): Expand the interactive definition of
goto-char to offer the number at point as default.  Note that only
numbers that make sense as character positions will be offered.  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.
---
 doc/emacs/basic.texi |  5 ++++-
 etc/NEWS             |  4 ++++
 src/editfns.c        | 13 +++++++++++--
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/doc/emacs/basic.texi b/doc/emacs/basic.texi
index cd1ffbebd7..77c8054746 100644
--- a/doc/emacs/basic.texi
+++ b/doc/emacs/basic.texi
@@ -310,7 +310,10 @@ Moving Point
 @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 514209516d..13ff0bb171 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/src/editfns.c b/src/editfns.c
index 4104edd77f..a6f9d30a7c 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -188,11 +188,20 @@ 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,
+         "(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 \"Goto char: \" default))))",
        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.  */)
   (register Lisp_Object position)
 {
   if (MARKERP (position))
-- 
2.28.0


  reply	other threads:[~2020-12-13  1:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <m1h7orj7uw.fsf.ref@yahoo.es>
2020-12-12 16:40 ` bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at point as default Unknown
2020-12-12 19:05   ` Lars Ingebrigtsen
2020-12-13  1:23     ` Unknown [this message]
2020-12-13 13:14       ` Lars Ingebrigtsen
2020-12-13 18:01         ` Unknown
2020-12-14 10:16           ` Robert Pluim
2020-12-14 16:17           ` Lars Ingebrigtsen
2020-12-14 19:29           ` Juri Linkov
2020-12-15  6:30             ` Lars Ingebrigtsen
2020-12-20  8:55               ` Juri Linkov
2020-12-20 17:55                 ` Lars Ingebrigtsen
2020-12-20 20:06                   ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1ft4a8poe.fsf@yahoo.es \
    --to=unknown@unknown.invalid \
    --cc=45199@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).