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.
99
questions
0
votes
2answers
71 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;
}
#+...
0
votes
0answers
13 views
Emacs incorrectly indenting C code when auto-fill-mode is enabled
I have this single line in my ~/.emacs:
(add-hook 'prog-mode-hook 'auto-fill-mode)
Now I open a foo.c with Emacs and type this code. I only type the code
and enter. I do not type any tab. This is the ...
0
votes
0answers
55 views
How to change default shell for Emacs on MS Windows?
I'm very new to Emacs (using Doom Emacs) as a former Vim user, and I've been loving it. However, I've been having issues trying to get irony-server to run. From what little I've been able to gather (...
1
vote
1answer
35 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:
...
1
vote
1answer
35 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) {
...
0
votes
0answers
33 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 ...
1
vote
2answers
73 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 ...
0
votes
0answers
87 views
Doom Emacs: Flycheck cannot find header files in gtkmm-3.0
I am attempting to use gtkmm-3.0-dev in a small project. It uses meson as its build tool, and I use ninja to create a compilation database. However, regardless of any variables I set, Flycheck cannot ...
3
votes
1answer
179 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?
...
1
vote
1answer
26 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 ...
0
votes
0answers
20 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 ‘...
0
votes
0answers
33 views
Aligning the colon in multi-line tertiary expressions in C and C++
Suppose I have the following line
double dx = r1 < 1 ? sqrt(r1) - 1 : 1 - sqrt(2 - r1);
I press enter and tab at the colon causing Emacs to align like this:
double dx = r1 < 1 ? sqrt(r1) - 1
...
3
votes
1answer
38 views
Centering within comment blocks or ASCII art
I have C comments like this:
/******************************************************************************
* Includes *
***********...
1
vote
1answer
25 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 ...
0
votes
0answers
70 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 ...
1
vote
0answers
32 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>
#...
0
votes
0answers
31 views
How to fix indentation of anonymous structures in function argument position in C?
I've been stumbling upon this constantly.
Suppose that I have a function that accepts a structure, or a pointer to a structure:
struct s {
int n;
char c;
};
void f(struct s *s);
I'd like to ...
0
votes
1answer
55 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:...
0
votes
0answers
9 views
Focus ggtags-global when it spawns
When I find definitions ggtags-find-tag-dwim and there are multiple results it opens *ggtags-global* but the focus remains in my buffer that initiated the call to ggtags-find-tag-dwim. I'm trying to ...
1
vote
1answer
73 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 ...
1
vote
0answers
23 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....
1
vote
1answer
521 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 ...
0
votes
0answers
54 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 ...
1
vote
0answers
140 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 ...
1
vote
0answers
47 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 ...
0
votes
0answers
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 ...
1
vote
1answer
42 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 ...
4
votes
1answer
191 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
278 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?
7
votes
2answers
409 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 ...
1
vote
0answers
91 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, -...
0
votes
0answers
86 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 ...
2
votes
1answer
346 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 ...
0
votes
2answers
117 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 ...
-1
votes
1answer
76 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?
2
votes
3answers
7k 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
0answers
204 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
1answer
202 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?
2
votes
1answer
583 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 ...
0
votes
1answer
167 views
CEDET semantic-complete-jump customization
When I search through project via semantic-complete-jump and tag is not unique (its defined in multiple places), I must hit <tab> to iterate through all possible places. Problem is, I horribly ...
1
vote
2answers
278 views
cscope-minor-mode not enabled for C in emacs 25
I'm using Emacs 25 on Ubuntu 16.04, after a while spent on Emacs 24. One thing that I've noticed changed in version 25 is, cscope minor mode is not enabled by default when I edit C files, while it was ...
0
votes
0answers
160 views
Performance issue of c-mode
When I'm pressing C-p/n moving the cursor around, the redisplaying is quite lagging. A profile of CPU give
+ command-execute 527 59%
- ...
5
votes
2answers
14k 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'...
1
vote
2answers
329 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
2answers
462 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
1answer
77 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
0answers
49 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
55 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
2answers
2k 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
0answers
192 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 ...