Emacs C模式 - 你如何突出显示十六进制数字?

Mal*_*ous 6 emacs syntax-highlighting

自从我切换到Emacs后,有一件事让我感到烦恼的是,我只能在C代码中正确地使用语法突出显示十进制数字.例如,这些数字正确突出显示:

1234
1234l
1234.5f
Run Code Online (Sandbox Code Playgroud)

但是,这些数字未正确突出显示:

0x1234  // x is different colour
0xabcd  // no hex digits are coloured
019     // invalid digit 9 is coloured like it is correct
Run Code Online (Sandbox Code Playgroud)

是否可以让Emacs为这些数字中的每个字符着色相同?如果无效数字(如019或0x0g)可以不同颜色以使它们脱颖而出,那就更好了.

Mal*_*ous 6

感谢指针Mischa Arefiev,它让我找到了正确的位置.这就是我提出的,它涵盖了我所有的原始要求.我现在意识到的唯一限制是它会突出显示无效的数字后缀,就好像它是正确的一样(例如"123ulu")

(add-hook 'c-mode-common-hook (lambda ()
    (font-lock-add-keywords nil '(

        ; Valid hex number (will highlight invalid suffix though)
        ("\\b0x[[:xdigit:]]+[uUlL]*\\b" . font-lock-string-face)

        ; Invalid hex number
        ("\\b0x\\(\\w\\|\\.\\)+\\b" . font-lock-warning-face)

        ; Valid floating point number.
        ("\\(\\b[0-9]+\\|\\)\\(\\.\\)\\([0-9]+\\(e[-]?[0-9]+\\)?\\([lL]?\\|[dD]?[fF]?\\)\\)\\b" (1 font-lock-string-face) (3 font-lock-string-face))

        ; Invalid floating point number.  Must be before valid decimal.
        ("\\b[0-9].*?\\..+?\\b" . font-lock-warning-face)

        ; Valid decimal number.  Must be before octal regexes otherwise 0 and 0l
        ; will be highlighted as errors.  Will highlight invalid suffix though.
        ("\\b\\(\\(0\\|[1-9][0-9]*\\)[uUlL]*\\)\\b" 1 font-lock-string-face)

        ; Valid octal number
        ("\\b0[0-7]+[uUlL]*\\b" . font-lock-string-face)

        ; Floating point number with no digits after the period.  This must be
        ; after the invalid numbers, otherwise it will "steal" some invalid
        ; numbers and highlight them as valid.
        ("\\b\\([0-9]+\\)\\." (1 font-lock-string-face))

        ; Invalid number.  Must be last so it only highlights anything not
        ; matched above.
        ("\\b[0-9]\\(\\w\\|\\.\\)+?\\b" . font-lock-warning-face)
    ))
))
Run Code Online (Sandbox Code Playgroud)

欢迎任何建议/优化/修复!

编辑:停止在注释中突出显示数字.