Thanks, I don't know why I didn't think of that...! I'll play around with this a bit and see where I get.

Helge Hafting wrote:
Dov Feldstern wrote:
[...]

Finally, back to word-completion: I've started working on that, but the main problem I've run into is preserving state between consecutive invocations. For example, let's say C-p is bound to this function. So the first time I call C-p, the word which the cursor is at is completed. The problem is, if I immediately (i.e., before moving the cursor or doing anything else in the document) press C-p again, I would like to get the next possible completion. But (a) how do I know that this is not the first call to the completion function, and (b) is there any way to keep track of the list of possible completion that I already found the first time around, so that I don't need to go through the whole buffer again?

I'd appreciate any thoughts or suggestions on this (all of the above).


How to know that it isn't the first call to the completion function:
In C, I would stick a couple of static variables in the function.
(Perhaps C++ have a more fancy OO way, I don't know.)
Static variables keep their value from one call to the next,
as you probably know.
One variable holds the location (in the document) of the last completion, the other is a counter (or similiar) keeping track of how many times you have completed. Or perhaps it is a pointer into your completion data. It all depends on how you
implement completion.

When the completion function is called, it will first check to see if the location is the same as last time. If not, reset the counter as it is a first-time call. Then
update the static location variable to remember this new location, and
perform the first possible completion.

If it is the same location however, then you know that the counter variable
(or pointer or whatever fits for keeping track of completions) is valid. So
you advance to the next possible completion and perform that.

Helge Hafting

Reply via email to