How do I change the style of comments for M-; (comment-dwim) when using c-mode?
I would like it to use comments preceeded by // instead of /* */ nesting.
Version:
GNU Emacs 23.2.1 (x86_64-pc-linux-gnu, GTK+ Version 2.20.1) of 2010-12-11 on brahms, modified by Debian
The command to create or align a comment is M-; ( comment-dwim ). The word “dwim” is an acronym for “Do What I Mean”; it indicates that this command can be used for many different jobs relating to comments, depending on the situation where you use it.
As mentioned above, the CTRL +; key in Emacs comments out the entire line where the cursor or the region is located. If you want to comment out only the selected region, you can use the ALT +; key. For example, consider the following selected region. To comment out only the highlighted region, use the ALT +; key.
To uncomment the region you use C-u - a plain prefix arg (no explicit number) to uncomment the region. C-h f comment-region says: comment-region is an interactive compiled Lisp function in newcomment.
The relevant vars are comment-start
and comment-end
so you can use this:
(add-hook 'c-mode-hook (lambda () (setq comment-start "//"
comment-end "")))
From http://www.cs.cmu.edu/cgi-bin/info2www?(emacs)C%20Mode:
C++ mode is like C mode, except that it understands C++ comment syntax and certain other differences between C and C++. It also has a command `M-x fill-c++-comment', which fills a paragraph made of C++ comment lines.
So you can just add this line to your .emacs:
(add-to-list 'auto-mode-alist '("\\.[ch]\\'" . c++-mode))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With