Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Determining the index within the current word during completion



How can I determine the index of the cursor within the current word
during completion for all potential inputs, with each character
between the start of the word & the cursor increasing the index by
one, regardless if it is part of an escape sequence or not (or any
other type of character)?

e.g., say the current word is:

1234

For all subsequent words, ^ is not a literal; it is only the location
of the cursor when completions have been requested. I want the
associated index to be returned:

0: ^1234
1: 1^234
2: 12^34
3: 123^4
4: 1234^

I can get that by using ${#PREFIX} for normal characters, but I'm
having problems for escaped characters.

e.g., for the following situations, the ${#PREFIX} won't give the
correct answer:

Current word & cursor: \n^
$PREFIX: n (should be \n)
${#PREFIX}: 1 (should be 2)

Current word & cursor: \^'
$PREFIX: \' (should be \)
${#PREFIX}: 2 (should be 1)

The following return the correct length:

Current word & cursor: \^n
$PREFIX: n (should be \)
${#PREFIX}: 1

Current word & cursor: \'^
$PREFIX: \'
${#PREFIX}: 2

Thanks for any help.




Messages sorted by: Reverse Date, Date, Thread, Author