How can I configure/modify objc-mode so that the face of comment-end is the same face as comment-start?

[The goal is to have commend-end always use font-lock-comment-delimiter-face, instead of font-lock-comment-face. Perhaps whatever method c-mode is using to achieve the desired behavior by default can be applied to objc-mode as an answer to this question.]

STEP 1: Launch the latest GUI version of Emacs 25 with no user configuration; i.e., emacs -q.

STEP 2: Open an Emacs source code file used to build Emacs such as nsterm.m. The buffer will be in objc-mode.

STEP 3: Place your cursor on a comment-start and type C-u C-x = and see that it has font-lock-comment-delimiter-face.

STEP 4: Place your cursor on a comment-end and type C-u C-x = and see that it has font-lock-comment-face.

If you repeat this same procedure in a c-mode buffer, the commend-end delimiter will have font-lock-comment-delimiter-face.

  • Please consider: (a) showing the problem/effect, (b) posting some code or other explanation of what you are doing to get that effect. (comment-start|end is a string - by itself it has no color - maybe clarify what you really mean, here.) – Drew Aug 19 '17 at 21:57
  • @Drew -- thanks for the suggestion -- I added a step 1, 2, 3 recipe. – lawlist Aug 19 '17 at 22:19

Emacs provides two variables, comment-start-skip and comment-end which font-lock use to determine which part of a comment should be in font-lock-comment-face and which should be in font-lock-comment-delimiter-face.

In C and Objective-C mode, comment-end are defined differently. (In Objective-C, comment-start (which isn't used by font-lock) and comment-end are set up for C++-style // comments):


comment-start: "/* "

comment-end: " */"


comment-start "// "

comment-end: ""

Fortunately, if you define a local font-lock-comment-end-skip variable, it will be used instead of comment-end.

Effectively, you could get the desired behavior using:

(set (make-local-variable 'font-lock-comment-end-skip) "\\*/")

See function font-lock-fontify-syntactically-region for details.

| improve this answer | |
  • The bounty has a 24 hour waiting period before it can be awarded, and stackexchange.com will send me reminders ... Thank you very much! – lawlist Aug 22 '17 at 17:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.