12 votes

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

The Emacs one is actually better. Here's why, The purpose of syntax highlighting in text editors is not being pretty, but to make important code structures stand out. If you look at the Emacs sample, ...
finalpatch's user avatar
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
  • 18k
9 votes
Accepted

Writing C++ (or other) code using lisp

It sounds like a job for YASnippet The philosophy behind it is to shorten the amount of keystrokes to enter frequently used structures and to not repeat yourself while writing the boilerplate code. ...
Ury Marshak's user avatar
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
  • 280
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
6 votes
Accepted

Weird indentation behavior in C++ mode

It's not weird; std: could be a label and until you type the second : it doesn't know otherwise. Edit: I forgot to mention, but you can customize c-default-style to choose a different indentation ...
db48x's user avatar
  • 18k
6 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,576
5 votes

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

color-identifiers-mode does this for variables, if I understand your question correctly. rainbo-identifiers-mode too, I think. Screenshot is from the former one.
Alejandro Erickson's user avatar
5 votes
Accepted

Best C++ indexer?

I can only tell for rtags that I have been using actively for the last 1-2 years. rtags works as expected. It is compiler based and provides correct code navigation. Something I have been looking for ...
log0's user avatar
  • 320
5 votes

Binding compile command to a key for c++ code

You need to do two things: 1. Bind compile to a key (like f5) 2. Change the command that compile runs. To do the first add (define-key c++-mode-map [f5] #'compile) to your .emacs. This sets the key ...
erikstokes's user avatar
  • 12.9k
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,479
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
5 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
  • 8,796
4 votes

tab and spaces shown aligned in emacs C++ mode, but not in other editors

The normal convention is that TAB characters align to the next multiple-of-8 column. Notice: I wrote 8, not 4. So if your other text editor aligns to a multiple-of-4 column (like you seem to imply), ...
Stefan's user avatar
  • 26.4k
4 votes
Accepted

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

You can add a function for that to arglist-cont-nonempty. In the following example my-c-lineup-arglist-lambda should do what you want: (c-add-style "work" '((indent-tabs-mode . nil) ...
theldoria's user avatar
  • 1,835
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
  • 51.1k
3 votes
Accepted

Override c++-mode font lock

Font-lock use two phases: The syntactic phase. In this phase, Emacs determines things like strings and comments. The keyword phase, i.e. the normal font-lock rules. If you want to make Emacs ignore ...
Lindydancer's user avatar
  • 6,160
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

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
  • 161
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,203
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,576
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,576
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,730
3 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.3k
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.2k
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

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