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]

is for C source code editing, completions, formatting, compiling, folding, searching, executing, syntax checking, debugging, and other modern IDE features that Emacs supports.

16
votes
1answer
2k views

How to automatically create neat C comment blocks while typing?

Some code editors such as eclipse automatically form neat blocks when you start typing a multi-line comment: Is there some package or another way to do this in emacs too? Edit: To clarify: I do not ...
11
votes
3answers
1k views

How can I automatically insert a prototype in foo.h from foo.c?

Suppose I'm writing a C program in a file foo.c: int add_numbers(int x, int y, int z) { // Very complex implementation here. return x + y + z; } I want a command that will insert a ...
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 ...
8
votes
4answers
423 views

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

In Verilog/C/C++, comments can begin with //. Here's an example comment, //This is a comment I like to use the find-file-at-point feature. If my cursor is on the file name in `include "some_file.v"....
7
votes
2answers
636 views

Hook that indicates when the cursor has been moved by scrolling

Inspired by this question: Let Emacs move the cursor off-screen, I am considering writing a minor mode that will keep the cursor in a fixed position that is not affected by scrolling operations. I ...
7
votes
1answer
177 views

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

I want to be able to view C source code of Emacs functions. For example, I want to be able to do M-: (find-function 'message). Emacs prompts me for directory the C sources, so it can set find-...
6
votes
2answers
137 views

How to add a new .c file to Emacs source code

I've added my own .c file to Emacs /src directory as well as the following lines emacs.o: ... file.c file.h file.o: file.c in deps.mk I get file.o generated, but it is not linked when generating ...
6
votes
2answers
4k views

emacs cscope integration basics

I am a long term eclipse CDT user migrating to emacs (ver. 23.3.1), because I have to work on a large C codebase accessible only through a telnet/ssh shell. After going through several online guides, ...
5
votes
2answers
181 views

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

How to swap two arguments for C function calls? eg: my_function(foo, bar, baz); ~~~~~~~~~~~~~^ (cursor location) Should be transposed to the right to make: my_function(bar, foo, baz); The simple ...
5
votes
2answers
733 views

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?
5
votes
2answers
111 views

Swap two statement on adjacent lines in C when one statement takes multiple lines

Assume that I have the following code: int x; string s = "some very long " " string"; I would like to have one command that swaps the order of these without ending up with something like: ...
4
votes
3answers
1k views

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

Is it possible to syntax highlight doxygen in C/C++ code? QtCreator and Vim both support basic highlighting so \param, \note... etc are highlighted differently.
4
votes
1answer
1k views

C brace indentation

I am new to Emacs and trying to learn the basics. I am writing a few C programs and I noticed that the default brace indentation is as follows: for(i = 0; i < 10; ++i) { // code }...
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
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
142 views

Turn C Electric Indentation off only for specific characters

Extending Customizing c-mode indentation behavior in emacs-24.4 How can electric indentation be disabled for other specific keys without disabling the entire mode? Specifically, how can electric ...
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
2k views

Emacs does not contain package “package”

I want to add C auto-completion at least so that I can use Emacs on a regular basis as my C editor. I am new to Emacs, and I had already it installed in my system, because it came with the OS (I think)...
2
votes
2answers
232 views

Does your project use Elisp for build automation?

I'm building a new appliance, linking BusyBox with Tor on top of a minimal GNU/Linux operating system. I'd like to try something different for the automated build infrastructure with this one and ...
2
votes
1answer
7k views

Auto-complete C/C++ functions

I want code completion for C/C++ functions and variables from headers. I tried to install Auto-complete and Company, but C/C ++ functions/variables aren't complemented. Here is the relevant portion ...
2
votes
1answer
601 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
1answer
360 views

How to make an alias in eshell

I want to make an alias in eshell so that when I type gcc it actually does gcc -Wall -pedantic -std=c99 but when I make the alias, it just displays gcc -Wall -pedantic -std=c99 and doesn't actually ...
2
votes
2answers
79 views

Automatically insert a space in some C expressions

The corporate rules about indention forces us to surround our if conditions with spaces like this (in a C and C++ codebase) : if (<space>foo == bar<space>) { } Is there any emacs tool ...
2
votes
1answer
1k views

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

I'm not finding a lot of examples/documentation for the non-REPL world of C/C++ in Emacs org-mode babel. For example, is there a way to break a program up into separate source code blocks, i.e., a ...
2
votes
0answers
13 views

Custom indentation for macros in C mode

I'm working in a codebase with an extensive use of function macros and I'm having some difficulty finding the correct way to set indentations with them. Specifically, we pass a lot of statement lists {...
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
0answers
93 views

How to modify behavior of syntax highlighting without editing the original source?

There is a bug in C/C++ comment highlighting (bug 11865) Where the fix appears to be to modify the value of c-font-lock-doc-comments Is there a way to do this in my emacs config, instead of having ...
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
715 views

How to display type of C variable in a curses type menu?

A friend of mine who uses vim had this useful feature enabled, that allowed him to see type/completion information in a dropdown window even in terminal mode. Currently in emacs I have to actually ...
1
vote
3answers
2k views

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

I recently moved from Code::Blocks to Emacs to write C code. The one thing I don't like (because it takes too much time and effort for a simple and repetitive task) is the fact that I can't compile/...
1
vote
1answer
178 views

Compile and run C-Programs in Emacs

I'm currently learning C with a book that has many small code examples that the reader is supposed to write, run and experiment with. I'm using Emacs as my primary tool for everything that has to do ...
1
vote
3answers
146 views

Emacs equivalent of the following vim operation

In the answer to a question on Quora, Gilles Castel wrote an answer highlighting the power of vim. The Question was: How would you write a C program to print 1 to 100 without loop, recursion, or ...
1
vote
1answer
128 views

#ifdef __cplusplus nuisance: How to prevent extra indenting?

If you ever wrote header files that have to be used by both C compiler and C++ compiler, you'd encounter this particular ifdef. This construct causes one to insert extra curly braces in the header ...
1
vote
2answers
201 views

What is the good resource for getting started using EMACS? [duplicate]

I have not used EMACS seriously in 20 years. I work on a Mac and am a vi/Eclipse person now. I want to switch back to EMACS for C and C++ programming. When I was researching EMACS add-on packages ...
1
vote
1answer
448 views

Change C indent style for specific project?

I have in my ~/.emacs.d/init.el: (use-package google-c-style ;; provides the Google C/C++ coding style :ensure t :config (add-hook 'c-mode-common-hook 'google-set-c-style)) However, a ...
1
vote
1answer
49 views

c-basic-offset is not influencing indentation of c/cpp files

No matter how I set this value I get this message when I try to describe it. Its value is 2 Original value was set-from-style Local in buffer .... ; *Global value is 3* I don't know what is ...
1
vote
2answers
1k views

How to run C/C++ code in Org Babel?

I'm trying to execute C and/or C++ snippets in Org Babel. For example, I want to be able to execute the following snippet with C-c C-c: #+begin_src C printf ("Hello World!"); #+end_src The ...
1
vote
1answer
771 views

Completion for variables in C using company-gtags, or not Semantic

I have a working C IDE without Semantic (too slow for me), from instructions here, with completion provided by company-gtags (I think. Maybe clang does something too?). Completion at point works for ...
1
vote
1answer
540 views

Emacs (semantic) include not working for relative personal includes

This works: Running semantic-decoration-include-visit (opens the included header): #include <string.h> #include "/usr/include/gtk-3.0/gtk/gtk.h" Works well. This does not: But if I ...
1
vote
1answer
364 views

How to indent C correctly

I've read several answers on here and on Google and have tried several solutions but nothing is fixing this for me. Right now, if I try to write C code Emacs indents it like so: #include <stdio....
1
vote
2answers
897 views

Why does hook to set up C++ mode indentation not work?

This is my code (defun my/set-c-mode () (local-set-key (kbd "C-c C-c") 'compile) (setq compilation-finish-function 'compilation-exit-autoclose-clone) (setq c-default-style "linux") (setq c-indent-...
1
vote
0answers
40 views

Align elements of a matrix to the right

I have a matrix in C++ Matrix<double> A = { {31, -13, 0, 0, 0, -10, 0, 0, 0}, {-13, 35, -9, 0, -11, 0, 0, 0, 0}, {0, -9, 31, -10, 0, 0, 0, 0, 0}, {0, 0, -10, 79, -30, 0, 0, 0, -...
1
vote
0answers
155 views

Is this a c-default-style? If not, how can i configure it?

I've just started using spacemacs and the docstrings for cc-styles are a bit daunting. I've also just started working on a new project in c, and would like to keep consistent with existing style: ...
1
vote
2answers
247 views

Org-babel. :flags in C code blocks dont work correctly anymore

I'm trying to run current code block #+HEADERS: :includes <math.h> <stdio.h> :flags -lm #+HEADERS: :var x=1.0 :var y=4.0 :var z=10.0 #+begin_src C :tangle trying double pi = 4*atan(1); ...
1
vote
0answers
39 views

annotate C's function list static or not in Speedbar

Is there any way to configure Speedbar to tag functions in the buffer static or extern for C? If not, how can I make it?
1
vote
0answers
41 views

Parsing non-standard C with gtags

I'm working with a codebase that's meant to be built with a proprietary C compiler using tons of esoteric language extensions. Ideally, I'd like to stick to my chosen environment as much as possible, ...
1
vote
0answers
134 views

Is CEDET/semantic obsolete? How to analyze C code for source transformation tasks?

Reading through some CEDET docs I found that the author herself recommends "to use Semantic only as source of information, and perform names completion using other packages". Does this advice also ...
1
vote
0answers
70 views

Doxygen style for c-doc-comment-style? [duplicate]

The option c-doc-comment-style supports javadoc, autodoc and gtkdoc. Is there a way to get doxygen support? (\returns, \note, \brief... etc)
1
vote
0answers
101 views

Structures are defined using a macro, flycheck gives errors

In our source code we surround structures with a macro (MKDIFF) that serves as a flag for the Makefile system. It does not expand into anything, just a flag. Flycheck (understandably) flags these ...
1
vote
0answers
89 views

Getting gdb to work for this project

For this project, I cannot seem to get M-x gdb to work in Emacs 25.1 (on Ubuntu 14.04.5 64-bit if it matters - this should be the case for any Ubuntu-based Linux in general I imagine). Steps to ...