Code Browsing, Refactoring, Auto Completion in Emacs

Autocompletion with Emacs and tags

Have you tried ac-source-gtags that is comes together with auto-complete package? You can also combine several sources, like described in documentation...

Emacs code completion for C/C++?

CEDET is just great, certainly needs some time at the beginning but worth it though.

Emacs how to auto-complete words of include files on C?

First generate tags for the source and include files you'd like to be able to autocomplete for. See my blogpost for tips on using tags if you didn't use tag tables before.

Now if you have a TAGS table that includes the stdio.h, then you can autocomplete 'printf' using the command `complete-tag'.

Perhaps bind `complete-tag' to a key:

(global-set-key [f3] 'complete-tag) 

How do I get the Eclipse project effect out of Emacs?

I'd suggest a combination of projectile + ctags + ECB (or just CEDET) + cscope.

Projectile offers easy navigation in a project's files and some nice functions like text search, tags regenerations, etc. ECB is an Emacs Code Browser that makes Emacs appear more IDE-like, CEDET will give you smart code completion and cscope will give you the ability to find usages (amongst other cool features).

Is it possible to make C++ autohinting in emacs cc-mode?

You can bind . and > with semantic-complete-self-insert command, that will try to show list of possible completions. Although I don't know, is it possible out of box to bind it to :: sequence (although, it should be possible with some amount of emacs lisp code)

How can I refactor C++ source code using emacs?

I do this a lot, so I'm axiously awaiting other replies too.

The only tricks I know are really basic. Here are my best friends in Emacs when refactoring code:

M-x query-replace

This allows you to do a global search and replace. You'll be doing this a ton when you move methods and commonly-accessed data to other classes or namespaces.

C-x 3

This gives you a display with two buffers side-by side. You can then proceed to load different files in them, and move your cursor from one to the other with C-x o. This is pretty basic stuff, but I mention it because of how powerful it makes the next one...

C-x (
(type any amount of stuff and/or emacs commands here)
C-x )

This is how you define a macro in emacs. Any time you find yourself needing to do the same thing over and over to a bunch of code (and it is too complex for query-replace), this is a lifesaver. If you mess up, you can hit C-g to stop the macro definition, and then undo (C-_) until you are back to where you started. The keys to invoke the macro are C-x e. If you want to do it a bunch of times, you can hit Esc and type in a number first. Eg: Esc 100 C-x e will try to invoke your macro 100 times.

(Note: On Windows you can get "Meta" by hitting the Esc key, or holding down Alt).

Emacs code validation

I assume that you're referring to basic syntactic correctness, in which case you should look at flymake, which is included with Emacs, and which runs a validation program in the background, parses its output, and marks up the buffer with errors and warnings.

And, to get you started, here is a small module for using flymake with Ruby, and a similar one for flymake with javascript using jslint as the validation program.

open include files in emacs as you can in msvc (visual c++)

C-c C-o, which runs the command ff-find-other-file, is what you are looking for. It will open the included file when the point is on the #include line.

Googling for emacs code browsing also reveals

  • ECB (Emacs Code Browser)
  • How can I best do source code browsing inside Emacs?
  • code browsing, refactoring, auto completion in Emacs


Related Topics



Leave a reply



Submit