OK, so the blogging functionality in TextMate is pretty nice. Its a little primitive, but it does have some cool features and all the text editing features that it offers to boot. I wanted to go back and clean up some old entries using TM, just to play around with it a bit; however, I was a little disappointed that I could not see more than the last 20 entries when choosing the command from the menu “Bundles/Blogging/Fetch Post.” So, since TM is very customizable, I set about fixing this issue, by creating the ability to fetch a post if you know the id of the post in your blogging engine. In order to do this, you must edit the blogging Ruby file in the blogging bundle (which is located in the TextMate.app bundle), and then add a command using the bundle editor. All this is assuming that you have been able to get the blogging functionality working at the base level in TextMate. So, let’s get started – read on…
** Note (added July 31, 2006): After posting this and shutting down, it occurred to me that it would be better to actually add the edited ruby code to an external directory so that it would not be overwritten in the process of updating Textmate; in addition, if you migrate your user to another computer (which I’m about to do soon), Migration Assistant should copy the changes over to the new machine. I’ve changed the content of the tutorial to reflect this change.
Edit “blogging.rb” Ruby file
- Go to the TextMate application.
- Right-click (command click) the TextMate application icon and choose “Show Package Contents” — you will probably have to authenticate.
- In the new window open the sub directory of the path “Contents/SharedSupport/Bundles” — you will see a list of bundles.
- Right-click, as before, the bundle called “Blogging.tmbundle” and choose “Show Package Contents” again.
- In the new window for the Blogging bundle, go into the directory path “Support/lib” — you should see some Ruby files, and one called “blogging.rb”.
- Make a copy of “blogging.rb” and place it into a directory in your user folder. I placed it here: “file:///Users/–username–/Library/Application Support/TextMate/BundleEdits/Blogging/blogging.rb”. (the name BundleEdits for the new folder in the TextMate support folder is arbitrary, but its what I chose…)
- Open the new “blogging.rb” with your text editor (TextMate is fine). (I chose not to use TextMate, just being superstitious.)
- Search for the string “# Command: Fetch” which is the commented line above the Fetch command for the blogging funtionality. Cursor to the line after the “fetch” function definition, and paste the code below:
# fetch_post_page def fetch_post_page begin _password = password self.post = client.getPost(post_id, username, _password) TextMate.exit_create_new_document(post_to_document) @mw_success = true rescue XMLRPC::FaultException => e TextMate.exit_show_tool_tip("Error retrieving post. Check your configuration and try again.") end end # Command: Fetch_By_Id def fetch_by_id if post_id fetch_post_page else TextMate.exit_show_tool_tip("A Post ID is required to fetch the post by id.") end end
- Now save the code and close out the document.
Create a new command in the TextMate Bundle Editor
- Open TextMate and choose menu item “Bundles”, then “Bundle Editor”, and finally “Edit Commands…” (you can also just use the key command of Control-Option-Command-C).
- Open the Blogging section on the left hand side of the Bundle Editor and select “Fetch Post” (but don’t do anything with it)
- Now click the duplicate button at the bottom left (looks like two +’s) to create a new command. Rename the command something like “Fetch Post By Id”
- Paste the following text into the field named “Command(s):”. Make sure that you substitute your system user name and if you did not create a directory called “BundleEdits”, use the name you used there.
#!/usr/bin/env ruby -rjcode -Ku require "Users/--username--/Library/Application Support/TextMate/BundleEdits/Blogging/blogging.rb" Blogging.new.fetch_by_id
- Leave the rest of it the same and close the Bundle Editor.
Open a Post
I have my settings as the default in WordPress, so that it’s fairly easy to find out what the post id is for a particular posting. As the default, the post id is the number at the end of the URL string when you click the permanent link for a posting. Once you’ve gotten the post id for the post you would like to view/edit, open a new text document in TextMate and type in the text “Post: XX”, where XX is your posting id.
Now choose the menu “Bundles/Blogging/Fetch Post By Id,” and after authenticating, Textmate will open your post in a new window for editing…