Skip to main content
10 votes
Accepted

How to compile and run a C++ file?

That's a lot of questions, but I will try to answer them in such a way that you can look up all the answers in detail. Emacs is primarily a text editor; you will use it to edit your C++ files. ...
db48x's user avatar
  • 19.1k
9 votes
Accepted

formatting constexpr if in c++-mode

UPDATE: That pretest version that I put down there in the original question (emacs-26.0.90.tar.gz) had a bug that cause certain infinity loops while parsing the buffer, specifically when using the <...
ABu's user avatar
  • 290
8 votes
Accepted

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

EDIT: As of late December 2018, this is no longer required, and lsp-mode does the required setup automatically. It was fixed in this commit as far as I can tell. You need to call lsp-clients-register-...
Lorenz's user avatar
  • 144
7 votes
Accepted

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

This can be done pretty easily. press M-x RET customize-face RET font-lock-function-name-face RET and you'll get the customization menu for function name face. You can change any attribute you want(...
Chakravarthy Raghunandan's user avatar
7 votes
Accepted

Extra indentation for argument lists beginning on a new line

Set point on the line in question and press C-c C-s to call c-show-syntactic-information. This shows you which variable you need to set. I set this to: (c-offsets-alist . ( (arglist-intro . c-...
jue's user avatar
  • 4,686
6 votes
Accepted

How to us a shortcut to add semicolon to end of current line?

If you ever want to add shortcuts functionality where you have control over the exact behavior, it's worth learning a little emacs-lisp. This kind of functionality is trivial to write. (global-set-key ...
ideasman42's user avatar
  • 9,157
5 votes
Accepted

Add include paths to flycheck and to company-irony?

Irony-mode maintainer's here. Also using ROS at work. If you use catkin, then you can get along with irony-mode easily. I do not have ROS at my disposal right now but you should be able to do ...
Guillaume Papin's user avatar
5 votes
Accepted

Change C indent style for specific project?

A .dir-locals.el file would certainly do the trick! I like to use the function (add-dir-local-variable MODE VARIABLE VALUE) rather editing .dir-locals.el manually. For those two values eval (let ((...
ebpa's user avatar
  • 7,579
5 votes
Accepted

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

With irony-mode, you can use M-x irony-get-type RET. This probably won't work for everything but it worked for the following snippet: int main() { auto var = 1.0; return var; } Having the ...
Guillaume Papin's user avatar
4 votes
Accepted

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

It indicates that you are using the electric indentation feature. The different minor modes, and their flags, are explained in the manual: (info "(ccmode) Minor Modes"). You can also get there by C-h ...
Tyler's user avatar
  • 22.8k
4 votes

Why does flycheck open a new buffer for error messages?

I recently experienced the same problem while editing Haskell and Typescript code, so I don't think irony-mode is at fault here. According to the documentation, I understand this is an expected ...
user6234673's user avatar
4 votes
Accepted

c++-mode-map does not stay empty after (setq c++-mode-map (make-sparse-keymap))

Messing with keymaps is usually best done after the defining library has loaded. (with-eval-after-load "cc-mode" (setq c++-mode-map (make-sparse-keymap)))
phils's user avatar
  • 53k
3 votes

Auto format messy code

The code you posted has several issues which needs to be fixed. I will explain a semiautomatic method. This will enable you to fix code which has different issues, with the same method. This code is ...
jue's user avatar
  • 4,686
3 votes
Accepted

automatically close type parens in C++

Have a look at the package smartparens. It can be installed from melpa. You can enable pairs of <> with: (sp-with-modes '(c-mode c++-mode) (sp-local-pair "<" ">")) after (require '...
jue's user avatar
  • 4,686
3 votes
Accepted

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

It's due to having the ( in column 0. You can set open-paren-in-column-0-is-defun-start to nil to prevent the bad indentation, although this may cause Emacs to take a long time indenting and/or ...
npostavs's user avatar
  • 9,253
3 votes

Gray-out preprocessor conditionals

Sorry that I didn't see this earlier. This should only happen in older hide-ifdef-mode in Emacs v24 or earlier. For any Emacs version newer than 25.1 (released 2016/09/17), the aforementioned Hide ...
Luke Lee's user avatar
  • 171
3 votes

Linking to c++ libraries in babel code block

Use :libs to specify libraries. ((or `c `cpp) (org-babel-eval (format "%s -o %s %s %s %s" (pcase org-babel-c-variant (`c org-babel-C-compiler) (`cpp org-babel-C++-compiler)) ...
Frank Liu's user avatar
3 votes

how to call a c++ function from elisp

For reasons that are beyond the scope of this posting, GNU Emacs doesn't have a foreign function interface (FFI), and hence cannot call C or C++ functions out of the box. (XEmacs used to have an FFI, ...
jch's user avatar
  • 5,800
3 votes
Accepted

How to hide header line in C++ mode?

You are seeing the header line of semantic-stickyfunc-mode. There are essentially two ways to switch it on/off. You can globally switch it on/off by customizing global-semantic-stickyfunc-mode. The ...
Tobias's user avatar
  • 33.7k
3 votes
Accepted

Error running timer ‘lsp--on-idle’: (error "The connected server(s) does not support method textDocument/documentLink

I got the solution from gitter.im. Setting the below in .spacemacs file worked (setq lsp-enable-links nil)
Rajkumar Natarajan's user avatar
3 votes
Accepted

Auto insert include guard in cpp header when inside projectile project

Thanks to f-sasa, I was able to write my own yasnippet file in order to construct the include guard. With the help of this yasnippet example and also this thread about getting the projectile file path ...
johhnry's user avatar
  • 31
3 votes
Accepted

C/C++ with tree sitter: how to change indent?

You may want to reuse most of an existing style so that your init.el does not add 100 new lines of indentation rules for every language. For the C/C++ family, they provide a custom option to add your ...
Charles G's user avatar
  • 175
2 votes

spacemacs how to show the documentation of a function during autocomplete in c-c++ layer

Its a long time since I asked that question, and I have found an answer by myself now. For others I would like to post my findings here: Basically there are two different implementations of source ...
smile1324's user avatar
2 votes

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

In some recent versions of Emacs, there's actually a new syntactic element available to handle lambdas: inlambda. This might be a bit clearner to use rather than a custom specifier function. As an ...
Xaldew's user avatar
  • 1,281
2 votes

irony mode not working in ubuntu 16.04

I'm pretty sure you're missing the company-irony mode here. As far as I know, irony is not enough for autocompleting. At least not with your setup. I'll first explain a kind-of-short answer to it ...
anachronic's user avatar
2 votes

Gray-out preprocessor conditionals

'hide-ifdef-mode' hides, but it doesn't do the preprocessor evaluation, since that can come from multiple places, most of which aren't available to an Emacs mode which is just looking at a single file....
Willy Lee's user avatar
  • 480
2 votes

Auto convert dot `.` to arrow `->` in C/C++?

Not completely automatic, but flycheck-ycmd supports that because it uses Clang under the hood and Clang's fix-its are available from Emacs. Position the point under the variable, just do M-x ycmd-...
Daniel Martín's user avatar
2 votes
Accepted

Globally set C++ source block header arguments

I found out, that I have to use cpp instead of C++ to get it working: #+PROPERTY: header-args:cpp :var x=1.0 #+header: :exports results #+header: :includes <iostream> #+begin_src cpp std::cout ...
theldoria's user avatar
  • 1,855
2 votes

Linking Multiple Implementation Files in C on Emacs

Emacs has a builtin tetris game, a psychoanalyst, and a bunch of other fun stuff, but AFAIK it does not have a linker (nor a C compiler), so I think you're either looking at the wrong place, or asking ...
Stefan's user avatar
  • 26.7k
2 votes

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

Clang has an option to disable this warning. Adding the following to my config fixed the issue for me. (with-eval-after-load "flycheck" (setq flycheck-clang-warnings `(,@flycheck-clang-warnings ...
Artem Yu's user avatar
  • 185

Only top scored, non community-wiki answers of a minimum length are eligible