Archive for the ‘bundles’ tag
Creating Bundles with TextMate
As a starter I write small programs that I’d like to see executed at once. The book has two suggestions for those who are using MacOSX:
a) Use xCode ( which is a software that I’ll need to learn somewhere in the remote future )
b) Use Gcc through command line. ( which is what I had in mind since day 1 actually )
However I felt uncomfortable having a terminal open along with TextMate just to compile programs. So I start looking for a shortcut that will do the job for me, nothing complicated: Just compile the current .m file, run it and show eventual errors otherwise the output.
I searched the manual and I found the apple-command+B shortcut which tries to compile the .m file with xCode unsuccessfully. The problem is that xCode looks for xCode-projects inside the working directory, so it does not recognize on the fly the specific file.
After that I looked at macromates for other info, because I was sure that something similar already exists. Nothing though, the Build command was bounded to xCode for .m files.
At this point I joined the IRC textmate support channel on Freenode. A found a Greek guy under the nickname cskiadas which helped me create my first bundle!
It was easier than expected! TextMate surprised me in a very positive way already! So what I did was:
Bundles -> Bundle Editor -> Edit Commands | New Commands
Following cskiadas advice I did not put the new bundle under Objective-C Bundles, I put it under my own Bundle category created by TextMate. The first thing we need to do is satisfy the Scope Selector which in my case was source.objc. Then following the GUI was easy to create a key shortcut I decide for apple-command+B which is the default shortcut for Build. I decide to watch the output in tooltip mode which is much more convenient and fancy than Document mode, which open’s another document and paste’s the output. Mr. cskiadas told me that tooltip may have issues with large text. Kept that in mind, but after all.. changing that option takes 3 seconds. Now the hard part was to put together the code that compiles & run’s the file. Mr. cskiadas helped with a short example and key feature to go peaceful with .m files.. here is the code:
# just to remind you of some useful environment variables
# see Help / Environment Variables for the full list
#echo File: "$TM_FILEPATH"
#echo Word: "$TM_CURRENT_WORD"
#echo Selection: "$TM_SELECTED_TEXT"
#!/usr/bin/sh - atma 05/11/2006
BASE=${TM_FILEPATH%.m}
gcc "$TM_FILEPATH" -o "$BASE" -l objc
# Simple bash check out and compile
if [[ -e $BASE ]]
then
echo "Executing $BASE"
echo ""
exec $BASE
else
echo ""
echo "File does not exist"
fi
The BASE=${TM_FILEPATH%.m} variable saved me from having hard time. The %m option means “without the .m extension”. The $TM_FILEPATH variable stands for full path filename as you can imagine. The rest is simple shell code which I put together with a little goggling ( I didn’t remember the -e variable for bash’s test ) just to make it more elegant.
Now when I type apple-command+B I get the compile & run results on the fly, inside a tooltip!

