Table of Contents

# $EPIC: indextoword.txt,v 1.3 2006/08/01 03:47:40 sthalik Exp $

Synopsis:

$indextoword(<position> <text>)

Technical:

Practical:

The most obvious application of this function is to find the word on the input line underneath the cursor. $L is the contents of the input line and $curpos() tells you where the cursor is; you can then use something like this:

$word($indextoword($curpos() $L) $L)

to extract the word “underneath” the cursor. This is the fundamental mechanics of how tab completion scripts know what to complete.

Returns:

A number suitable for use with the word manipulation functions that represents the word that contains the <position>th character in <text>. Both <position> and the return value count from zero.

Examples:

$word($indextoword($curpos() $L) $L)   returns the word under the cursor
@ foo = [one two. three.]
$indextoword($index(. $foo) $foo)      returns 1 (the . in ``two.'')
$indextoword($rindex(. $foo) $foo)     returns 2 (the . in ``three.'')
$indextoword(100 testing)              returns the empty string