[TxMt] TMTOOLS plugin

Thomas Aylott textmate at subtlegradient.com
Mon Sep 24 15:05:12 UTC 2007


Hans-Joerg Bibiko bibiko at eva.mpg.de
Thu Sep 20 07:43:29 GMT 2007

> Hi,
>
> Over the past years I wrote some very tiny code snippets in order to
> save time while using TM. I copy&pasted it from one code to a new
> command etc. Then I had the idea to put everything together in a
> plugin to use my code snippets more flexible.
> Ok, I did this. I took the idea of tm_dialog, Joachim Mårtensson's
> completion menu, and me tiny code snippets. The result is the TMTOOLS
> plugin.
>
> usage:
> "$TMTOOLS" -[fsgiem] -p PLIST
> f --extended-popup
> s --set
> g --get
> i --insert
> e --execute
> m --play macro
>
> Each of the following commands can be used within any tmCommand/
> script written in bash, ruby, perl, etc.
>
> (tentative) LIST OF COMMANDS:
> -----------------------------------------------
> Show as completion menu:
> -TM's internal word list completion
> -Word completion with Cocoa's spellchecker dictionaries of different
> languages
>  (TM's internal word completion list is added before the
> spellchecker's list :)
> -File/Path Completion
>
> -Insert text
> -Insert text as snippet
>
> Set: (also as batch)
> -set word characters
> -place the caret to
> -select something within the document
> -set tab size
> -set soft tabs
> -set soft wrap
> -set the language/grammar by its name
> -set show line numbers
> -set font size
> -set font name
> -set bookmarks for lines
> -set userdefault for a key
>
> -play a dynamic generated macro
>
> Get:
> -get the _current_ text from the document
> -get the XML representation of the document
> -get the XML representation of the selection
> -get the position under the caret
> -get all bookmarks out the current document
> -get all symbols
> -is document edited?
> -get font size
> -get font name
> -get current stylesheet
> -get all opened files in a project
> -get the default for a key
> -get the head of the current line according to the caret
> -get the tail of the current line according to the caret
> -get the head of the current word according to the caret
> -get the tail of the current word according to the caret
>
> Execute: (also as batch)
> -reloadBundles
> -select current scope
> -run any macro, command, template, or snippet by its name
> -open saveAs panel
> -open open Panel
> -open web preview
> -open bundle editor
> -open print panel
> -center selection in window
> -delete all bookmarks
> -go to next/previous snippet field
>
> -convert a text according to unicode's mapping [(de)compose]
>
>
> and some more...
>
>
> One can do very nice things with TMTOOLS.
> E.g., by myself I'm using very often
> -go to next snippet field and show suggestions according the selected
> text, select a suggestion, and go to the next snippet field
> (It was always annoying to see only 'NSStringEncoding'. Now, if the
> snippet field is 'NSStringEncoding' it shows me 'NSUTF8Encoding,
> NSASCIIStringEncoding, NSJapaneseEUCStringEncoding, ...'. Or if the
> snippet field is something like uft8|ascii|utf16, it gives me these
> items as inline menu. )
> -create an HTML page out of my document, change the  font size, and
> open the web preview
> -get all bookmarks, show a inline menu, and go to the selected  
> bookmark
> -open a text document *.txt, set my grammar to a language which
> highlights consonat clusters, hide line numbers
> -open a text document *_jp.txt, set the font name to ForMateKonaVe
> and size to 14pt, to input Japanese
> -the chance to execute dynamic generated macros - very helpful ;)
> -if you have a long text you can set bookmarks to line
> 50,100,150,200,...
>
> To illustrate the syntax of such commands here some examples:
>
> play a macro:
> "$TMTOOLS" -m -p '{
>     commands = (
>         {command = "moveWordRight:"; },
>         {command = "moveWordLeftAndModifySelection:"; },
>         {command = "moveWordLeftAndModifySelection:"; },
>         {command = "moveWordLeftAndModifySelection:"; }
>     );
> }' $val
>
> set a grammar:
> "$TMTOOLS" --set -p '{grammar;to="Objective-C++";}'
>
> set as batch:
> "$TMTOOLS" -s -p '{
>   batch=(
>     {grammar;to=Perl;},
>     {wordchars;to="_$";},  <= this is very useful ;)
>     {caret;toLine=2;toColumn=2;},
>     {selection;toColumn=end;}
>   );
> }'
>
> execute as batch:
> "$TMTOOLS" -e -p '{
>   batch=(
>     {command;name="Add Line Numbers to Document / Selection";},
>     {command;name="Duplicate Line / Selection";},
>     {macro;name="Move to EOL and Insert “.”";}
>   );
> }'
>
> go to next snippet field and show according to its selection a inline
> menu with suggestions:
> "$TMTOOLS" -e -p '{nextsnippetfield;}'
> "$TMTOOLS" -e -p '{command;name="ShowAsList";}'
>
> prepare a coloured print version of my document:
> "$TMTOOLS" -e -p '{command;name="Create HTML From Document /
> Selection";}'
> "$TMTOOLS" -m -p '<?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>font-size: .*?px</string>
> 				<key>ignoreCase</key>
> 				<true/>
> 				<key>regularExpression</key>
> 				<true/>
> 				<key>replaceAllScope</key>
> 				<string>document</string>
> 				<key>replaceString</key>
> 				<string>font-size: 8px</string>
> 				<key>wrapAround</key>
> 				<true/>
> 			</dict>
> 			<key>command</key>
> 			<string>findWithOptions:</string>
> 		</dict>
> 	</array>
> </dict>
> </plist>
> '
> "$TMTOOLS" -e -p '{showwebpreview;}'
>
>
>
> convert the unicode mapping of the entire document:
> IN=$(cat)
> PLIST="{convert;what=\"$IN\";using="nfd";}"
> "$TMTOOLS" -g -p "$PLIST"
>
> #  allowed parameters for key 'using'
> #
> #   nfd   =  decompose according to canonical mapping
> #   nfc   =  compose according to canonical mapping
> #   kd    =  decompose according to canonical compatibility mapping
> #   kc    =  compose according to canonical compatibility mapping
> #
> #  see more at http://www.unicode.org/reports/tr15/
>
>
>
> set the selection from the caret 4 chars back:
> "$TMTOOLS" --set -p '{selection;length=-4;}'
>
>
>
> one has the line "This is rub|bish and" [| = caret]:
> "$TMTOOLS" -g -p '{wordaftercaret;}'
> gives you "bish"
>
>
> Up to now this plugin is more or less a collection. I have to fixed
> some error handlings, unify the output, etc.
>
> So, my question whether it would be worth to clean the code and
> publish it. In other words: Is someone interested in such a plugin?
> One has to mention that TMTOOLS depends on Allan's code. If he
> changes the code maybe one has to adjust TMTOOLS' code as well. Then
> Allan plans to include some of these commands in TM2.
>
> Any feedback?
>
> Cheers,
>
> Hans

Sorry not to reply to this properly and destroy all threading. I've  
been having email issues.

This all sounds extremely awesome and useful.

Am I right in assuming that you'd be able to run that command  
periodically to get all this stuff out of textmate through the plugin  
without interrupting your workflow?

What I've always wanted to be able to do is have an HTML Output window  
open and have it constantly update with all the TM_ variables. There's  
lots of stuff that you could use that for.

You could watch the current document from the background and keep  
track of all the cursor positions where an edit was made and enable  
some sort of back/forward thing like in a browser.

That's just one of the uses I can see for all this.

Where is the code for this or is it all just theory at this point?

Thanks.


—Thomas Aylott – subtleGradient—




More information about the textmate mailing list