* bug#16834: 24.3.50; num3-mode detects long hex numbers as decimal
@ 2014-02-21 17:12 Alex Bennée
2014-02-21 18:05 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Alex Bennée @ 2014-02-21 17:12 UTC (permalink / raw)
To: 16834
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#16834: 24.3.50; num3-mode detects long hex numbers as decimal
2014-02-21 17:12 bug#16834: 24.3.50; num3-mode detects long hex numbers as decimal Alex Bennée
@ 2014-02-21 18:05 ` Stefan Monnier
2014-02-21 19:49 ` Michal Nazarewicz
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-02-21 18:05 UTC (permalink / raw)
To: Alex Bennée; +Cc: 16834, Michal Nazarewicz
> 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@gmail.com>, Michal Nazarewicz <mina86@mina86.com>
;; Maintainer: Michal Nazarewicz <mina86@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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#16834: 24.3.50; num3-mode detects long hex numbers as decimal
2014-02-21 18:05 ` Stefan Monnier
@ 2014-02-21 19:49 ` Michal Nazarewicz
2014-02-21 20:52 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Michal Nazarewicz @ 2014-02-21 19:49 UTC (permalink / raw)
To: Stefan Monnier, Alex Bennée; +Cc: 16834
[-- Attachment #1: Type: text/plain, Size: 3498 bytes --]
On Fri, Feb 21 2014, Stefan Monnier <monnier@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@gmail.com>, Michal Nazarewicz <mina86@mina86.com>
> ;; Maintainer: Michal Nazarewicz <mina86@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@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--
[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]
[-- Attachment #2.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#16834: 24.3.50; num3-mode detects long hex numbers as decimal
2014-02-21 19:49 ` Michal Nazarewicz
@ 2014-02-21 20:52 ` Stefan Monnier
2014-02-24 0:31 ` Michal Nazarewicz
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-02-21 20:52 UTC (permalink / raw)
To: Michal Nazarewicz; +Cc: 16834, Alex Bennée
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#16834: 24.3.50; num3-mode detects long hex numbers as decimal
2014-02-21 20:52 ` Stefan Monnier
@ 2014-02-24 0:31 ` Michal Nazarewicz
0 siblings, 0 replies; 5+ messages in thread
From: Michal Nazarewicz @ 2014-02-24 0:31 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 16834, Alex Bennée
[-- Attachment #1: Type: text/plain, Size: 1013 bytes --]
On Fri, Feb 21 2014, Stefan Monnier <monnier@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@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--
[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]
[-- Attachment #2.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-02-24 0:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-21 17:12 bug#16834: 24.3.50; num3-mode detects long hex numbers as decimal Alex Bennée
2014-02-21 18:05 ` Stefan Monnier
2014-02-21 19:49 ` Michal Nazarewicz
2014-02-21 20:52 ` Stefan Monnier
2014-02-24 0:31 ` Michal Nazarewicz
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.