Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4248508
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:16:00+00:00 2026-05-21T04:16:00+00:00

I need a little help with some Emacs syntax highlighting troubles. I’d like to

  • 0

I need a little help with some Emacs syntax highlighting troubles. I’d like to set the colour of all C/C++ operators. I am having trouble because “/” is used for division (which I want to colour) but also used to start comments (which I don’t want to colour myself, the default code colours them fine.) I can’t seem to figure out how to tell Emacs to only colour a single forward-slash when it is not surrounded by any other forward slashes.

This is what I have now:

(add-hook 'c-mode-common-hook (lambda ()
  (font-lock-add-keywords nil         
    '(("[<>:&*=+^%!~,.?;/-]" 0 font-lock-warning-face t)))
))

But it won’t correctly highlight something like this:

i = 1 / 2
// Test
i=1/2//test

Of course if there’s already a way of assigning a colour/face to punctuation/operators and I’ve just missed it please let me know!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:16:00+00:00Added an answer on May 21, 2026 at 4:16 am

    Each font long entry has the following format:

    (SUBEXP FACENAME [OVERRIDE [LAXMATCH]])
    

    The t in your rule corresponds to the OVERRIDE entry. If you drop it, your rule will not re-highlight something that already has been highlighted, for example comments and strings.

    There is no general package for highlighting all operators, but cwarn-mode will highlight = and += etc. that are embedded inside larger expressions, as well as the ; in situations where it shouldn’t be, like if (condition);. It’s implemented using functions rather than regexp:s, and I consider it a good reference if you plan to implement relatively advanced font-lock rules.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting a little confused and need some help please. Take these two
I need a little help converting some VB.NET code to C#. I have tried
I need a little help on a regex pattern. I have some strings ending
I have some JQuery that isn't working and I need a little help. I
I have very little experience with asp.net and need some help with a presumably
I need a little help on this subject. I have a Web application written
I have started to study UML standard and would need little help with two
Need a little help with a SQL / ActiveRecord query. Let's say I have
I need a little help clearing something up with Zend_Form and adding filters to
I need a little help. I am fairly new to reflection. We're using a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.