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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
53 views

C offset is 2 with treesit

I recently started using treesit and I'm noticing with C files, my auto-indent is 2 spaces. How can I fix this to make it 4 spaces again? I've tried c-basic-offset.
user129393192's user avatar
2 votes
2 answers
1k views

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

I use Emacs with tree sitter for c++ code (c++-ts-mode). With usual c++-mode I've used this fix for me: (c-set-offset 'inline-open '0) but I don't understand how to do it in new c++-ts-mode. In ...
Sergey's user avatar
  • 223
0 votes
1 answer
74 views

Emacs not opening existing file, only opens new file

I recently started coding in C (college class) and use Emacs as my primary text editor. In my class, we use the terminal to create new files and open existing ones, and I decided I wanted to be able ...
minerva_png's user avatar
0 votes
0 answers
63 views

How to configure Emacs to support indented C preprocessor statements?

In some cases I deal with code that has heavily indented C preprocessor statements and want to setup Emacs to work with it without changing that indentation and follow the same indentation when having ...
PRouleau's user avatar
  • 786
0 votes
1 answer
152 views

flycheck can't find header file even though flycheck-clang-include-path configured

I am using Doom Emacs as my editor for C. I'm trying to use glib in my C project and for that I'm including glib.h. I have added the include dirs displayed by pkg-config --cflags glib-2.0 to flycheck-...
Johnny's user avatar
  • 1
0 votes
0 answers
25 views

How to set brace style for empty function in Doom emacs?

When defining an empty function Doom emacs makes it such that the function automatically looks like this: // after inserting braces void my_func() {} // after pressing enter void my_func() { } /...
Krys's user avatar
  • 95
0 votes
0 answers
42 views

Can not get irony-mode to show completions

I'm a new Emacs user, and want to get autocompletion in C using irony-mode. I installed elpa-irony using apt, as well as irony-server using apt, as the CMake compilation fails. I added these lines to ...
theboringkid's user avatar
0 votes
0 answers
27 views

Make ff-find-other-file ignore include directive in C

I have a binding setup as described here, the problem is every time the cursor is on #include "file" it always tries to jump on this include. I want that no matter where there cursor is I ...
Yuki's user avatar
  • 111
0 votes
1 answer
75 views

Babel C++ blocks have incorrect indentation

When using a C++ source block in org-mode, the indentation doesn't match that of the C++ major mode. Viewing the source block in the org file: Viewing the same code in a C++ mode buffer or using org-...
dag-h's user avatar
  • 1
0 votes
0 answers
146 views

When using company and lsp, why does the placeholder text sometimes not get replaced?

In a buffer in c-mode with the following content (with point after retu), pressing enter completes to return expression;. int main(int argc, char** argv) { retu } Point is now at the beginning of ...
ruds's user avatar
  • 143
0 votes
0 answers
131 views

Rewriting paths for bazel

The Bazel build tool has some features that interact poorly with emacs. When you build a C/C++ project for sandboxing purposes it makes a crazy hierarchy of symlinks, and uses them when invoking GCC. ...
Joseph Garvin's user avatar
0 votes
0 answers
27 views

Emacs displays letters and spaces as newlines until a non-letter/space char is entered

I am editing a C file, and it suddenly starts moving to a new line instead of showing the character I typed. This seems to be for letters and space. However, it has saved the characters, and if I type ...
Bill Purvis's user avatar
0 votes
1 answer
125 views

Emacs displays different formatting than what actually is

I have been using emacs for a while now, I am relatively new to it but while editing i noticed that sometimes emacs will show the code correctly formatted, when i open it with another text editor ...
user2742982's user avatar
1 vote
0 answers
25 views

Customized c-mode indentation style in Emacs 27.2

I would like to produce c code in the following format: char *ft_strdup(const char *s1) { char *h; size_t len; ... } Where I can tab after the type of the function signature and ...
Egydio Pacheco's user avatar
1 vote
1 answer
116 views

Is there a way to display breadcrumbs in C mode in a headerline or another window

I am using emacs (GNU Emacs 25.3.2) on Ubuntu. I was wondering if its possible to display short breadcrumbs or selected compound statement in a headerline (even another window is fine). Probably I am ...
Aval Sarri's user avatar
0 votes
0 answers
12 views

Strange flush left C-code formatting in Emacs 24.3 of SLES 12 SP5

I see some odd Emacs behavior in C-mode recently. I suspect that the change happened either when switching from SLES 12 SP4 to SLES12 SP5 (both have Emacs 24.3), or when switching from SLES 11 SP4 (...
U. Windl's user avatar
  • 193
3 votes
1 answer
200 views

How to get the following indentation style in c?

I would like to have the following behavior: int main(){ to result in: int main(){ | } Where pipe is the cursor, and I DON'T have to press RETURN key after '{'. I have already achieved the ...
Typedragon33's user avatar
1 vote
1 answer
303 views

How do I populate tags for C?

I hover over stdlib: #include <stdlib.h> I type M-. and it asks me: Visit tags table (default TAGS): I don't have one of those. I see a lot of information about TAGS in the emacs ...
Mittenchops's user avatar
0 votes
2 answers
925 views

How to use C header files in org-mode source code blocks?

I have a C code block in my org-mode document like the following: #+begin_src C :exports both #include "my_header.h" int main(void) { function_from_my_header(); return 0; } #+...
bashfuloctopus's user avatar
2 votes
1 answer
257 views

Emacs not indenting enum / enum class contents

I've got a small problem to do with Doom Emacs / Emacs. Enum contents are not indented at all... Here's what I would like: enum class RandomEnum { A, B, C, D }; Here's what I get: ...
Krys's user avatar
  • 95
1 vote
1 answer
83 views

How to pass the current scopes function symbol as an argument to an elisp function

I am trying to create an org-capture template which works with yankpad and yasnippets to such that if I am working with some c code like this: example.c static int somefunc(int a) { if (a ==5) { ...
Reginald Marr's user avatar
0 votes
0 answers
257 views

noweb doesn't expand at all

I have a feeling this must be a stupid simple problem however I just can't seem to figure out what I'm doing wrong. I'm using Doom emacs and trying to use noweb with org mode source code blocks to ...
Reginald Marr's user avatar
1 vote
2 answers
154 views

How to NOT Auto Indent when a specific Character is inputted?

So I recently encountered a problem programming in C that whenever I enter the left parenthesis character, (, Emacs auto-idents the code. [4 spaces here]DATA *SeqQueueOut( I know that there is this ...
user30099's user avatar
3 votes
1 answer
664 views

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

Is there a shortcut to add a semicolon to the end of the current line of code? For instance, M-; inserts a comment at the end of the current line of code. Is there anything like that for a semicolon? ...
mrbean's user avatar
  • 133
1 vote
1 answer
37 views

How to see brief location in the code in C/C++ mode

While editing a long C++ file, I use rtags to jump around. It would be very handy for me to know where I am in terms of where the cursor is relative to the classes-functions. For example, it would be ...
yujaiyu's user avatar
  • 896
0 votes
0 answers
49 views

Use iconv directly on the selected region to convert codes

I copied and pasted the C code as: int main(void) {    statements    return 0; } to org's babel code block, when strike C-c C-c, it report error: /tmp/babel-uaYVXU/C-src-Pd1SZs.c:11:6: error: stray ‘...
Wizard's user avatar
  • 1,241
3 votes
1 answer
125 views

Centering within comment blocks or ASCII art

I have C comments like this: /****************************************************************************** * Includes * ***********...
Vercingatorix's user avatar
1 vote
1 answer
86 views

c-set-style: Error loading guessed style

My company has very specific indentation rules for C code. I want to create a style from those rules, and have it load at startup. Doing a C/Guess Style From This Buffer and C/Install Last Guessed ...
Vercingatorix's user avatar
0 votes
0 answers
186 views

Where is M-x compile?

I have a basic C file open in c-mode: #include <stdio.h> #include <stdlib.h> int main() { return 0; }; I'm trying to compile it. I type M-x compile expecting to be asked to set my ...
Mittenchops's user avatar
1 vote
0 answers
47 views

ETAGS with dependencies

I'm trying to use emacs for C development. From here, I understand that in order to see the definitions of functions, I need to use something called etags. My code is: #include <stdlib.h> #...
Mittenchops's user avatar
1 vote
1 answer
418 views

How can I lint a C file?

I have the following: int main() { int a = 1; int b = 2; return 0; }; I am expecting some lint to align the indentation. My file is open with (C/*l AC Abbrev). I try C-c . which asks me:...
Mittenchops's user avatar
1 vote
1 answer
259 views

Customize org babel execution command in C

I have the following C code: #include <stdio.h> #include <math.h> int main(){ printf("Square = %d", pow(4,2)); return 0; } Now if I run this in the shell. I would first compile ...
mle0312's user avatar
  • 295
1 vote
0 answers
29 views

fork in org-mode babel source block executes incorrectly

I have this small piece of code on emacs org-mode : #+BEGIN_SRC C :eval #+BEGIN_SRC C :fork-example1.c :noweb no-export :eval :flags -Wall -Werror -pedantic //Fork-exemplec-cours.c #include <stdio....
Vincent's user avatar
  • 11
1 vote
1 answer
1k views

Flycheck does not find .h file

I am using Flycheck for my syntax highlighting which have been working out great when working with all header and source files in one directory. I recently decided to add some unit tests to test my ...
ZeppRock's user avatar
  • 113
0 votes
0 answers
74 views

Stepping through c code in emacs

I am trying to step through code in emacs and am looking for a plugin which will displa the contents of an element when I hover over it. Is there any plugin like this currently? How do you step ...
pluto's user avatar
  • 1
1 vote
0 answers
362 views

How do you guys use doxygen? [closed]

I'm curious about Doxygen, how do you guys manage documentation in C/C++ projects on emacs? I didn't find a good package that does it consistently. So far I did use gendoxy and doxymacs. I had ...
Lucas Peixoto's user avatar
1 vote
0 answers
56 views

Is there a package that show the value of constant variables? C/C++

I would like some package that show the variable value when I put cursor on it. The behavior that I expect can be seen in the image below. The image below is in vscode, I would like some package that ...
Lucas Peixoto's user avatar
0 votes
0 answers
22 views

some pointer declarations not colored

macs -nw fails to color code certain declarations of pointer arrays seemingly depending on the structure being pointed to. For example: SomeStruct *one[4] is all white (I have dark background), but ...
Thomas Kirven's user avatar
1 vote
1 answer
48 views

Adding rule to indentation

A code base I work on has the macro #define when break; case to make switch statements 'cleaner' However this causes problems with indentation, Is it possible to set the behavior of 'when' to be ...
Mitchk's user avatar
  • 13
4 votes
1 answer
306 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 {...
Koala Bear's user avatar
3 votes
0 answers
407 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?
hrkrshnn's user avatar
  • 439
7 votes
2 answers
574 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 ...
ideasman42's user avatar
  • 8,556
1 vote
0 answers
146 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, -...
Mike Manilone's user avatar
0 votes
0 answers
196 views

Too much time spent for emacs to open cpp in the project

I use ggtags in order to improve my efficiency. I follow the manual to setup emacs environment. https://tuhdo.github.io/c-ide.html However, during editing the cpp files in the projects. Chance are ...
yuxuan's user avatar
  • 781
3 votes
1 answer
691 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 ...
wvxvw's user avatar
  • 11.3k
0 votes
2 answers
254 views

How to configure C-M-q and TAB key to expand pre-existing TAB characters into spaces in C/C++ files

In C and C++ files, I want to configure the mode so that any time I request indentation, that it will always expand all of the embedded TAB characters in indentation (at the start of the line, and no ...
bgoodr's user avatar
  • 339
-1 votes
1 answer
114 views

Eshell - ./hello command not found(gcc)

emacs was installed by Msys32 on Win7 32bit! gcc can't run hello.c on eshell but on minibuffer, Why?
zhyd1997's user avatar
3 votes
3 answers
13k 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/...
elanonrigby's user avatar
1 vote
0 answers
269 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: ...
Aidenhjj's user avatar
  • 111
1 vote
1 answer
381 views

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

I am using gtags and can jump to where a function is defined. Howeve I am not able to find inside a function where it is begin called from. Is there anyway to find where a function is called from?
Roarer's user avatar
  • 11