Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c++]

Questions related to the C++ language or the cc-mode

48
votes
9answers
23k views

Using Emacs as a full-featured C/C++ IDE

I have been trying off and on for over a year now to use Emacs as a C/C++ IDE. I have only been marginally successful thus far, but have run into a few brick walls along the way. Currently I am ...
43
votes
6answers
54k views

How to get intelligent auto-completion in C++?

Emacs cannot compete with another other IDE if it doesn’t have an auto completion function. Auto-complete simply makes me a more efficient programmer. I know of the Auto Complete Mode extension, but ...
11
votes
2answers
849 views

Display the beginning of a scope when it is out of screen

I would like to display the opening part of a scope when this one get out of screen. Example: namespace a { ... --------------------- <- display frame ... | }* ...
11
votes
2answers
4k views

How to get semantic syntax highlighting on emacs for C/C++ code

I'm new to emacs and programming in general so please bear with me. I'm trying to use emacs as my C/C++ IDE, and I noticed that in CC mode the variables/functions seemed to be highlighted only during ...
11
votes
1answer
762 views

disable specific warning in flycheck (specifically “#pragma once in main file”)

I'm using flycheck for C++ development, and get the following warning: #pragma once in main file In all headers included in a main file. Searching the webs, I get the impression this has something ...
11
votes
1answer
817 views

Color declared variables

I'm looking for a simple way to make emacs remember of declared variable in a single function in C/C++. By "simple", I mean without any external package, just with some elisp lines in configuration ...
11
votes
3answers
2k views

How can I get C/C++ context-sensitive completion with Company?

Semantic seems to be able to do this, but I cannot get it to work as I would expect it to. For example, if I #include "Type.h" and declare Type t, using semantic-complete-analyze-inline when point is ...
10
votes
1answer
4k views

Best C++ indexer?

I've recently switched over from Eclipse CDT to Spacemacs with the C++ layer as my development environment. So far... awesome! However, one of the things I miss about Eclipse is its indexer. At the ...
9
votes
2answers
2k views

Is there a yasnippet producing a prepopulated doxygen comment?

For the following C++ function: bool importantStuff(double a, double b); It should output the following snippet, perhaps without the tags: /** * <Insert description of importantStuff> * * @...
8
votes
1answer
371 views

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 ...
7
votes
2answers
3k views

Class Browsing in C++

I'm working with a large codebase and often find it to be tedious and hard to understand class relationships. I found the following wiki that describes various tools for working with OOP in C++, but ...
6
votes
2answers
914 views

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 ...
6
votes
1answer
2k views

How should I configure irony-mode if my project has no “compilation flags”?

irony-mode is: an Emacs minor-mode that aims at improving the editing experience for the C, C++ and Objective-C languages. It works by using a combination of an Emacs package and a C++ program (irony-...
6
votes
2answers
239 views

C++ mode: smartly use /*…*/ for comment-dwim

I want to adjust the behavior of comment-dwim when editing c++ files: When a region is selected that either starts or ends in the middle of a line I would prefer /* ... */ comments. For the other ...
4
votes
1answer
503 views

Displaying the type of variable in C++ code with cursor

It has been difficult to see immediately the types of variables in C++ codes because they are defined using 'auto', 'template' and 'decltype'. If you use IDE, you can detect the type after the ...
4
votes
2answers
664 views

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 ...
4
votes
1answer
84 views

Is there a way to disable multi-line string literals in c++-mode?

Suppose I have a short string in C++ and I accidentally delete the double quote that ends it. What Emacs does is highlight the rest of the code as a single very long string, which messes up all the ...
4
votes
1answer
102 views

Globally set C++ source block header arguments

I try to globally set header properties for C++ source examples, with no success. I would have expected that the following works #+PROPERTY: header-args:C++ :var x=1.0 What did work is using ...
4
votes
0answers
2k views

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 { ...
3
votes
2answers
6k views

How to compile and run a C++ file? [closed]

I don't know how to compile and run a C++ file in GNU Emacs. I searched on the various sites and stackexchange network, but from them what I understood was write something like make compile, and I don'...
3
votes
1answer
215 views

Weird indentation behavior in C++ mode

In C++ mode there is the following behavior of the indentation: Why is this happening? How can I fix it?
3
votes
1answer
1k views

lsp-mode: How to use built-in clangd client?

I'm trying to use lsp-mode (together with company-lsp) for auto completion in C++. According to the docs[0], recent lsp-mode includes clangd support, so I should be all set when I do (require 'lsp-...
3
votes
1answer
5k views

How do I get company mode to recognize clang?

My current setup is as follows Elementary OS Freya Emacs version 24.5.1 company-mode 0.8.12 clang-3.5-dev libclang-3.5-dev I've checked that both libclang-3.5-dev and clang-3.5-dev are installed ...
3
votes
2answers
460 views

automatically close type parens in C++

Does anybody know of a way or a package that can recognize < and > when occuring in template contexts and automatically writes a > either right after the < or after the selected region ...
3
votes
1answer
541 views

Is it possible to use mozilla's rr with gdb multi-window?

I have started using mozilla's rr (timetravelling debugger, github here) on the command line for debugging c++ code. In emacs I can start it with gud-gdb and writing rr replay (as mentioned here or ...
3
votes
1answer
2k views

setting up irony-mode json compilation database

I am struggling with the setup for irony-mode's JSON cdb support. I have this in my initialization: ;;; C++ code completion (eval-after-load 'company '(add-to-list 'company-backends 'company-irony)...
3
votes
0answers
997 views

Spacemacs C++ debugging?

What tools are you using for setting Breakpoints visualize Variables within Spacemacs? I had a look at gdb but it felt awkward to set the breakpoints separated from the source files. I would like to ...
3
votes
0answers
60 views

Working around preprocessor blocks

I am trying to navigate a C project that has lots of preprocessor directives like this: #ifdef SOME_COMPILE_TIME_VARIABLE for ( idx=0; idx<FOO; idx++ ) { #else for ( idx=0; idx<BAR; idx+...
3
votes
0answers
166 views

Class inheritance tree in ECB

I'd like to see the inheritance tree for classes which I have currently open, similarly to how it ECB shows related files (e.g. I have a class B in my buffer, its parent A and child C are in different ...
2
votes
2answers
4k views

Better syntax-higlighting for member variables and function calls in cpp-mode

In atom, C++ files are well colored unlike emacs cpp-mode. Emacs does not highlight references to member variables, function calls or member functions. They all are uncolored. The left is from emacs ...
2
votes
1answer
1k views

Enlarge font size of function names in source code like Source Insight

Source Insight can show function names in a larger font. Can Emacs display function names with a larger font and different color?
2
votes
2answers
1k views

Enable Emacs to suggest the available methods of a class

I have setup Emacs to work almost like an IDE but I haven't managed to make it suggest the available methods of every class. I currently write in C++ and previously I was using Visual Studio so when ...
2
votes
2answers
962 views

cc-styles c-offsets-alist setting for C++11 lambda brace indentation

I am trying to configure my cc-styles to use a single basic offset for the braces of an inline defined lambda. I have a function template which takes a functor as an argument template<typename ...
2
votes
1answer
2k views

Add include paths to flycheck and to company-irony?

I am starting to develop a ROS (Robot Operating System) application for the first time using Emacs. Here is my ~/.emacs.d/init.el configuration for Flycheck and company packages: ;;;;;;;;;;;;;;;;;;;;;...
2
votes
3answers
498 views

Changing or adding compiling options in cc-mode

In cc-mode, when we go to compile, M-x followed by compile, the default option is make -k. If I hit the down arrow, I am told no defaults available. Is it possible to add the option g++ -Wall ...
2
votes
1answer
602 views

Gray-out preprocessor conditionals

Is there a package that will gray out or hide the false portion of a c preprocessor macro? #define ENABLE 1 #if ENABLE bool hide = false; #else bool hide = true; #endif In the above example, ...
2
votes
2answers
1k views

C++ Incorrect Enum Indentation

It seems like cc-mode indentation is working rather well, however I seem to have run into a minor issue when creating a few enums in C++. Emacs seems to handle almost all kinds of enums rather well ...
2
votes
2answers
594 views

Linking to c++ libraries in babel code block

The title says it all, and I've included the relevant sections of my file below. I'm trying to create a src block that uses some functionality of the boost libraries, the first src block sets up the ...
2
votes
1answer
49 views

autofill a cpp file based on the .h file

suppose I have x.h class X { void f(); void g(); } in x.cpp #include "x.h" can I just entry a command with "X" as a parameter, then I can get void X::f() {} void X::g() {}
2
votes
1answer
818 views

Jump to definition of function or class in one of the include files?

Take the following sample code: #include <cmath> int main() { double a = -10; double b = std::abs(a); return 0; } When I place the cursor over abs, for example between b and s, I ...
2
votes
1answer
690 views

Configuring Emacs as a CMake based C/C++ IDE

I have been interested in Emacs for a while, since I have seen some great articles on the Internet, which demonstrates the usage of Emacs as a C/C++ IDE. Those projects are awesome, yet they are not ...
2
votes
1answer
680 views

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 ...
2
votes
0answers
71 views

Valgrind interface for emacs

Is there an interface similar to 'gdb-mi' for using Valgrind in emacs? What are some ways to use Valgrind inside emacs?
2
votes
1answer
58 views

Emacs indents C++ functions in structs in an unexpected way

Emacs indents functions in structs in the following way: struct A { int a() { return 1; } int b() { return 2; } } int c() { return ...
2
votes
0answers
226 views

Navigate C/C++ Source Code with Emacs [closed]

So, i'm finally starting to work with a multi-file Project in C++ and am in need for smart navigation and completion! So far, i've used company-mode (with irony and company-headers), which is great if ...
1
vote
2answers
1k views

How to set up hotkey for compiling c code and run the compiled file?

I used to use tmux with vim to write codes in C/C++. So I split the screen into two in tmux and then press F3 to "make" the file. And then I can press F4 to run the "main" file in the next subscreen. ...
1
vote
2answers
229 views

`M-x` compile always runs the same command

I'm a very new user (~ 2 days) to Emacs. I switched from vim, because it wasn't working for me. I'm learning C++ and I've run into this issue when I write M-x compile. Upon writing this command, emacs ...
1
vote
1answer
137 views

What does the `/l` mean in the mode `C++/l` mean?

Just a simple question with more than likely a simple answer: What does the /l mean in the mode C++/l mean?
1
vote
1answer
150 views

Why do multi-line comment blocks influence C++ indentation?

I'm a long-term Emacs user who recently started to learn C++. I was surprised to discover that indentation for C++ is actually rather bad, specifically in files containing multi-line comment blocks. ...
1
vote
2answers
432 views

helm-semantic-imenu doesn't identify pointers and references in C++ code

With semantic-mode enabled and reading a C++ source file in cc-mode, running helm-semantic-or-imenu correctly shows all the classes, variables and functions defined in that file. However, all the ...