0

I recently notice that there's some strange behaviours of the font-lock of the c++-mode.

Let's start emacs by emacs -Q in the terminal, edit a new file test.cpp and save the following contents

enter image description here

Then put the cursor two lines above the int main line, type int test, you will find that the color of word main changes from blue to black

enter image description here

Backspace the current line to in or i, you will see that the color of main change back to blue.

This is not a very big problem under this test, but I use color theme that the function names are in bold type. So when I add a function above another function, the font-lock of the below one keep changing all the time which is really annoying.

Is this a emacs bug ? I want bold function name and other keywords but how can I get rid of it ? Any help will be appreciated.

  • 1
    You could mitigate the problem by first inserting a semicolon for function declarations or curly braces for function definition and then start typing your function before them. A good way would be to use templates to define functions, e.g. by using yasnippet: f M-x yas-expand. – theldoria Aug 19 '16 at 10:33
  • @theldoria This is not only happens when adding a new function. when one type 'std::out' above another 'std::out', the font-lock is also keep changing. – stackunderflow Aug 20 '16 at 0:45
  • Well, again, first put a semicolon and put whatever you want before that. You could, for example, bind the following function to M-;: (defun my-semicolon () "Insert semicolon and puts cursor before that" (interactive) (insert ";") (backward-char 1)). – theldoria Aug 20 '16 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.