# [texworks] SCRIPTING: Autocompletion based on the current file.

Henrik Skov Midtiby henrikmidtiby at gmail.com
Sun Jan 30 13:00:34 CET 2011

An embedded and charset-unspecified text was scrubbed...
Name: warning1.txt
URL: <http://tug.org/pipermail/texworks/attachments/20110130/007f9656/attachment.txt>
-------------- next part --------------
Attached is the updated autocomplete script.

There are two main changes.
1) The script will no longer enter an infinite loop if activated with
non alphanumeric chars below the cursor.
2) The script will look for completion candidates in all files
currently opened in TeXWorks.

Henrik

On 30 January 2011 12:36, Henrik Skov Midtiby <henrikmidtiby at gmail.com> wrote:
> Hi Paul (and others)
>
> I'm currently looking at the script once more. Primarily for cleaning
> up the code and try to remove a bug where the script enters an
> infinite loop.
>
> The code example looks like exactly what I needed. It will be tested
> later today.
>
> Henrik
>
> On 30 January 2011 12:23, Paul A Norman <paul.a.norman at gmail.com> wrote:
>> Dear Henrik,
>>
>> I really like your script very useful thank you - sorry that it has
>> taken so long to get back.
>>
>> I am going to have more of a look at it over the next few days.
>>
>>>"My question is then how to determine the other tex files witch are
>> opened by texworks when the script is invoked?"
>>
>> This link if you have not already found the information may help, the
>> terminology may have not been obvious.
>>
>> http://twscript.paulanorman.com/docs/html/files/getOpenWindows.html
>>
>> You would want in terms of that link
>>
>> ?var windows = ?TW.app.getOpenWindows();
>> ? var textList = [];
>>
>> ? ? for (editor in windows)
>> ? ? ? ? ?{
>> ? ? ? ? ? ?var targetDocument = windows[editor];
>> ? ? ? ? ? textList.push(targetDocument.text + "\n");
>> ? ? ? ? ? ?}
>>
>> Or augment a string perhaps instead of an array
>>
>> Please let me know if I have misunderstood what you were looking for,
>>
>> Paul
>>
>> On 30 December 2010 23:07, Henrik Skov Midtiby <henrikmidtiby at gmail.com> wrote:
>>> WARNING: This e-mail has been altered by the NFIT virus/spamfilter. ?Please see below for a record of the changes made.
>>> . In case of problems consider contacting the sender or postmaster at nfit.au.dk
>>>
>>> -------Change report:
>>>
>>> An attachment named autocomplete.js was removed from this document as it
>>> the sender and arrange an alternate means of receiving it.
>>>
>>>
>>> A new version of the script is available. It is now context aware with
>>> respect to the commands \label \ref and \pageref.
>>> If you try to complete a parameter to a \label it will only search for
>>> matches which itself are parameters to the commands \ref and \pageref.
>>>
>>> Comments and suggestions are welcome.
>>>
>>> Best regards,
>>> Henrik Skov Midtiby
>>>
>>> On 27 December 2010 08:59, Henrik Skov Midtiby <henrikmidtiby at gmail.com> wrote:
>>>> Hi
>>>>
>>>> I have just started messing around with the texworks scripting
>>>> capabilities, and a lot of possibilities begin to appear. I hope to
>>>> find time to explore it further ;-)
>>>>
>>>> My first real script is a kind of autocompleter, inspired by the one
>>>> found in vim. It looks at the word you were typing when the script was
>>>> activated and locates matching words in the current file. The script
>>>> is uploaded to the script issue [1].
>>>>
>>>> Some ideas for where the script can be improved:
>>>> * look for matching words in related files (files opened by texworks,
>>>> bibtex file, ...)
>>>> * context aware: only locate labels when autocompleting a parameter to
>>>> a \ref command
>>>>
>>>> My question is then how to determine the other tex files witch are
>>>> opened by texworks when the script is invoked?
>>>>
>>>> Best regards,
>>>> Henrik Skkov Midtiby
>>>>