This is a short post about again another tool for the mac. I was using TextMate as an external text editor. There were a few reasons why I liked it a lot. I am using it mainly for editing files without opening a full blown editor like IntelliJ or DashCode. Since I am doing a lot of java development, I have a lot of property files as well as xml files that I need to edit. I heard about TextMate and got curious, for me there were a few reasons why I liked TextMate a lot.
- Quick startup times
- Possibility to startup TextMate from the command line
# mate <filename>
- Integration with subversion
- Xml formatting
Today I decided to by TextMate, than I saw it was almost 50 euros. that is to much for me for just a text editor. Therefore I started looking for something else. I found the open source tools Smultron. My conclusion, TextMate is better but not worth the 50 euros when you compare them. I did have to integrate an xml formatter to get three of the points out of the four mentioned within Smultron.
read on to find out the small steps I had to take.
Actually installing has two steps, the first step is downloading the application and moving it to the desired location. For me that is the applications folder. The second step is installing the command line. Which is as easy as going to the help menu and choosing the menu item Install Command-Line Utility. You can find the download here:
After unzipping and moving, open de application and go to the mentioned menu item in the help menu. You have to enter your root password twice, which is explained why (for the application and the man pages). Test if everything went well by typing smultron at the command line. It will open the application. It is more useful if you provide a filename at the command line like the following command. Then that file will be opened in smultron
# smultron pom.xml
Now we have a fast text editor with code highlighting and lot’s of other functionality. We can open a file using that editor from the command line. To bad there is no subversion integration, but for my purpose the svn command line application is good enough. Than the final requirement, the xml formatting. This is also not included smultron. But smultron does have an easy way of calling command line applications. The next section deals with just that.
Using Tidy to format xml using smultron
The mac comes standard with a utility called Tidy. I am not sure if this utility is installed the moment you install the developer tools. If it is not installed you can find more information on this page. This is the same page to find information about everything you can do with tidy. I managed to format my files in a reasonable way using the following command
tidy –input-xml true –output-xml true –indent yes –wrap 100 -m pom.xml
Next step is to integrate this with smultron. To be able to do this, we need to add a command. Open the command window by going to the menu tools > Handle Commands > Show Commands Window. There is also a shortcut, command + B. I added my command to the Other collection. Select the Other group and push the plus sign at the right of the screen to create a new command. Give the command a new name, I used format xml document. You can also give it a shortcut. The command is the same as before, only we need the full path. We also provide a special parameter from smultron %%p. This parameters copies the complete path when executing the script.
/usr/bin/tidy –input-xml true –output-xml true –indent yes –wrap 100 -m %%p
Your command window now should look like the following image. If something is not working, check the command result window. Again using the menu tools, or a shortcut alt+shift+command+B.
3 thoughts on “Using smultron as a TextMate alternative”
Great tip thanks
also thanks to Ben for the update on the commandline!
I dont know if its just me, but you dont see the updated version of the file right away. But after a “File->Revert” everything is fine!
If you’re using Snow Leopard it uses a newer version of Tidy and the command line above does not work. Replace it with the following command line:
/usr/bin/tidy -indent -xml -wrap 100 -m %%p
Thanks for posting this.. Code formatting is something I was badly looking for in Smultron..
Comments are closed.