[OS X TeX] BBAutocomplete script for TeXShop

Ramón M. Figueroa-Centeno ramonf at hawaii.edu
Wed Mar 4 05:08:30 CET 2009


Hi,

Here is an AppleScript to use BBAutoComplete
<http://c-command.com/bbautocomplete/> in the front most window of TeXShop.

It adds auto-completion for words already in the document and in the
system's dictionary (check BBAutoComplete's preferences). It fulfills a wish
for TeXShop posted in this list :)

It can be improved in at least two ways:

(a) It could be written to follow "\input" commands.
(b) Standard LaTeX keywords can be added using a list.

(a) requires some thought; but (b) should be easy.

Ramón

--Applescript direct

-- Script to use BBAutoComplete in TeXShop
-- Ramon Figueroa-Centeno (March 3, 2009)
-- http://www2.hawaii.edu/~ramonf

tell application "TeXShop"
    
    activate
    
    set the front_document to the front document
    
    -- The whole text of the document
    set whole_document to the text of the front_document
    
    -- The offset of the selection
    set selection_offset to offset of the selection of the front_document
    
    -- make Completion
    tell application "BBAutoComplete"
        set theCompletion to complete word starting at offset
selection_offset ¬
            in text whole_document
    end tell
    set {startOffset, endOffset, completionText} to theCompletion
    
    display dialog (startOffset as string) & ":" & (endOffset as string) &
return & completionText
    
    set the offset of the selection of the front_document to startOffset
    set the length of the selection of the front_document to endOffset -
startOffset + 1
    
    set the content of the selection of the front_document to completionText
    
    set the offset of the selection of the front_document to endOffset +
(count of completionText)
    set the length of the selection of the front_document to 0
    
end tell

-- 

Ramón M. Figueroa-Centeno, Ph.D.
Associate Professor

Mathematics Department
University of Hawaii at Hilo
College Hall 4-A
200 W. Kawili St.
Hilo, HI 96720-4091

(808) 974-7387 (office)
(808) 933-3473 (fax)

http://www2.hawaii.edu/~ramonf/

PGP/GnuPG Public Key at http://www2.hawaii.edu/~ramonf/ramonf.gpgkey





More information about the macostex-archives mailing list