GNU bug report logs - #45199
28.0.50; [PATCH] Make goto-char offer the number at point as default

Previous Next

Package: emacs;

Reported by: Daniel Martín <mardani29 <at> yahoo.es>

Date: Sat, 12 Dec 2020 18:21:02 UTC

Severity: normal

Tags: confirmed, fixed, patch

Found in version 28.0.50

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45199 in the body.
You can then email your comments to 45199 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Sat, 12 Dec 2020 18:21:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daniel Martín <mardani29 <at> yahoo.es>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 12 Dec 2020 18:21:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Martín <mardani29 <at> yahoo.es>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.0.50; [PATCH] Make goto-char offer the number at point as default
Date: Sat, 12 Dec 2020 17:40:23 +0100
[Message part 1 (text/plain, inline)]
My use case (there may be many) comes from working with PDFs at a low
level.  If you open a PDF file in fundamental-mode, towards the end of
the file you'll see text that resembles the following:

xref
0 26
0000000000 65535 f 
0000006459 00000 n 

This is a table where the first column contains file offsets that point
to where the PDF objects are defined.  I wanted to place the point on
the "0000006459", do M-g c, and easily go to file offset 6459 to see the
definition of the PDF object number 1 ("1 0 obj").  goto-char is useful
here because PDF files are open as unibyte in Emacs.

If you also find the behavior generally useful, feel free to install it
for Emacs 28.

Thanks.

[0001-Make-goto-char-offer-the-number-at-point-as-default.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Sat, 12 Dec 2020 19:06:02 GMT) Full text and rfc822 format available.

Message #8 received at 45199 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Daniel Martín <mardani29 <at> yahoo.es>
Cc: 45199 <at> debbugs.gnu.org
Subject: Re: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at
 point as default
Date: Sat, 12 Dec 2020 20:05:42 +0100
Daniel Martín <mardani29 <at> yahoo.es> writes:

> * src/editfns.c (Fgoto_char): Expand the interactive definition of
> goto-char to offer the number at point as default.

I think this makes sense, but:

> -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* ((default\
> +	             (save-excursion\
> +	               (skip-chars-backward \"0-9\")\
> +	               (if (looking-at-p \"[0-9]\")\
> +	                   (string-to-number\
> +	                   (buffer-substring-no-properties\
> +	                   (point)\
> +	                   (progn (skip-chars-forward \"0-9\")\
> +		                  (point))))))))\
> +              (list (read-number \"Goto char: \" default))))",

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?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Sun, 13 Dec 2020 01:24:02 GMT) Full text and rfc822 format available.

Message #11 received at 45199 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Martín <mardani29 <at> yahoo.es>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 45199 <at> debbugs.gnu.org
Subject: Re: 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
[Message part 1 (text/plain, inline)]
Lars Ingebrigtsen <larsi <at> 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?

[0001-Make-goto-char-offer-the-number-at-point-as-default.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Sun, 13 Dec 2020 13:15:02 GMT) Full text and rfc822 format available.

Message #14 received at 45199 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Daniel Martín <mardani29 <at> yahoo.es>
Cc: 45199 <at> debbugs.gnu.org
Subject: Re: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at
 point as default
Date: Sun, 13 Dec 2020 14:14:19 +0100
Daniel Martín <mardani29 <at> yahoo.es> writes:

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

Yeah, I'd still rather have a helper function -- putting several lines
of Lisp code in a string in C isn't optimal.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Sun, 13 Dec 2020 18:02:01 GMT) Full text and rfc822 format available.

Message #17 received at 45199 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Martín <mardani29 <at> yahoo.es>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 45199 <at> debbugs.gnu.org
Subject: Re: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at
 point as default
Date: Sun, 13 Dec 2020 19:01:24 +0100
[Message part 1 (text/plain, inline)]
Lars Ingebrigtsen <larsi <at> gnus.org> writes:
>
> Yeah, I'd still rather have a helper function -- putting several lines
> of Lisp code in a string in C isn't optimal.

OK, done.

[0001-Make-goto-char-offer-the-number-at-point-as-default.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Mon, 14 Dec 2020 10:17:02 GMT) Full text and rfc822 format available.

Message #20 received at 45199 <at> debbugs.gnu.org (full text, mbox):

From: Robert Pluim <rpluim <at> gmail.com>
To: Daniel Martín <mardani29 <at> yahoo.es>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 45199 <at> debbugs.gnu.org
Subject: Re: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at
 point as default
Date: Mon, 14 Dec 2020 11:16:29 +0100
Daniel Martín <mardani29 <at> yahoo.es> writes:

> Lars Ingebrigtsen <larsi <at> gnus.org> writes:
>>
>> Yeah, I'd still rather have a helper function -- putting several lines
>> of Lisp code in a string in C isn't optimal.
>
> OK, done.
>

The docstring for the function needs to mention the new behaviour as
well.

Robert




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Mon, 14 Dec 2020 16:18:02 GMT) Full text and rfc822 format available.

Message #23 received at 45199 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Daniel Martín <mardani29 <at> yahoo.es>
Cc: 45199 <at> debbugs.gnu.org
Subject: Re: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at
 point as default
Date: Mon, 14 Dec 2020 17:17:29 +0100
Daniel Martín <mardani29 <at> yahoo.es> writes:

> Lars Ingebrigtsen <larsi <at> gnus.org> writes:
>>
>> Yeah, I'd still rather have a helper function -- putting several lines
>> of Lisp code in a string in C isn't optimal.
>
> OK, done.

Great; I've now applied this to Emacs 28 (but made the helper function
an internal function, and altered the doc string like Robert suggested).

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) confirmed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 14 Dec 2020 16:18:03 GMT) Full text and rfc822 format available.

Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 14 Dec 2020 16:19:01 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 45199 <at> debbugs.gnu.org and Daniel Martín <mardani29 <at> yahoo.es> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 14 Dec 2020 16:19:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Mon, 14 Dec 2020 19:58:01 GMT) Full text and rfc822 format available.

Message #32 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Daniel Martín via "Bug reports for GNU Emacs, the
 Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 45199 <at> debbugs.gnu.org,
 Daniel Martín <mardani29 <at> yahoo.es>
Subject: Re: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at
 point as default
Date: Mon, 14 Dec 2020 21:29:08 +0200
>> Yeah, I'd still rather have a helper function -- putting several lines
>> of Lisp code in a string in C isn't optimal.
>
> OK, done.

Shouldn't goto-line use the same function to read a number?
The first version of your patch used the code similar to
goto-line-read-args, so wouldn't it make sense to use the
new function in goto-line-read-args as well?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Mon, 14 Dec 2020 19:58:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Tue, 15 Dec 2020 06:32:01 GMT) Full text and rfc822 format available.

Message #38 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: "Daniel Martín via Bug reports for GNU Emacs, the Swiss
 army knife of text editors" <bug-gnu-emacs <at> gnu.org>, 45199 <at> debbugs.gnu.org,
 Daniel Martín <mardani29 <at> yahoo.es>
Subject: Re: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at
 point as default
Date: Tue, 15 Dec 2020 07:30:57 +0100
Juri Linkov <juri <at> linkov.net> writes:

>>> Yeah, I'd still rather have a helper function -- putting several lines
>>> of Lisp code in a string in C isn't optimal.
>>
>> OK, done.
>
> Shouldn't goto-line use the same function to read a number?
> The first version of your patch used the code similar to
> goto-line-read-args, so wouldn't it make sense to use the
> new function in goto-line-read-args as well?

Reusing it directly would be awkward, but goto-line-read-args could
indeed use number-at-point.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Tue, 15 Dec 2020 06:32:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Sun, 20 Dec 2020 08:59:02 GMT) Full text and rfc822 format available.

Message #44 received at 45199 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 45199 <at> debbugs.gnu.org
Subject: Re: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at
 point as default
Date: Sun, 20 Dec 2020 10:55:33 +0200
[Message part 1 (text/plain, inline)]
>> Shouldn't goto-line use the same function to read a number?
>> The first version of your patch used the code similar to
>> goto-line-read-args, so wouldn't it make sense to use the
>> new function in goto-line-read-args as well?
>
> Reusing it directly would be awkward, but goto-line-read-args could
> indeed use number-at-point.

Here's a patch where it uses number-at-point:

[goto-line-read-args-number-at-point.patch (text/x-diff, inline)]
diff --git a/lisp/simple.el b/lisp/simple.el
index f79543058b..e17f2b0fc2 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1276,15 +1276,8 @@ goto-line-read-args
   (if (and current-prefix-arg (not (consp current-prefix-arg)))
       (list (prefix-numeric-value current-prefix-arg))
     ;; Look for a default, a number in the buffer at point.
-    (let* ((default
-             (save-excursion
-               (skip-chars-backward "0-9")
-               (if (looking-at "[0-9]")
-                   (string-to-number
-                    (buffer-substring-no-properties
-                     (point)
-                     (progn (skip-chars-forward "0-9")
-                            (point)))))))
+    (let* ((number (number-at-point))
+           (default (and (natnump number) number))
            ;; Decide if we're switching buffers.
            (buffer
             (if (consp current-prefix-arg)
[Message part 3 (text/plain, inline)]
Also this patch adds the same useful property from goto-line to goto-char.
When there is no number at point, then M-n gets the current char position
number for editing, so the user can decrease or increase it
relative to the current position:

[goto-char-default-point.patch (text/x-diff, inline)]
diff --git a/lisp/subr.el b/lisp/subr.el
index 275e224b55..c7b7ac6444 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2828,7 +2828,7 @@ goto-char--read-natnum-interactive
       (list (prefix-numeric-value current-prefix-arg))
     (let* ((number (number-at-point))
            (default (and (natnump number) number)))
-      (list (read-number prompt default)))))
+      (list (read-number prompt (list default (point)))))))
 
 
 ;; Behind display-popup-menus-p test.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Sun, 20 Dec 2020 17:56:02 GMT) Full text and rfc822 format available.

Message #47 received at 45199 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: 45199 <at> debbugs.gnu.org
Subject: Re: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at
 point as default
Date: Sun, 20 Dec 2020 18:55:09 +0100
Juri Linkov <juri <at> linkov.net> writes:

> Here's a patch where it uses number-at-point:

Looks good to me.

> Also this patch adds the same useful property from goto-line to goto-char.
> When there is no number at point, then M-n gets the current char position
> number for editing, so the user can decrease or increase it
> relative to the current position:

Yeah, that sounds useful.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45199; Package emacs. (Sun, 20 Dec 2020 20:08:02 GMT) Full text and rfc822 format available.

Message #50 received at 45199 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 45199 <at> debbugs.gnu.org
Subject: Re: bug#45199: 28.0.50; [PATCH] Make goto-char offer the number at
 point as default
Date: Sun, 20 Dec 2020 22:06:13 +0200
>> Here's a patch where it uses number-at-point:
>
> Looks good to me.
>
>> Also this patch adds the same useful property from goto-line to goto-char.
>> When there is no number at point, then M-n gets the current char position
>> number for editing, so the user can decrease or increase it
>> relative to the current position:
>
> Yeah, that sounds useful.

Now pushed to master.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 18 Jan 2021 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 210 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.