GNU bug report logs -
#16834
24.3.50; num3-mode detects long hex numbers as decimal
Previous Next
Reported by: Alex Bennée <kernel-hacker <at> bennee.com>
Date: Fri, 21 Feb 2014 17:13:02 UTC
Severity: minor
Found in version 24.3.50
Done: Glenn Morris <rgm <at> gnu.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 16834 in the body.
You can then email your comments to 16834 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16834
; Package
emacs
.
(Fri, 21 Feb 2014 17:13:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Alex Bennée <kernel-hacker <at> bennee.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Fri, 21 Feb 2014 17:13:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
When dealing with large hex numbers the default regex of num3-mode can
detect them as decimals. For example given:
V28 : 00000000000000000007fc0000000000 vs 0000000000000000000bfc000000000
the follow is high-lighted
V28 : __xxx___xxx___xxx_____x___xxx___ vs _xxx___xxx___xxx_________xxx___
which is obviously wrong.
In the end I just reset num3--number-re to:
(setq num3--number-re "\\([[:xdigit:]]+\\)\\|\\([0-9]+\\)\\|\\.\\([0-9]+\\)")
but perhaps a slightly more clever solution that maintains old behaviour
for very long decimal numbers unless there is a hex digit in there would
be better.
It wouldn't hurt to have customisable faces as well as the default can
look quite harsh depending on the theme.
Regards,
--
Alex Bennée
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16834
; Package
emacs
.
(Fri, 21 Feb 2014 18:07:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 16834 <at> debbugs.gnu.org (full text, mbox):
> When dealing with large hex numbers the default regex of num3-mode can
> detect them as decimals. For example given:
> V28 : 00000000000000000007fc0000000000 vs 0000000000000000000bfc000000000
> the follow is high-lighted
> V28 : __xxx___xxx___xxx_____x___xxx___ vs _xxx___xxx___xxx_________xxx___
> which is obviously wrong.
I guess we could use the patch below. Michal, what do you think?
> It wouldn't hurt to have customisable faces as well as the default can
> look quite harsh depending on the theme.
Hmmm... they are, AFAICT (faces num3-face-odd and num3-face-even).
Stefan
diff --git a/packages/num3-mode/num3-mode.el b/packages/num3-mode/num3-mode.el
index b890c89..ae3289a 100644
--- a/packages/num3-mode/num3-mode.el
+++ b/packages/num3-mode/num3-mode.el
@@ -1,6 +1,6 @@
;;; num3-mode.el --- highlight groups of digits in long numbers -*- lexical-binding: t -*-
-;; Copyright (C) 2012 Free Software Foundation, Inc.
+;; Copyright (C) 2012, 2014 Free Software Foundation, Inc.
;; Author: Felix Lee <felix8a <at> gmail.com>, Michal Nazarewicz <mina86 <at> mina86.com>
;; Maintainer: Michal Nazarewicz <mina86 <at> mina86.com>
@@ -98,7 +98,10 @@ where) decimal point (would be) is."
(define-globalized-minor-mode global-num3-mode num3-mode num3-mode)
(defconst num3--number-re
- (concat "\\(?:0[xX]\\|#\\)\\([0-9a-fA-F]+\\)" ; 1 = hexadecimal
+ ;; Recognize "0x" and "#x" as prefixes announcing hexadecimal (from C and
+ ;; Elisp, respectively).
+ (concat "[0#][xX]\\([[:xdigit:]]+\\)" ; 1 = hexadecimal
+ "\\|\\(?1:[[:xdigit:]]*[a-fA-F][[:xdigit:]]*\\)" ; 1 = hexadecimal
"\\|\\([0-9]+\\)" ; 2 = decimal
"\\|\\.\\([0-9]+\\)")) ; 3 = fraction
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16834
; Package
emacs
.
(Fri, 21 Feb 2014 19:50:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 16834 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Fri, Feb 21 2014, Stefan Monnier <monnier <at> iro.umontreal.ca> wrote:
>> When dealing with large hex numbers the default regex of num3-mode can
>> detect them as decimals. For example given:
>> V28 : 00000000000000000007fc0000000000 vs 0000000000000000000bfc000000000
>> the follow is high-lighted
>> V28 : __xxx___xxx___xxx_____x___xxx___ vs _xxx___xxx___xxx_________xxx___
>> which is obviously wrong.
>
> I guess we could use the patch below. Michal, what do you think?
Looks good in general, but this leads to some interesting results:
“Aaaaaaa” he screamed as the dentist pulled his teeth out.
And if someone sets num3-threshold to 1 and changes num3-face-odd, all
the hexadecimal digits will get highlighted in a regular text even when
they are inside of a word.
I also hope engineers won't get mad when 1000A starts being treated as
a hexadecimal number. (They should know to put a non-break space
between the number an the unit anyway).
Perhaps this would be better:
(defconst num3--number-re
(concat "[0#][xX]\\([[:xdigit:]]+\\)" ; 1 = hexadecimal
"\\|\\(?1:\\b\\(?:[0-9]+[a-fA-F]\\|" ; 1 = hexadecimal
"[a-fA-F]+[0-9]\\)[[:xdigit:]]*\\b\\)"
"\\|\\([0-9]+\\)" ; 2 = decimal
"\\|\\.\\([0-9]+\\)")) ; 3 = fraction
So there would have to be at least one decimal digit and the whole
sequence would have to be a complete word (i.e. 1000Ah, which would be
a pretty big battery, won't be highlighted as a hexadecimal number).
>> It wouldn't hurt to have customisable faces as well as the default can
>> look quite harsh depending on the theme.
>
> Hmmm... they are, AFAICT (faces num3-face-odd and num3-face-even).
Yep, I have this in my custom.el:
'(num3-face-even ((t (:foreground "#CFF" :underline nil :weight normal))))
I don't particularly like the defaults myself, but that was what Felix
used in his original code, so I kept it.
> diff --git a/packages/num3-mode/num3-mode.el b/packages/num3-mode/num3-mode.el
> index b890c89..ae3289a 100644
> --- a/packages/num3-mode/num3-mode.el
> +++ b/packages/num3-mode/num3-mode.el
> @@ -1,6 +1,6 @@
> ;;; num3-mode.el --- highlight groups of digits in long numbers -*- lexical-binding: t -*-
>
> -;; Copyright (C) 2012 Free Software Foundation, Inc.
> +;; Copyright (C) 2012, 2014 Free Software Foundation, Inc.
>
> ;; Author: Felix Lee <felix8a <at> gmail.com>, Michal Nazarewicz <mina86 <at> mina86.com>
> ;; Maintainer: Michal Nazarewicz <mina86 <at> mina86.com>
> @@ -98,7 +98,10 @@ where) decimal point (would be) is."
> (define-globalized-minor-mode global-num3-mode num3-mode num3-mode)
>
> (defconst num3--number-re
> - (concat "\\(?:0[xX]\\|#\\)\\([0-9a-fA-F]+\\)" ; 1 = hexadecimal
> + ;; Recognize "0x" and "#x" as prefixes announcing hexadecimal (from C and
> + ;; Elisp, respectively).
> + (concat "[0#][xX]\\([[:xdigit:]]+\\)" ; 1 = hexadecimal
> + "\\|\\(?1:[[:xdigit:]]*[a-fA-F][[:xdigit:]]*\\)" ; 1 = hexadecimal
> "\\|\\([0-9]+\\)" ; 2 = decimal
> "\\|\\.\\([0-9]+\\)")) ; 3 = fraction
>
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +--<mpn <at> google.com>--<xmpp:mina86 <at> jabber.org>--ooO--(_)--Ooo--
[Message part 2 (text/plain, inline)]
[signature.asc (application/pgp-signature, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16834
; Package
emacs
.
(Fri, 21 Feb 2014 20:54:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 16834 <at> debbugs.gnu.org (full text, mbox):
> Perhaps this would be better:
> (defconst num3--number-re
> (concat "[0#][xX]\\([[:xdigit:]]+\\)" ; 1 = hexadecimal
> "\\|\\(?1:\\b\\(?:[0-9]+[a-fA-F]\\|" ; 1 = hexadecimal
> "[a-fA-F]+[0-9]\\)[[:xdigit:]]*\\b\\)"
> "\\|\\([0-9]+\\)" ; 2 = decimal
> "\\|\\.\\([0-9]+\\)")) ; 3 = fraction
> So there would have to be at least one decimal digit and the whole
> sequence would have to be a complete word (i.e. 1000Ah, which would be
> a pretty big battery, won't be highlighted as a hexadecimal number).
Sounds good. Can you install that?
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#16834
; Package
emacs
.
(Mon, 24 Feb 2014 00:32:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 16834 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Fri, Feb 21 2014, Stefan Monnier <monnier <at> iro.umontreal.ca> wrote:
>> Perhaps this would be better:
>
>> (defconst num3--number-re
>> (concat "[0#][xX]\\([[:xdigit:]]+\\)" ; 1 = hexadecimal
>> "\\|\\(?1:\\b\\(?:[0-9]+[a-fA-F]\\|" ; 1 = hexadecimal
>> "[a-fA-F]+[0-9]\\)[[:xdigit:]]*\\b\\)"
>> "\\|\\([0-9]+\\)" ; 2 = decimal
>> "\\|\\.\\([0-9]+\\)")) ; 3 = fraction
>
>> So there would have to be at least one decimal digit and the whole
>> sequence would have to be a complete word (i.e. 1000Ah, which would be
>> a pretty big battery, won't be highlighted as a hexadecimal number).
>
> Sounds good. Can you install that?
Pushed.
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +--<mpn <at> google.com>--<xmpp:mina86 <at> jabber.org>--ooO--(_)--Ooo--
[Message part 2 (text/plain, inline)]
[signature.asc (application/pgp-signature, inline)]
bug closed, send any further explanations to
16834 <at> debbugs.gnu.org and Alex Bennée <kernel-hacker <at> bennee.com>
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Mon, 24 Feb 2014 01:09:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 24 Mar 2014 11:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 11 years and 149 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.