I think that find_ident_at_pos contains a bug. The thing is that
expand("<cWORD>") expands to a non-empty string if positioned over a
whitespace character after a WORD at the start of a line, but to an
empty string anywhere else. I doubt that this is intentional, but it
seems that at least the rubycomplete.vim script and the
pythoncomplete.vim script assume that it always expands to a non-empty
string, and perhaps we need to keep this behavior for backwards
compatability. The problem can be remedied in the scripts by backing
the cursor up to the actual word, but that's not a very good solution.
To try it out, put the following in an empty buffer:
:x.
And position the cursor over/at the trailing space. Then execute
:echo expand('<cWORD>')
The expansion will be empty.
Now, change the buffer to contain only
:x.
and again position the cursor over/at the trailing space. Again execute
:echo expand('<cWORD>')
The expansion will be ':x.'.
nikolai