Questions tagged [cc-mode]

Major mode for C, C++, Objective-C, Java, CORBA IDL, Pike, AWK. Included in GNU Emacs and XEmacs.

CC Mode is an Emacs mode for editing files in C-like languages: C, C++, Objective-C, Java, CORBA IDL, Pike, AWK. It is included in GNU Emacs and in XEmacs. Use the tag for questions about CC Mode in general.

For questions about a specific language supported by CC Mode, see the corresponding tag: , , , , , , . For questions about CC Mode's support for that language, use both the language tag and .

Useful links

71 questions
18
votes
3 answers

before-save-hook for cc-mode

I want to customize cc-mode to execute a function before saving. One solution would be to modify cc-mode keymap to bind C-x C-s to a function which performs the work I need and then saves it. My question is whether there is a hook I could customize…
Pradhan
  • 2,330
  • 14
  • 28
11
votes
1 answer

formatting constexpr if in c++-mode

I recently started using C++17, which brings constexpr if. This however screws up c++-modes default indentation. // emacs 25.3.2 with --no-init if constexpr (n == 1) { // Why? } else if constexpr (n == 2) { // This is a mess... } else { …
topisani
  • 113
  • 4
10
votes
1 answer

Custom indentation for specific lines?

I currently try to figure out, how I can handle some lines specifically without messing up the indentation of the rest of the buffer. Consider the following function MyFunc as an example: void MyFunc() { unsigned y = 0; DONOTINDENT; unsigned…
Rosepeter
  • 101
  • 2
6
votes
2 answers

Change the way CC-mode font-lock the C++11 `auto` syntax

With C++11, the keyword auto attained a new syntax and semantics. However, it seems that CC-mode has not been aware of this. For example, if I write auto var = exp, I get var in green, in which various types are displayed. I don't like this; var…
Pteromys
  • 185
  • 5
6
votes
2 answers

How to use C++ comments "//" in c-mode?

In c-mode comment-region is adding /* */ style comments. Is there a way to default to using C++ style // prefix in C source files instead?
ideasman42
  • 8,375
  • 1
  • 28
  • 105
6
votes
3 answers

Customizing c-mode indentation behavior in Emacs 24.4

Before Emacs 24.4, indentation in c-mode happened after typing things like ;, , and so on and I like this behavior. But in Emacs 24.4, c-mode also indents on RET. This causes a lot of problems for me because if I want to insert a blank line, I need…
fghj
  • 193
  • 7
6
votes
1 answer

rgrep default files pattern

How can I modify the default FILES pattern in rgrep for C++ mode? For C mode the default is *.[ch]. For C++, it is *.cc *.cxx *.cpp *.C *.CC *.c++. I would like to change it to *.cc *.[ch]xx *.[ch]pp *.[CHh] *.CC *.HH *.[ch]++.
SCC
  • 61
  • 1
4
votes
1 answer

How to highlight “constexpr” in cc-mode?

Question Pretty straightforward: How to highlight constexpr in cc-mode (editing C++ code)? Example If I use const as in the following example const double = 3.14 const gets highlighted as a keyword(1) (i.e., in pink), while if I write constexpr…
Pier Paolo
  • 275
  • 3
  • 10
4
votes
1 answer

How to convert single line comments to multiline comments?

I have a bunch of single line comment blocks in C-code that I want to change to multiline. Example: // foo // bar should become: /* foo * bar */ How can I do this easily in Emacs?
Arne
  • 409
  • 3
  • 12
4
votes
2 answers

CC-Mode - Javadoc Comment Colors in C/C++

I've been fiddling around a bit with CC-mode lately and figured that since I prefer to comment my functions/classes with javadoc-like syntax, I'd like to use the built-in comment highlighting provided by the corresponding c-doc-comment-style. This…
Xaldew
  • 1,181
  • 9
  • 20
4
votes
2 answers

Indentation after braces in C

I don't know what the formal name of it is (this being one of the reasons that I can't find how to achieve it). But, what I want is to make Emacs start the second bracket with the same amount of space that is used in the first one and when you press…
Adam
  • 2,407
  • 2
  • 21
  • 38
4
votes
1 answer

Override c++-mode font lock

I am improving the C++ highlighting in Emacs with the minor mode: modern-cpp-font-lock. Consider this following C++14 code: int main() { int i = 1'2'3l; } From cppreference.com Optional single quotes(') may be inserted between the digits as a …
user12181
4
votes
0 answers

Support C++11 syntax in c++-mode

I want correct indentation with my C++ code. The following piece of code indents properly. It nicely indents the access label and the member declaration independently. class Test : public Base { public: int a; }; However if I add a final…
Hot.PxL
  • 203
  • 1
  • 5
3
votes
1 answer

How to re-enable syntax highlighting of code that have been disabled by #if preprocessor statements

Code between #if SYMBOL and #endif is greyed out in cc-mode if the SYMBOL has not been defined within the current file. The project that I´m currently working on has a common code base for Mac and Windows so there´s a lot of #if WINDOWS and #if MAC…
Mikael Springer
  • 513
  • 3
  • 13
3
votes
1 answer

Indentation of multi-line arrays within braces?

Currently in C mode, contents of a muli-line arrays are aligned with the brace. eg: const unsigned int array[4] = { A, B, C, }; Is there a way to configure…
ideasman42
  • 8,375
  • 1
  • 28
  • 105
1
2 3 4 5