help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: C Headers completion candidates


From: Drew Adams
Subject: RE: C Headers completion candidates
Date: Thu, 14 Jul 2016 07:27:19 -0700 (PDT)

> I want a set of completion candidates for c-headers, something like
> `auto-complete c headers'. Only, I do not want the complete ac-library
> tagged along, nor do I want the popups.
> 
> Personally, I want to use the icicles interface, where I feel
> comfortable.

Icicles does not provide anything special for completing symbols
in C headers.  Whatever is already available for vanilla Emacs
(e.g. to determine the possible completions for a partial symbol
before the cursor) should be usable with Icicles.

> Step 1. Identifying the context
> --- Example
> #include <vec|>
> ---
> `|' represents the cursor here
> I think I can code the regexp here

What regexp do you mean, here?  If the cursor is at that location
then all that should be needed is a function that takes the name
just before the cursor (e.g. "vec") and returns completions for
it (your step 2).

> Step 2. Set of completion candidates
> Search the $INCLUDE environment variable, with `visited' flags on the
> folders that have been visited; and create the set of completion
> candidates, one in a line

Sounds reasonable.  Maybe someone familiar with Emacs C mode(s)
can speak to what is already available wrt such gathering of
completion candidates.  (Icicles does nothing specific for this,
but if you have a function that provides the completions then
Icicles can make use of it.)

> I hope there is a smarter way?

Maybe there is already a function that gathers completions here.
Wait to hear from those who are familiar with Emacs C modes.

If there is not then you can code it, along the lines you
suggested (using $INCLUDE etc.).

> Step 3. Tell Icicles to invoke these set of completion candidates,
> when the context is active. How? I do not know.

As Stefan mentioned, `completion-at-point-functions' is a list
of functions that, in the current mode (e.g. C mode), perform
completion for a name (e.g. a "symbol") that is just before the
cursor.

If there is already a function on the list that is the value of
that variable when you are in C mode, then try it.  `C-M-i'
is bound to `complete-symbol' - this is what you would use to
complete the symbol (name) at point.

If that command uses the minibuffer to let you choose among
completions when there is more than one, then (in Icicle mode)
you can take advantages of Icicles completion automatically.

But probably it does not use the minibuffer for this.

If `C-M-i' does not use the minibuffer when there are multiple
choices, but instead expects you to keep hitting `C-M-i' to
cycle to another choice, then you will need to use another
command instead, which does use the minibuffer (e.g. bind it
to `C-M-i' or some other key, in C mode).  (If a command uses
the minibuffer with completion then you can use it with Icicles
completion.)

In that case, you will need to code that command.  If there is
already a function on list `completion-at-point-functions' in
C mode, then you can model the Icicles command that you will
add to list `completion-at-point-functions' on that existing
function.

The only change you should need to make is for the case when
multiple completions are available.  In that case, call
`completing-read', passing the list of completions as argument,
to read the chosen candidate.  Then, delete the partial name
just before the cursor and replace it by that chosen completion
(just as the vanilla code does).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]