Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How can I make Emacs to complete words that are in C include files ?

#include <stdio.h>
int main(){
print//<-- this is where I want it to complete printf

What's the simplest way? (something simpler than Cedet)

like image 424
Liran Orevi Avatar asked Feb 28 '23 05:02

Liran Orevi


2 Answers

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) 
like image 184
justinhj Avatar answered Mar 07 '23 17:03

justinhj


Unlike complete-tag, dabbrev-expand, or hippie-expand (which does dabbrev-expand like things), the CEDET suite does exactly what the question describes. When asked to perform a completion, it looks and sees that you have included stdio.h, and then looks there for possible completions.

CEDET does a lot of other things related to completion as well which will provide very focused and correct suggestions, not just vaguely similar suggestions. A side affect is that CEDET takes more effort to setup. You need to teach it where you include files are, for example, and sometimes how to deal with macros, and what the project you are working on is like.

There is more detail on this here: link text

like image 23
Eric Avatar answered Mar 07 '23 19:03

Eric