Hot answers tagged

11 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, ...
user avatar
10 votes

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

UPDATE: I created Semantic Refactor package that completely solves this problem and more. You can look at the demos to see how it works. The remaining text of this answer, after this sentence, is old ...
user avatar
  • 6,652
9 votes
Accepted

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

This is a bit disppointing, because ffap.el has some code that should do just that: ;; Immediate rejects (/ and // and /* are too common in C/C++): ((member name '("" "/" "//" "/*" ".")) nil) ...
user avatar
  • 4,440
9 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. ...
user avatar
  • 11.3k
8 votes
Accepted

How to automatically create neat C comment blocks while typing?

The below code works fine from my brief testing in a c-mode buffer: After typing /*, hit M-j, the default binding for indent-new-comment-line (and the default binding for c-indent-new-comment-line in ...
user avatar
  • 24.2k
8 votes

Emacs does not contain package "package"

OS-X comes with emacs 22, which is several years out of date. One easy way to get a current emacs is by downloading from http://emacsformacosx.com/. This will give you package.
user avatar
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 ...
user avatar
  • 7,059
6 votes

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

this seems to answer the member function bit of your question (font-lock-add-keywords 'c++-mode `((,(concat "\\<[_a-zA-Z][_a-zA-Z0-9]*\\>" ; Object identifier "\\s *" ...
user avatar
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.
user avatar
5 votes
Accepted

Hook that indicates when the cursor has been moved by scrolling

Yes. The functions in window-scroll-functions are called just before a redisplay that would cause scrolling. Each function returns two arguments, the window window and the new window start position ...
user avatar
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 ...
user avatar
  • 2,595
5 votes
Accepted

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 ...
user avatar
  • 29.8k
5 votes

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. (defun my-c-transpose-args-...
user avatar
  • 7,059
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 ...
user avatar
  • 7,059
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 ...
user avatar
  • 24.2k
4 votes

Does your project use Elisp for build automation?

I had a similar idea once, but honestly? there are quite a few things that a proper build system needs, and which will require quite a lot of work. One thing you want is memorizing things you've ...
user avatar
  • 10.8k
4 votes

How to set up hotkey for compiling c code and run the compiled file?

Here is a start. Add to your .emacs file: (global-set-key [f4] 'compile) You can also enter the "f4" and "compile" interactively. Starting out with M-x global-set-key Compile is a generic for ...
user avatar
  • 858
4 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, ...
user avatar
  • 1,491
4 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 ((...
user avatar
  • 6,794
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 ...
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. ...
user avatar
  • 19.5k
3 votes
Accepted

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

Quoting deps.mk: ## This file is included in src/Makefile if AUTO_DEPEND=no.\ So it's kind of a fallback file only used to give dependencies to make sure compilation ordering is right. You want to ...
user avatar
  • 25.2k
3 votes
Accepted

How to make an alias in eshell

In eshell aliases $* is replaced by the list of arguments passed after the aliased command. (You can also use $1 to get the first argument, $2 for the second, etc.) So, try alias gcc "gcc -Wall -...
user avatar
  • 8,912
3 votes

emacs cscope integration basics

You can check my C/C++ guide for all the needs above: You can use GNU Global with ggtags or helm-gtags, which can be installed through MELPA. GNU Global can use cscope backend, but you should use its ...
user avatar
  • 6,652
3 votes
Accepted

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

You can install irony-mode and see full information of each completion candidates; it looks like this. Alternatively, you can also use company-clang that comes with company that gives you something ...
user avatar
  • 6,652
3 votes

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

The following command should do it. It passed my tests, and has no external dependencies. (defun endless/copy-proto-to-header-file () (interactive) (save-excursion ;; c-mode's `beginning-of-...
user avatar
  • 22.3k
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 ...
user avatar
  • 19.1k
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 #+...
user avatar
  • 1,734
3 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 @...
user avatar
  • 7,059
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"
user avatar

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