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

  • SEARCH
  • Home
  • 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 8090669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:47:55+00:00 2026-06-05T19:47:55+00:00

Sometimes I want to have temporary comments fully left justified on a line (//)

  • 0

Sometimes I want to have temporary comments fully left justified on a line (//) or a block of lines /* */. However, CC Mode overrides this by auto-indenting upon typing the second key. In general, I like auto-indent for keywords, etc, but I would prefer it to be disabled for comments. (update: ie. I want to disable the way comment indentation is triggered by the c-electric- key-bindings, but comments should still indent normally othewise)

I’ve tried putting these lines in .emacs, but it doesn’t prevent the behaviour.

(c-electric-slash nil)
(c-electric-star nil)
  • 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-06-05T19:47:57+00:00Added an answer on June 5, 2026 at 7:47 pm

    Short answer:

    (eval-after-load 'cc-mode
      '(progn
         (define-key c-mode-base-map "/" 'self-insert-command)
         (define-key c-mode-base-map "*" 'self-insert-command)))
    

    Here’s how I go about it:

    Find out the function bound to /: C-h k /

    It says “/ runs the command c-electric-slash, which is an interactive compiled Lisp
    function in ‘cc-cmds.el'”.

    (If you don’t see the link to cc-cmds.el, then you don’t have the elisp sources installed. Assuming you’re not on Windows, you can use your system’s package manager to install the emacs-el package and try again.)

    Follow that link to open cc-cmds.el. Searching for c-electric-slash doesn’t find anything other than the function definition, so the keys aren’t bound in this file. Searching in cc-mode.el from this directory reveals:

    (define-key c-mode-base-map "/" 'c-electric-slash)
    

    Now we know the name of the “keymap” in which to override the / keybinding.

    If you add something like this to your init file, you’ll probably get an error on startup:

    (define-key c-mode-base-map "/" 'self-insert-command)
    

    …because your init file is loaded before cc-mode.el is, and c-mode-base-map is undefined. So we use eval-after-load (as at the top of my answer). The first argument, 'cc-mode, has to match the provide statement at the very end of cc-mode.el. If you don’t know what the progn means, do C-h f progn.

    If you like this style of learning/discovering Emacs, you might consider reading my “How to learn Emacs”.

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

Sidebar

Related Questions

I love the IDLE. However, sometimes I have 100-200 line scripts and I want
I feel silly asking this question... Sometimes I have a domain that I want
Sometimes I want to edit a certain visual block of text across multiple lines.
I have 2 classes both inherit from the same interface. i want sometimes to
Sometimes I want to use a minimal vim configuration, so with pathogen I have
I have some data in a chart using SSRS, sometimes we want to see
I have a table with a BLOB field that I sometimes want to set
We have a lot of multi-statement TVFs and we sometimes want to convert these
I have a question about using attr_accessible in Rails. I sometimes want to set
I have a class that knows its existing instances. Sometimes I want the class

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.