Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

Emacs: I want to highlight the numbers that my variables contain, no the name of the variables by itself

so, I added this to my theme:

(font-lock-add-keywords 'c-mode
        '(("\([0-9]+\)" . font-lock-warning-face)))

so far so good... it changes the color of what the variable contain. ex:

int a = 5

where the '5' is colored with a predefined color. the problem goes when I have a variable whose name correnspond to "variable_1" it colors the '1' in "variable_1"... is there a way to fix this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This solution was tested on the following three (3) examples:

  • int a = 5

  • funtion(1, 2)

  • variable_1

(defun my-c-mode-keywords ()
  (font-lock-add-keywords nil (list
    (list "[^_]\([0-9]+\)" '(1 'font-lock-warning-face))) 'prepend))

(add-hook 'c-mode-hook 'my-c-mode-keywords)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...