* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
@ 2023-07-20 6:19 Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-20 6:39 ` Eli Zaretskii
0 siblings, 1 reply; 14+ messages in thread
From: Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-07-20 6:19 UTC (permalink / raw)
To: 64739
Hello,
Given the following number with point at ★:
★12.34
number-at-point correctly returns "12.34".
However,(forward-thing 'number) puts point just before the period:
12★.34
while I'd expect:
12.34★
(get 'number 'forward-op)
⇒ forward-word
forward-word doesn't seem to be the correct forward-op for numbers.
Joseph
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-20 6:19 bug#64739: (forward-thing 'number) doesn't work with decimal numbers Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-07-20 6:39 ` Eli Zaretskii
2023-07-21 12:28 ` Roland Winkler
0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-07-20 6:39 UTC (permalink / raw)
To: Joseph Turner; +Cc: 64739
> Date: Wed, 19 Jul 2023 23:19:27 -0700
> From: Joseph Turner via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>
> Hello,
>
> Given the following number with point at ★:
>
> ★12.34
>
> number-at-point correctly returns "12.34".
>
> However,(forward-thing 'number) puts point just before the period:
>
> 12★.34
>
> while I'd expect:
>
> 12.34★
>
> (get 'number 'forward-op)
> ⇒ forward-word
>
> forward-word doesn't seem to be the correct forward-op for numbers.
That depends on the buffer's syntax table, though.
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-20 6:39 ` Eli Zaretskii
@ 2023-07-21 12:28 ` Roland Winkler
2023-07-21 12:48 ` Eli Zaretskii
0 siblings, 1 reply; 14+ messages in thread
From: Roland Winkler @ 2023-07-21 12:28 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 64739, Joseph Turner
On Thu, Jul 20 2023, Eli Zaretskii wrote:
>> forward-word doesn't seem to be the correct forward-op for numbers.
>
> That depends on the buffer's syntax table, though.
I am frequently running into similar problems when I deal with numbers,
but the syntax table is not designed for this. Would it make sense if
(forward-thing 'number) temporarily used a customized synatx table?
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-21 12:28 ` Roland Winkler
@ 2023-07-21 12:48 ` Eli Zaretskii
2023-07-21 12:52 ` Eli Zaretskii
0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-07-21 12:48 UTC (permalink / raw)
To: Roland Winkler; +Cc: 64739, joseph
> From: Roland Winkler <winkler@gnu.org>
> Cc: Joseph Turner <joseph@breatheoutbreathe.in>, 64739@debbugs.gnu.org
> Date: Fri, 21 Jul 2023 07:28:29 -0500
>
> On Thu, Jul 20 2023, Eli Zaretskii wrote:
> >> forward-word doesn't seem to be the correct forward-op for numbers.
> >
> > That depends on the buffer's syntax table, though.
>
> I am frequently running into similar problems when I deal with numbers,
> but the syntax table is not designed for this. Would it make sense if
> (forward-thing 'number) temporarily used a customized synatx table?
It should use its own function, if you ask me. forward-word is a
kludge.
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-21 12:48 ` Eli Zaretskii
@ 2023-07-21 12:52 ` Eli Zaretskii
2023-07-21 14:14 ` Roland Winkler
2023-07-22 0:23 ` Michael Heerdegen
0 siblings, 2 replies; 14+ messages in thread
From: Eli Zaretskii @ 2023-07-21 12:52 UTC (permalink / raw)
To: winkler; +Cc: 64739, joseph
> Cc: 64739@debbugs.gnu.org, joseph@breatheoutbreathe.in
> Date: Fri, 21 Jul 2023 15:48:07 +0300
> From: Eli Zaretskii <eliz@gnu.org>
>
> > From: Roland Winkler <winkler@gnu.org>
> > Cc: Joseph Turner <joseph@breatheoutbreathe.in>, 64739@debbugs.gnu.org
> > Date: Fri, 21 Jul 2023 07:28:29 -0500
> >
> > On Thu, Jul 20 2023, Eli Zaretskii wrote:
> > >> forward-word doesn't seem to be the correct forward-op for numbers.
> > >
> > > That depends on the buffer's syntax table, though.
> >
> > I am frequently running into similar problems when I deal with numbers,
> > but the syntax table is not designed for this. Would it make sense if
> > (forward-thing 'number) temporarily used a customized synatx table?
>
> It should use its own function, if you ask me. forward-word is a
> kludge.
To clarify: I meant that using forward-word in this case is a kludge.
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-21 12:52 ` Eli Zaretskii
@ 2023-07-21 14:14 ` Roland Winkler
2023-07-21 14:29 ` Eli Zaretskii
2023-07-22 0:23 ` Michael Heerdegen
1 sibling, 1 reply; 14+ messages in thread
From: Roland Winkler @ 2023-07-21 14:14 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 64739, joseph
On Fri, Jul 21 2023, Eli Zaretskii wrote:
>> It should use its own function, if you ask me. forward-word is a
>> kludge.
>
> To clarify: I meant that using forward-word in this case is a kludge.
I am not familiar with how forward-thing is implemented. A dedicated
function has been my personal solution for this problem that has been
serving me well for many years. So one can rephrase: How common a
problem is this that it may (not?) justify a solution in the standard
emacs code?
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-21 14:14 ` Roland Winkler
@ 2023-07-21 14:29 ` Eli Zaretskii
2023-07-23 3:36 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-07-21 14:29 UTC (permalink / raw)
To: Roland Winkler; +Cc: 64739, joseph
> From: Roland Winkler <winkler@gnu.org>
> Cc: 64739@debbugs.gnu.org, joseph@breatheoutbreathe.in
> Date: Fri, 21 Jul 2023 09:14:48 -0500
>
> On Fri, Jul 21 2023, Eli Zaretskii wrote:
> >> It should use its own function, if you ask me. forward-word is a
> >> kludge.
> >
> > To clarify: I meant that using forward-word in this case is a kludge.
>
> I am not familiar with how forward-thing is implemented. A dedicated
> function has been my personal solution for this problem that has been
> serving me well for many years. So one can rephrase: How common a
> problem is this that it may (not?) justify a solution in the standard
> emacs code?
By "its own function" I meant that we implement it in Emacs, not that
you implement it in your personal customizations.
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-21 14:29 ` Eli Zaretskii
@ 2023-07-23 3:36 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-23 5:33 ` Eli Zaretskii
0 siblings, 1 reply; 14+ messages in thread
From: Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-07-23 3:36 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 64739, Roland Winkler
Eli Zaretskii <eliz@gnu.org> writes:
> By "its own function" I meant that we implement it in Emacs, not that
> you implement it in your personal customizations.
I see that the definition of number-at-point includes two magic regexps,
one matching hex numbers and another matching decimal numbers. Would it
make sense to move those regexps into defconsts, and then create a new
function forward-number which uses those new constants?
Joseph
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-23 3:36 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-07-23 5:33 ` Eli Zaretskii
2023-07-23 19:03 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-07-23 5:33 UTC (permalink / raw)
To: Joseph Turner; +Cc: 64739, winkler
> From: Joseph Turner <joseph@breatheoutbreathe.in>
> Cc: Roland Winkler <winkler@gnu.org>, 64739@debbugs.gnu.org
> Date: Sat, 22 Jul 2023 20:36:16 -0700
>
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > By "its own function" I meant that we implement it in Emacs, not that
> > you implement it in your personal customizations.
>
> I see that the definition of number-at-point includes two magic regexps,
> one matching hex numbers and another matching decimal numbers. Would it
> make sense to move those regexps into defconsts, and then create a new
> function forward-number which uses those new constants?
That's probably one idea, yes. (But note that those regexps don't
support numbers like "1.0e2".)
Another idea is to define a special-purpose syntax table and use that
with forward-word.
Yet another idea is to use 'read', since the Lisp reader already knows
how to read numbers.
And there probably are other ideas as well.
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-23 5:33 ` Eli Zaretskii
@ 2023-07-23 19:03 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-24 11:25 ` Eli Zaretskii
0 siblings, 1 reply; 14+ messages in thread
From: Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-07-23 19:03 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 64739, winkler
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Joseph Turner <joseph@breatheoutbreathe.in>
>> Cc: Roland Winkler <winkler@gnu.org>, 64739@debbugs.gnu.org
>> Date: Sat, 22 Jul 2023 20:36:16 -0700
>>
>> > By "its own function" I meant that we implement it in Emacs, not that
>> > you implement it in your personal customizations.
>>
>> I see that the definition of number-at-point includes two magic regexps,
>> one matching hex numbers and another matching decimal numbers. Would it
>> make sense to move those regexps into defconsts, and then create a new
>> function forward-number which uses those new constants?
>
> That's probably one idea, yes. (But note that those regexps don't
> support numbers like "1.0e2".)
I agree that the regexp solution is not ideal.
> Another idea is to define a special-purpose syntax table and use that
> with forward-word.
Did you have something like this in mind?
(defvar number-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?. "w " st)
;; ?- and ?+ could indicate the sign at the beginning of a number or
;; they could indicate the sign of an exponent like 1.5e-6
(modify-syntax-entry ?- "w " st)
(modify-syntax-entry ?+ "w " st)
;; ?# acts as a prefix for integers in bases other than 10.
(modify-syntax-entry ?# "w " st)
st)
"Syntax table used to detect word boundaries for numbers.")
(defun forward-number (&optional n)
(interactive)
(with-syntax-table number-syntax-table
(forward-word-strictly n)))
(defun backward-number (&optional n)
(interactive)
(with-syntax-table number-syntax-table
(forward-word-strictly n)))
;; We don't need the following two lines, since forward-thing uses
;; intern-soft to get these function names anyway.
(put 'number 'forward-op 'forward-number)
(put 'number 'beginning-op 'backward-number)
What would we use for end-op? Is it necessary?
Also I notice that the current implementation of number-at-point fails
to recognize the following as a single number:
-1.5e+6
Could we do something like:
(defun number-at-point (&optional no-properties)
(with-syntax-table number-syntax-table
(word-at-point no-properties)))
(put 'number 'thing-at-point 'number-at-point)
I'd appreciate feedback on the syntax table above. It incorrectly
recognizes some non-number strings as numbers:
a-a+a-
#abc#abc
> Yet another idea is to use 'read', since the Lisp reader already knows
> how to read numbers.
Sounds interesting! I'm not sure how to approach a solution like that.
How would you let the Lisp reader know where to start and stop reading?
Joseph
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-23 19:03 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-07-24 11:25 ` Eli Zaretskii
2023-07-26 12:21 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2023-07-24 11:25 UTC (permalink / raw)
To: Joseph Turner, Stefan Monnier; +Cc: 64739, winkler
> From: Joseph Turner <joseph@breatheoutbreathe.in>
> Cc: winkler@gnu.org, 64739@debbugs.gnu.org
> Date: Sun, 23 Jul 2023 12:03:50 -0700
>
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > That's probably one idea, yes. (But note that those regexps don't
> > support numbers like "1.0e2".)
>
> I agree that the regexp solution is not ideal.
>
> > Another idea is to define a special-purpose syntax table and use that
> > with forward-word.
>
> Did you have something like this in mind?
More or less. TBH, I didn't think about this too much, so maybe this
idea doesn't "hold water".
> > Yet another idea is to use 'read', since the Lisp reader already knows
> > how to read numbers.
>
> Sounds interesting! I'm not sure how to approach a solution like that.
> How would you let the Lisp reader know where to start and stop reading?
Start is easy: 'read' always starts at point. End might give us
trouble, but in general 'read' reads one expression, so it should stop
at the end of the number, no?
Anyway, I was just brain-storming. A real solution will need more
thought and more testing. Perhaps Stefan (CC'ed) has some ideas or
inputs.
^ permalink raw reply [flat|nested] 14+ messages in thread
* bug#64739: (forward-thing 'number) doesn't work with decimal numbers
2023-07-21 12:52 ` Eli Zaretskii
2023-07-21 14:14 ` Roland Winkler
@ 2023-07-22 0:23 ` Michael Heerdegen
1 sibling, 0 replies; 14+ messages in thread
From: Michael Heerdegen @ 2023-07-22 0:23 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 64739, winkler, joseph
Eli Zaretskii <eliz@gnu.org> writes:
> > > On Thu, Jul 20 2023, Eli Zaretskii wrote:
> > > >> forward-word doesn't seem to be the correct forward-op for numbers.
> > > >
> > > > That depends on the buffer's syntax table, though.
> > >
> > > I am frequently running into similar problems when I deal with numbers,
> > > but the syntax table is not designed for this. Would it make sense if
> > > (forward-thing 'number) temporarily used a customized synatx table?
> >
> > It should use its own function, if you ask me. forward-word is a
> > kludge.
>
> To clarify: I meant that using forward-word in this case is a kludge.
It had been added by Lars when fixing Bug#54555 "number is not an
accepted value for THING in bounds-of-thing-at-point" last year.
Probably just not being aware of this problem with the decimal point.
So: yes, a klugde, it's too simple.
Michael.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2023-07-29 23:01 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-20 6:19 bug#64739: (forward-thing 'number) doesn't work with decimal numbers Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-20 6:39 ` Eli Zaretskii
2023-07-21 12:28 ` Roland Winkler
2023-07-21 12:48 ` Eli Zaretskii
2023-07-21 12:52 ` Eli Zaretskii
2023-07-21 14:14 ` Roland Winkler
2023-07-21 14:29 ` Eli Zaretskii
2023-07-23 3:36 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-23 5:33 ` Eli Zaretskii
2023-07-23 19:03 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-24 11:25 ` Eli Zaretskii
2023-07-26 12:21 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-29 23:01 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-22 0:23 ` Michael Heerdegen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.