Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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
  • 18.3k
7 votes

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

This can be done by changing comment-start & comment-end. (add-hook 'c-mode-hook (lambda () (setq comment-start "//" comment-end ""))) Found the answer ...
ideasman42's user avatar
  • 8,826
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,499
5 votes
Accepted

Auto-complete C/C++ functions

A vanilla company install wont quite get you where you want; you'll need to use use something like the company-c-headers package. Tuhdo has written an excellent document on using Emacs as a C/C++ IDE, ...
Gastove's user avatar
  • 1,551
5 votes
Accepted

C brace indentation

As mentioned in this answer on SO, you can do: (setq c-default-style "bsd") This will set the style for all C-based modes. If you want to set it only for one, do e.g.: (add-to-list 'c-default-style ...
Scott Weldon's user avatar
  • 2,715
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

How to transpose two arguments of a function call for C family languages?

The following transposes two arguments of c-functions. The first argument is the one with point in it. It is followed by the second arg and separated by a comma. It looks for arguments by skipping ...
Tobias's user avatar
  • 33.3k
5 votes
Accepted

How to transpose two arguments of a function call for C family languages?

Based on @Tobias's excellent answer. this extends it to have both forward and backward transpose. correct cursor location. don't move the cursor if there is nothing to do. Note that this happens to ...
ideasman42's user avatar
  • 8,826
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,826
4 votes

How do I disable ffap (find file at point) when the first two non-space characters in a line are '//'?

Thanks to the solution posted by @Sigma. I had that solution in my config for more than 2 years, and finally sent that as a patch to emacs upstream. Commit in emacs master: e472cfe8 Here is what the ...
Kaushal Modi's user avatar
  • 25.7k
4 votes
Accepted

Syntax highlight doxygen comments in C/C++? (c-doc-comment-style)

Posting own answer since I didn't find an existing method *. This is generic Doxygen highlighting, it doesn't try to be too strict since doxy supports so many different expressions. \[anything] and @...
ideasman42's user avatar
  • 8,826
4 votes

How can I compile and run my C code from within Emacs like I would with the terminal?

I use the compile command, and also add a run target to my makefile like this program: program.cpp gcc program.cpp -o program run: program program So you can just use make run to compile ...
Ian4264 's user avatar
4 votes

How to get the following indentation style in c?

First, customize c-hanging-braces-alist to use the style settings: I think that's the default, but since you've been mucking around with customizing it, go back and make sure it is set to the default. ...
NickD's user avatar
  • 30.5k
3 votes

Compile and run C-Programs in Emacs

Since you are using Org-mode and all you want (according to your post), is to evaluate small C code examples, I'd use ob-C and just evaluate everything using org-babel. This is not an answer on how ...
Daniel's user avatar
  • 3,653
3 votes

Stuck at input emacs gdb debugging C program /* enter doesn't end text input */

Type your input in the "input/output" window. Not in the "gud" window. In the layout shown in GDB User Interface Layout it is the one labled "I/O buffer for debugged pgm"
emacs-user's user avatar
3 votes
Accepted

Emacs equivalent of the following vim operation

Emacs has keyboard macros with counter support. The gist of the solution would be (assuming default key bindings): F3 to start recording a macro Type printf("%d", " F3 to insert the macro counter ...
glucas's user avatar
  • 20.6k
3 votes

C/C++ coding in Emacs org-mode's babel

You can do this by using the noweb reference syntax: First we define some named code blocks #+NAME: srcMyfunc #+BEGIN_SRC C void myfunc() { printf("print from function\n"); } #+END_SRC #+...
dfeich's user avatar
  • 1,904
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

#ifdef __cplusplus nuisance: How to prevent extra indenting?

Set the inextern-lang offset to 0 in c-offsets-alist for your indentation style. Here's some code adapted from my own init file that creates a C style called wvxvw and defines it to have 4-space ...
Gilles 'SO- stop being evil''s user avatar
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
  • 165
2 votes

How can I build/package Emacs so that the C source files are installed to a standard find-function-C-source-directory?

If what you are asking is "how to include source code in my Arch package", it doesn't seem to belong here but maybe https://unix.stackexchange.com/. Are there configuration options Emacs' makefile ...
Yasushi Shoji'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
  • 470
2 votes

Syntax highlight doxygen comments in C/C++? (c-doc-comment-style)

I just released a package for highlighting Doxygen comments. In addition to highlighting Doxygen commands and their arguments, it highlights code examples according to the language they are written in....
Lindydancer's user avatar
  • 6,170
2 votes

Syntax highlight doxygen comments in C/C++? (c-doc-comment-style)

Here's an attempt at improved Doxygen syntax highlighting based on ideasman42 answer. The code: (require 'cc-mode) (defface doxygen-verbatim-face '((default :inherit default)) "Face used to show ...
John32ma's user avatar
2 votes
Accepted

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

Support for toggling between block-style and line-style comments was added a few months ago, and should be included in the next release. If you have a snapshot of the development version of emacs (...
Toon Claes's user avatar
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.5k
2 votes

What is the good resource for getting started using EMACS?

If your project uses cmake, cmake-ide is a good start. Or else, use company(auto completion)+counsel-gtags(code navigation)+global You can use helm-gtags instead of counsel-gtags. Both packages are ...
chen bin's user avatar
  • 4,877
2 votes

How can I compile and run my C code from within Emacs like I would with the terminal?

M-! let's you type a shell command and M-x shell takes you to a shell window. I'd probably set up makefile/CMake and run that. Also if you install flycheck it should show you live if there are any ...
Anton's user avatar
  • 163
2 votes

How to find where a given function is called from in gtags

That would be ggtags-find-reference, bound by default to M-]. Also, using the "standard" ggtags-find-tag-dwim (M-.) on a function's prototype should show you its call sites.
Valentin Schneider's user avatar
2 votes

Eshell - ./hello command not found(gcc)

As my comment said, the executable is hello.exe, not hello, thus you should use ./hello.exe instead.
xuchunyang's user avatar
  • 14.6k

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