TMTOOLS Help

version 0.905 by Hans-Jörg Bibiko

teaser

Table of Contents


1 Outline

The TMTOOLS plug-in is a conglomeration of shell commands which provide the user with advanced functionality to interact with TextMate.

It is based on code fragments of tm_dialog 1.x and 2.x. Furthermore I was inspired by: Allan Odgaard, Joachim Mårtensson, Chris Thomas, Ciarán Walsh, and Håkan Waara.

Important Note:

The TMTOOLS plug-in calls undocumented TextMate functions without an appropriate API.

     The usage of that plug-in is at your own risk!

 


2 Usage

To use the TMTOOLS plug-in write a shell command:

 "$TMTOOLS" verb command {options}
 ... | "$TMTOOLS" verb command -

For help type the following into an empty line of a TextMate document and press CTRL+R

 "$TMTOOLS" help me

verb := [ get | set | move | insert | call | goto | show | close | reload | delete | scroll | complete | use | do | help ]

The plug-in sets an environment variable “$TMTOOLS” automatically. “TMTOOLS” only interacts with TextMate if you invoke it from a document, meaning this plug-in doesn’t work with the Bundle Editor, Web Preview, etc. in order to avoid unstableness.

options must be written as ‘Property List’. If the property list will be piped to TMTOOLS one has to write a - (a hyphen) to tell TMTOOLS to read the options on STDIN.

Each value given in the Property List will be evaluated as string and converted internally if needed.

2.1 version

In order to get TMTOOLS’ version type

"$TMTOOLS" -v

Bash Example

It checks whether TMTOOLS is installed and if the current version is greater or equal 0906. If not it will download the plug-in.

            if [ -z "$TMTOOLS" ]; then
                open "http://email.eva.mpg.de/~bibiko/downloads/textmate/TMTools.tmplugin.zip"
                exit_discard
            fi

            VERSION=$("$TMTOOLS" -v)

            if [ $VERSION -lt 906 ]; then
                open "http://email.eva.mpg.de/~bibiko/downloads/textmate/TMTools.tmplugin.zip"
                exit_discard
            fi

3 Syntax

3.1 get

In general get asks Textmate for something.

3.1.1 allBookmarks

            "$TMTOOLS" get allBookmarks
            echo -n "{format=plain;}" | "$TMTOOLS" get allBookmarks -

3.1.2 allBundleItems

            "$TMTOOLS" get allBundleItems

3.1.3 allBundles

            "$TMTOOLS" get allBundles

3.1.4 allCommands

            "$TMTOOLS" get allCommands

3.1.5 allEnvironmentVariables

            "$TMTOOLS" get allEnvironmentVariables '{format=plain;}'
            "$TMTOOLS" get allEnvironmentVariables '{variables=(TM_LINE_NUMBER, TM_SELECTED_TEXT, TM_SCOPE);}'

3.1.6 allGrammars

            "$TMTOOLS" get allGrammars

3.1.7 allPreferences

            "$TMTOOLS" get allPreferences

3.1.8 allSnippets

            "$TMTOOLS" get allSnippets

3.1.9 allSymbols

            "$TMTOOLS" get allSymbols

3.1.10 allTemplates

            "$TMTOOLS" get allTemplates

3.1.11 antiAliasEnabled

            "$TMTOOLS" get antiAliasEnabled

3.1.12 autoIndent

            "$TMTOOLS" get autoIndent

3.1.13 bundlePathsForUUID '{uuid="XXX"}'

            "$TMTOOLS" get bundlePathsForUUID '{uuid="0D42D5EE-5800-40A6-AD0E-29C3F56FAF16";}'

3.1.14 completionListFor '{prefix="XXX"}'

            "$TMTOOLS" get completionListFor '{prefix="Text"}'
            echo -n "prefix=$TM_CURRENT_WORD;format=plain;" | "$TMTOOLS" get completionListFor -

3.1.15 contentOfWindow '{pathContains="XXX"}'

            "$TMTOOLS" get contentOfWindow '{pathContains="MyDocument"}'

3.1.16 currentCharacter

            "$TMTOOLS" get currentCharacter

3.1.17 currentFontName

            "$TMTOOLS" get currentFontName

3.1.18 currentFontSize

            "$TMTOOLS" get currentFontSize

3.1.19 currentGrammarUUID

            "$TMTOOLS" get currentGrammarUUID

3.1.20 currentGrammar

            "$TMTOOLS" get currentGrammar

3.1.21 currentSpellCheckerLanguage

            "$TMTOOLS" get currentSpellCheckerLanguage

3.1.22 currentStyleSheet

            "$TMTOOLS" get currentStyleSheet

3.1.23 currentSymbol

            "$TMTOOLS" get currentSymbol

3.1.24 currentWordChars

            "$TMTOOLS" get currentWordChars

3.1.25 currentWord

            "$TMTOOLS" get currentWord '{delimiter=" ()";}'
            "$TMTOOLS" get currentWord '{only=head;}'
            "$TMTOOLS" get currentWord '{only=tail;delimiter=" ():.";}'

3.1.26 defaultBundle

            "$TMTOOLS" get defaultBundle

3.1.27 foldingsEnabled

            "$TMTOOLS" get foldingsEnabled

3.1.28 freehandMode

            "$TMTOOLS" get freehandMode

3.1.29 frontMostDocument

            "$TMTOOLS" get frontMostDocument

3.1.30 hardWrap

            "$TMTOOLS" get hardWrap

3.1.31 hasSelection

            "$TMTOOLS" get hasSelection

3.1.32 indentedPaste

            "$TMTOOLS" get indentedPaste

3.1.33 isContinuousSpellCheckingEnabled

            "$TMTOOLS" get isContinuousSpellCheckingEnabled

3.1.34 isDocumentEdited

            "$TMTOOLS" get isDocumentEdited

3.1.35 lineHead

            "$TMTOOLS" get lineHead

3.1.36 lineTail

            "$TMTOOLS" get lineTail

3.1.37 mainScreenSize

            "$TMTOOLS" get mainScreenSize

3.1.38 openDocumentFiles

            "$TMTOOLS" get openDocumentFiles
            "$TMTOOLS" get openDocumentFiles '{format=plain;shellEscape;}'
            eval mate `"$TMTOOLS" get openDocumentFiles '{format=mate;}'` untitled
            L=$("$TMTOOLS" get openDocumentFiles '{format=mate;}')
            "$TMTOOLS" do closeAllFloatingDocumentWindows
            eval mate "$L" untitled
            FRONTMOSTFILE=$("$TMTOOLS" get frontMostDocument '{urlEscape;}')
            eval mate `"$TMTOOLS" get openDocumentFiles '{format=mate;}'` untitled
            open "txmt://open/?url=file://$FRONTMOSTFILE"
            "$TMTOOLS" close allFloatingDocumentWindows
            open "txmt://open/?url=file://$FRONTMOSTFILE"

3.1.39 openProjectFiles

            "$TMTOOLS" get openProjectFiles
            "$TMTOOLS" get openProjectFiles '{format=plain;urlEscape;}'

3.1.40 overwriteMode

            "$TMTOOLS" get overwriteMode

3.1.41 positionUnderCaret

            "$TMTOOLS" get positionUnderCaret

3.1.42 selectionXML

            "$TMTOOLS" get selectionXML

3.1.43 showBookmarksInGutter

            "$TMTOOLS" get showBookmarksInGutter

3.1.44 showLineNumbersInGutter

            "$TMTOOLS" get showLineNumbersInGutter

3.1.45 showSoftWrapInGutter

            "$TMTOOLS" get showSoftWrapInGutter

3.1.46 smartTyping

            "$TMTOOLS" get smartTyping

3.1.47 softTabs

            "$TMTOOLS" get softTabs

3.1.48 softWrap

            "$TMTOOLS" get softWrap

3.1.49 standardUserDefaults '{key="XXX"}'

            "$TMTOOLS" get standardUserDefaults '{key=OakTextViewNormalFontName;}'

3.1.50 suggestedExtensionForDocument

            "$TMTOOLS" get suggestedExtensionForDocument

3.1.51 textString

            "$TMTOOLS" get textString

3.1.52 textXML

            "$TMTOOLS" get textXML

3.1.53 uuidFor '{name="XXX"; kind="YYY";}'

            "$TMTOOLS" get uuidFor '{name="Lorem ipsum"; kind="snippet";}'
            "$TMTOOLS" get uuidFor '{name="defaultBundle"; kind="bundle";}'

3.1.54 windowOriginAndSize

            "$TMTOOLS" get windowOriginAndSize

3.1.55 wordHead

            "$TMTOOLS" get wordHead

3.1.56 wordTail

            "$TMTOOLS" get wordTail

3.2 set

In general set sets something in the current document.

3.2.1 antiAliasEnabled '{to=X;}'

             "$TMTOOLS" set antiAliasEnabled '{to=no;}'

3.2.2 autoIndent '{to=X;}'

             "$TMTOOLS" set autoIndent '{to=no;}'

3.2.3 bookmarks '{to=(X,Y,...);}'

             "$TMTOOLS" set bookmarks '{to=(5,10,15,20,25);}'

3.2.4 caretTo '{line=X;index=Y;}'

            "$TMTOOLS" set caretTo '{line=2;index=4;}'
            "$TMTOOLS" set caretTo '{index=end;}'
            "$TMTOOLS" set caretTo '{line=2;}'
            "$TMTOOLS" set caretTo '{index=4;}'

3.2.5 continuousSpellCheckingEnabled '{to=X;}'

             "$TMTOOLS" set continuousSpellCheckingEnabled '{to=no;}'

3.2.6 expandSnippetsOnTab '{to=X;}'

             "$TMTOOLS" set expandSnippetsOnTab '{to=no;}'

3.2.7 foldingsEnabled '{to=X;}'

             "$TMTOOLS" set foldingsEnabled '{to=yes;}'

3.2.8 fontName '{to="XXX";}'

             "$TMTOOLS" set fontName '{to="Monaco";}'

3.2.9 fontSize '{to=X;}'

             "$TMTOOLS" set fontSize '{to=14;}'

3.2.10 freehandedEdit '{to=X;}'

             "$TMTOOLS" set freehandedEdit '{to=yes;}'

3.2.11 frontMostDocument '{to="XXX";}'

            "$TMTOOLS" set frontMostDocument '{to="/Users/TextMate/index.html";}'

3.2.12 grammar '{to="XXX";}'

             "$TMTOOLS" set grammar '{to="Plain Text";}'

3.2.13 indentedPaste '{to=X;}'

             "$TMTOOLS" set indentedPaste '{to=no;}'

3.2.14 lineNumbering '{to=X;}'

             "$TMTOOLS" set lineNumbering '{to=no;}'

3.2.15 overwriteMode '{to=X;}'

             "$TMTOOLS" set overwriteMode '{to=yes;}'

3.2.16 selectionTo '{line=X;column=Y;length=Z}'

            "$TMTOOLS" set selectionTo '{line=2;column=3;}'
            "$TMTOOLS" set selectionTo '{length=-2;}'

3.2.17 selectionToCurrentScope

             "$TMTOOLS" set selectionToCurrentScope

3.2.18 showBookmarksInGutter '{to=X;}'

             "$TMTOOLS" set showBookmarksInGutter '{to=yes;}'

3.2.19 showInvisibles '{to=X;}'

             "$TMTOOLS" set showInvisibles '{to=yes;}'

3.2.20 showSoftWrapInGutter '{to=X;}'

             "$TMTOOLS" set showSoftWrapInGutter '{to=yes;}'

3.2.21 smartTyping '{to=X;}'

             "$TMTOOLS" set smartTyping '{to=no;}'

3.2.22 softTab '{to=X;}'

             "$TMTOOLS" set softTab '{to=yes;}'

3.2.23 spellCheckerLanguage '{to=XXX;}'

             "$TMTOOLS" set spellCheckerLanguage '{to=en_GB;}'

3.2.24 tabWidth '{to=X;}'

             "$TMTOOLS" set tabWidth '{to=8;}'

3.2.25 windowOrigin '{x=X;y=Y;}'

             "$TMTOOLS" set windowOrigin '{x=100;y=150;}'

3.2.26 windowSize '{width=X;height=Y;}'

             "$TMTOOLS" set windowSize '{width=100;height=200;}'

3.2.27 wordChars '{to="XXX";}'

             "$TMTOOLS" set wordChars '{to="_$";}'

3.3 move

In general move moves something in the current document.

3.3.1 move caretBy '{line=X;index=Y;}'

             "$TMTOOLS" move caretBy '{index=-2;}'

3.3.2 move caretToCenter

             "$TMTOOLS" move caretToCenter

3.3.3 move selectionBy '{line=X;column=Y;}'

             "$TMTOOLS" move selectionBy '{line=-2;column=-3;}'

3.4 insert

In general insert inserts something in the current document.

3.4.1 snippet '{value="XXX";}'

             "$TMTOOLS" insert snippet '{value="\${1:Hello} - \${2:World}\${3:}";}'

3.4.2 text '{value="XXX";}'

             "$TMTOOLS" insert text '{value="Hello World";}'

3.5 call

In general call executes an item which is stored as bundle item.

3.5.1 bundleItem '{uuid="XXX";}'

             "$TMTOOLS" call bundleItem '{uuid="DA0A4E77-5F16-11D9-B9C3-000D93589AF6";}'

3.5.2 command '{name="XXX";}'

             "$TMTOOLS" call command '{name="Add Line Numbers to Document / Selection";}'

3.5.3 command PLIST

            "$TMTOOLS" call command '
                <dict>
                    <key>beforeRunningCommand</key>
                    <string>nop</string>
                    <key>command</key>
                    <string>
                        A=$(cat)
                        echo -e "$A"
                        echo -en "Hello World"
                    </string>
                    <key>input</key>
                    <string>selection</string>
                    <key>fallbackInput</key>
                    <string>word</string>
                    <key>output</key>
                    <string>showAsTooltip</string>
                </dict>
                '

3.5.4 macro '{name="XXX";}'

             "$TMTOOLS" call macro '{name="Delete Line";}'

3.5.5 macro PLIST

            "$TMTOOLS" call macro '{
                commands = (
                    {command = "moveWordRight:"; },
                    {command = "moveWordLeftAndModifySelection:"; },
                    {command = "moveWordLeftAndModifySelection:"; },
                    {command = "moveWordLeftAndModifySelection:"; }
                );
            }'

            "$TMTOOLS" call macro '<?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/#PropertyList-1.0.dtd">
            <plist version="1.0">
            <dict>
                <key>commands</key>
                <array>
                    <dict>
                        <key>argument</key>
                        <dict>
                            <key>action</key>
                            <string>replaceAll</string>
                            <key>findInProjectIgnoreCase</key>
                            <false/>
                            <key>findString</key>
                            <string>Textmate is good</string>
                            <key>ignoreCase</key>
                            <true/>
                            <key>replaceAllScope</key>
                            <string>document</string>
                            <key>replaceString</key>
                            <string>TextMate is extraordinary</string>
                            <key>wrapAround</key>
                            <true/>
                        </dict>
                        <key>command</key>
                        <string>findWithOptions:</string>
                    </dict>
                </array>
            </dict>
            </plist>
            '

3.5.6 snippet '{name="XXX";}'

             "$TMTOOLS" call snippet '{name="Lorem ipsum";}'

3.5.7 template '{name="XXX";}'

             "$TMTOOLS" call template '{name="From Clipboard";}'

3.6 goto

In general goto goes to an item.

3.6.1 nextBookmark

             "$TMTOOLS" goto nextBookmark

3.6.2 nextSnippetField

             "$TMTOOLS" goto nextSnippetField

3.6.3 prevBookmark

             "$TMTOOLS" goto prevBookmark

3.6.4 prevSnippetField

             "$TMTOOLS" goto prevSnippetField

3.7 show

In general show opens a panel or window.

3.7.1 alertSheet

             "$TMTOOLS" show alertSheet '{informativeText="This is only a info";
                messageTitle="This is a message";buttonTitles=(OK,Cancel);alertStyle=critical;}'

3.7.2 bundleEditor

             "$TMTOOLS" show bundleEditor

3.7.3 bundleMenu

             "$TMTOOLS" show bundleMenu

3.7.4 contextMenu

             "$TMTOOLS" show contextMenu

3.7.5 openPanel

             "$TMTOOLS" show webPreview

3.7.6 printPanel

             "$TMTOOLS" show printPanel

3.7.7 projectDrawer '{onEdge=X;}'

             "$TMTOOLS" show projectDrawer '{onEdge=0;}'

3.7.8 saveAsPanel

             "$TMTOOLS" show saveAsPanel

3.7.9 webPreview

             "$TMTOOLS" show webPreview

3.8 close

In general close closes windows.

3.8.1 allAuxiliaryWindows

             "$TMTOOLS" close allAuxiliaryWindows
             "$TMTOOLS" close allAuxiliaryWindows '{except=(OakFindPanel, OakBundleEditorWindow);}'

3.8.2 allFloatingDocumentWindows

             "$TMTOOLS" close allFloatingDocumentWindows

3.8.3 allWindows

             "$TMTOOLS" close allWindows

3.9 reload

In general reload reloads something.

3.9.1 allBundles

             "$TMTOOLS" reload allBundles

3.10 delete

In general delete deletes something.

3.10.1 allBookmarks

             "$TMTOOLS" delete allBookmarks

3.11 scroll

In general scroll scrolls the window content of the current document.

3.11.1 columnLeft

             "$TMTOOLS" scroll columnLeft

3.11.2 columnRight

             "$TMTOOLS" scroll columnRight

3.11.3 lineDown

             "$TMTOOLS" scroll lineDown

3.11.4 lineUp

             "$TMTOOLS" scroll lineUp

3.11.5 windowToCaret

             "$TMTOOLS" scroll windowToCaret

3.12 complete

In general complete will show a pull-down menu of suggestions. While typing this list will be updated automatically. This code is mainly taken from Joachim Mårtensson. Changes are only done for the event handling. This pull-down menu will not interfere with tm_dialog.

3.12.1 path

             "$TMTOOLS" complete path

3.12.2 usingDictionary

             "$TMTOOLS" complete usingDictionary
             "$TMTOOLS" complete usingDictionary '{lang="de_DE";}'
             "$TMTOOLS" complete usingDictionary '{lang="da";showInternalListFirst=yes;}'

3.12.3 usingDocument

             "$TMTOOLS" complete usingDocument

3.13 use

In general use is an API to cocoa’s objects.

3.13.1 nsstring '{initWith="XXX"; toGet="YYY"}'

            "$TMTOOLS" use nsstring '{initWith="ö"; toGet="decomposedStringWithCanonicalMapping";}'
            "$TMTOOLS" use nsstring '{initWith="รถ"; toGet="decomposedStringWithCanonicalMapping";}'
            "$TMTOOLS" use nsstring '{initWith="hello"; toGet="hasPrefix:"; with="he"; }'
            "$TMTOOLS" use nsstring '{initWith="hello"; toGet="length"; }'
            "$TMTOOLS" use nsstring '{initWith="hello"; toGet="rangeOfString:"; with="el"; }'
            "$TMTOOLS" use nsstring '{initWith="hello"; toGet="smallestEncoding"; }'
            "$TMTOOLS" use nsstring '{initWith="A:B:C"; toGet="componentsSeparatedByString:"; with=":"; }'
            "$TMTOOLS" use nsstring '{initWith="hello"; toGet="compare:"; with="hel"; }'
            "$TMTOOLS" use nsstring '{initWith="たてもの"; toGet="characterAtIndex:"; with="2"; }'
            "$TMTOOLS" use nsstring '{initWith="たてもの"; toGet="canBeConvertedToEncoding:"; with="8"; }'
            "$TMTOOLS" use nsstring '{initWith="/Users/TextMate"; toGet="lastPathComponent";}'
            "$TMTOOLS" use nsstring '{initWith="たてもの"; toGet="stringByAddingPercentEscapesUsingEncoding:"; with="4"; }'
            "$TMTOOLS" use nsstring '{initWith="%E3%81%9F%E3%81%A6%E3%82%82%E3%81%AE";
                            toGet="stringByReplacingPercentEscapesUsingEncoding:"; with="4"; }'
            "$TMTOOLS" use nsstring '{initWith="{z=({a='b';});}"; toGet="propertyList";  }'
            "$TMTOOLS" use nsstring '{initWith="юри"; toGet="caseInsensitiveCompare:"; with="Юри"; }'

3.14 do

In general do executes something or implements an event handler.

3.14.1 centerWindow

             "$TMTOOLS" do centerWindow

3.14.2 checkUUID '{uuid="XXX";}'

             "$TMTOOLS" do checkUUID '{uuid="67CBC425-6A5B-4621-97A1-147C8CEC221A";}'

3.14.3 miniaturizeAllWindows

             "$TMTOOLS" do miniaturizeAllWindows

3.14.4 onKeyDownAfterDelay '{delay=T; shell="XXX"; }' or PLIST

            "$TMTOOLS" do onKeyDownAfterDelay "{delay=2;
                    shell='\"$TMTOOLS\" call command \'{name=\"ShowCurrentScopeToolTip\";}\''; stopkey=53; }"
            "$TMTOOLS" do onKeyDownAfterDelay "{delay="0.5";
                    shell='\"$TMTOOLS\" complete usingDictionary \"{lang=de_DE;}\"'; stopkey=53; }"
            "$TMTOOLS" do onKeyDownAfterDelay "{delay="1.5"; repeat=yes; startAtCall=no;
                    shell='\"$TMTOOLS\" complete usingDocument'; stopkey=53; }"
            "$TMTOOLS" do onKeyDownAfterDelay "{delay="5"; repeat=no; startAtCall=no;
                    shell='\"$TMTOOLS\" get textString > /tmp/\"$TM_FILENAME\".txmtbkp;say \"document was saved\"'; stopkey=53; }"

            "$TMTOOLS" do onKeyDownAfterDelay '
                <dict>
                    <key>delay</key>
                    <string>2</string>
                    <key>beforeRunningCommand</key>
                    <string>nop</string>
                    <key>command</key>
                    <string>
                        A=$(cat)
                        echo -e "$A"
                        echo -en "Hello World"
                    </string>
                    <key>input</key>
                    <string>selection</string>
                    <key>fallbackInput</key>
                    <string>word</string>
                    <key>output</key>
                    <string>showAsTooltip</string>
                </dict>
'

3.14.5 openFileInNewWindow

             "$TMTOOLS" do openFileInNewWindow

3.14.6 openFileWithFinder

             "$TMTOOLS" do openFileWithFinder

3.14.7 redo

             "$TMTOOLS" do redo

3.14.8 revealFileInFinder

             "$TMTOOLS" do revealFileInFinder

3.14.9 saveCurrentDocument

             "$TMTOOLS" do saveCurrentDocument '{avoidPanel;}'
Attention: If one uses that command without the option `avoidPanel` and the current document is an ‘untitled’ document within of a script —not as the last command—, all following commands will be ignored! This also could lead that TextMate freezes and/or some modifications won’t be saved! An other side-effect could be that TextMate registers more than one instance of the same file!
To avoid such a behaviour it is always the best to use the option avaoidPanel and react to the return value.

3.14.10 saveWithFilenameAndReopen '{name="XXX";}'

             "$TMTOOLS" do saveWithFilenameAndReopen '{name="/Users/TextMate/test.txt";overwriteMode;}'
             FILENAME="$TM_SELECTED_TEXT"
             EXT=$("$TMTOOLS" get suggestedExtensionForDocument)
             filename="$(CocoaDialog filesave --with-directory `dirname "$TM_FILEPATH"` --with-file "$FILENAME.$EXT" )"
             if [ -n "$filename" ]; then
                 echo "{name=\""$filename"\";overwriteMode;}" |"$TMTOOLS" do saveWithFilenameAndReopen -
             fi

3.14.11 undo

             "$TMTOOLS" do undo

3.14.12 zoomWindow

             "$TMTOOLS" do zoomWindow

3.15 help

3.15.1 me

             "$TMTOOLS" help me

4 Release Notes

4.1 Release 0900

4.2 Release 0901

4.3 Release 0902

4.4 Release 0903

4.5 Release 0904

4.6 Release 0905

4.7 Release 0906


5 Contact

If there are further suggestions or bugs don’t hesitate to mail me.

26 October 2007 - Hans-Jörg Bibiko bibiko@eva.mpg.de