From: Visuwesh <visuweshm@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 69239@debbugs.gnu.org
Subject: bug#69239: 30.0.50; number-at-point and bounds-of-thing-at-point disagree
Date: Sat, 09 Mar 2024 15:18:03 +0530 [thread overview]
Message-ID: <8734szg2i4.fsf@gmail.com> (raw)
In-Reply-To: <86cyslxd3p.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 25 Feb 2024 08:38:34 +0200")
[-- Attachment #1: Type: text/plain, Size: 293 bytes --]
[ஞாயிறு பிப்ரவரி 25, 2024] Eli Zaretskii wrote:
>> But if you want to be on the safer side, then I can write a patch that
>> doesn't use number-at-point.
>
> Yes, please.
>
> Thanks.
Sorry for the delay, life had me busy. Please find attached patch.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-bounds-of-thing-at-point-property-for-number.patch --]
[-- Type: text/x-diff, Size: 2156 bytes --]
From f402a765365ec76f741d8eaffb75f4177abb1261 Mon Sep 17 00:00:00 2001
From: Visuwesh <visuweshm@gmail.com>
Date: Sat, 9 Mar 2024 15:17:26 +0530
Subject: [PATCH] Add bounds-of-thing-at-point property for 'number'
* lisp/thingatpt.el (thing-at-point-decimal-regexp)
(thing-at-point-hexadecimal-regexp): Extract regexps from...
(number-at-point): here. Use above.
(number): Add 'bounds-of-thing-at-point' property as
`forward-word' does not always return the right boundary e.g.,
in latex-mode buffers. (bug#69239)
---
lisp/thingatpt.el | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 83ddc640d35..7896ad984df 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -735,20 +735,33 @@ symbol-at-point
(let ((thing (thing-at-point 'symbol)))
(if thing (intern thing))))
+(defvar thing-at-point-decimal-regexp
+ "-?[0-9]+\\.?[0-9]*"
+ "A regexp matching a decimal number.")
+
+(defvar thing-at-point-hexadecimal-regexp
+ "\\(0x\\|#x\\)\\([a-fA-F0-9]+\\)"
+ "A regexp matchin a hexadecimal number.")
+
;;;###autoload
(defun number-at-point ()
"Return the number at point, or nil if none is found.
Decimal numbers like \"14\" or \"-14.5\", as well as hex numbers
like \"0xBEEF09\" or \"#xBEEF09\", are recognized."
(cond
- ((thing-at-point-looking-at "\\(0x\\|#x\\)\\([a-fA-F0-9]+\\)" 500)
+ ((thing-at-point-looking-at thing-at-point-hexadecimal-regexp 500)
(string-to-number
(buffer-substring (match-beginning 2) (match-end 2))
16))
- ((thing-at-point-looking-at "-?[0-9]+\\.?[0-9]*" 500)
+ ((thing-at-point-looking-at thing-at-point-decimal-regexp 500)
(string-to-number
(buffer-substring (match-beginning 0) (match-end 0))))))
+(put 'number 'bounds-of-thing-at-point
+ (lambda ()
+ (and (or (thing-at-point-looking-at thing-at-point-hexadecimal-regexp 500)
+ (thing-at-point-looking-at thing-at-point-decimal-regexp 500))
+ (cons (match-beginning 0) (match-end 0)))))
(put 'number 'forward-op 'forward-word)
(put 'number 'thing-at-point 'number-at-point)
--
2.43.0
next prev parent reply other threads:[~2024-03-09 9:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-16 12:26 bug#69239: 30.0.50; number-at-point and bounds-of-thing-at-point disagree Visuwesh
2024-02-24 9:17 ` Eli Zaretskii
2024-02-25 4:42 ` Visuwesh
2024-02-25 6:38 ` Eli Zaretskii
2024-03-09 9:48 ` Visuwesh [this message]
2024-03-14 9:42 ` Eli Zaretskii
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=8734szg2i4.fsf@gmail.com \
--to=visuweshm@gmail.com \
--cc=69239@debbugs.gnu.org \
--cc=eliz@gnu.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).