Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks for the pointer Mischa Arefiev, it got me looking in the right places. This is what I have come up with, and it covers all of my original requirements. The only limitation I'm aware of right now is that it will highlight an invalid number suffix as if it were correct (e.g. "123ulu")</p> <pre><code>(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) )) )) </code></pre> <p>Any suggestions/optimisations/fixes welcome!</p> <p>EDIT: Stopped it from highlighting numbers within comments.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload