04 Jan 2006

[Textmate][1] has seen some massive improvements recently. One of the most useful is the [scoping][2] feature that acts a little like CSS selectors, and allows you to restrict certain features to particular languages. So 'commenting out' sections of text gives you `# comment` in Ruby files, `// comment` in C files, and `/* comment */` in CSS files. Likewise, you can have spell checking turned on in text files, but turned off in source files, where it's generally not helpful. That's really just scratching the surface, and the stunning usefulness of scoping isn't fully apparent until you explore it properly.
A little while ago, I wanted to set up a kind of organised scratch file for jotting down odd bits of information, and to act as an _ad hoc_ journal at work. I tend to use either [Notebook][3] (when I'm primarily writing new text) or [DevonThink][4] (when I'm mainly organising existing files and snippets) for particular project resources, but I didn't find that worked well for the kinds of ephemeral-but-sometimes-useful-for-reference data I need to get down on a daily basis.
[1]: http://www.macromates.com [2]: http://macromates.com/textmate/manual/scope_selectors#scope_selectors [3]: http://circusponies.com/ [4]: http://www.devon-technologies.com/products/devonthink/overview.php
I wanted something that was super-quick to enter text into, easy to search, and that would provide an easy route for re-purposing the file, and TextMate fitted the bill beautifully. Since I wanted to write using Markdown markup anyway, I decided to use the Markdown language bundle as a starting point. First, I added a new pattern to match the date stamp you can see in the image above:
{ name = 'markup.datehdr.markdown';
match = '(d){4}-(d){2}-(d){2}@(d){2}:(d){2}';
},
Then I added a foldingStopMarker, so that the block starting with the date stamp and ending with a Markdown horizontal row (`***`) get automatically folded. So if you click one of the little triangles on the left hand side in the image above, the block unfolds as below:

The word in square brackets is a tag to help me find related snippets, and a TextMate snippet (triggered by typing 'dts TAB') inserts the structure of the block with the current date stamp, and places the cursor inside the brackets to enter the tag. Another press of the tab key takes me into the 'body' of the block to start my incoherent ramblings.
As you can see, everything is coloured nicely, which helps to pick out information, and the headings (lines starting with `##`) also appear automatically in the popup list at the bottom of the window. That makes a nice way to quickly browse the file for particular content. For extra speed, I've set up a system wide hotkey (with QuicKeys) to open my big text file when I hit F13.
I've deliberately used a fairly strict structure so that it would be possible in the future to write a little Ruby script to suck the file in, put it into an SQLite database and then provide easy ways to browse tags, find text or search by date.
2
Hmm, you are getting the same basic concept as Tinderbox, from Eastgate systems. Except, yours is a lot cheaper than Tinderbox - but you might want to play with the TB demo anyway, just to see what its like.by Richard @ 05/01/2006 1:01 pm • Permalink
3
Jeroen: Sure, if I can figure out how to sort out the bundle. It's a bit hacky, but it might provide a starting point for someone else. Mr. D.: Sorry... [hands Mr. D. a couple of Ibruprofen...] Richard: Actually, I know Tinderbox fairly well. I used to run this blog with it (a few years ago now), and I also used it for a while for GTD. It's very nice software, but for some reason, it didn't quite gel with my working patterns in the long run. It gets quite expensive upgrading every year too...4
I'm afraid I don't quite follow what you've done, which is vexing as I'd like to emulate it as well. As such, I'd welcome the opportunity to peruse a more detailed discussion of your changes ... [hint]5
MacroMates linked to you -- apparently your technical insight makes the developer weak in the knees... I'd gotten excited about scoping when I first read about it, but hadn't actually gotten around to trying to do anything with it. Now you've inspired me -- I have a project for the weekend.by Dan Ridley @ 07/01/2006 7:01 pm • Permalink
6
Chet: I'll try to make it into a bundle available for download when I've got a moment. It's easier to delve around in the bundle and see how it works than to try to explain it, unfortunately. Dan Ridley: Yes, I saw that, and felt extremely honoured. I'm thinking about getting a T-shirt printed with "I made Allan Odgaard's legs go weak". Almost nobody who saw it would understand it, but it would be cool!7
That shirt would be awesome. The fact that it's obscure would be part of its charm...by Dan Ridley @ 09/01/2006 1:02 am • Permalink
8
If anyone's interested, here's what I did while taking inspiration from this post (thanks bsag, BTW). I modified the Markdown bundle as well. I added a new snippet called _New TimeLog Item_ (triggered with `log `) like this: # `date +%Y-%m-%d@%H:%M` ## ${1:title} $0 *** I put a hash before the date so I get it listed in TextMate's status bar, and it gets an `` hilight. I didn't use the square brackets, for me a title willl suffice. Then I edited the first lines of the language definition like this: fileTypes = ( 'markdown', 'text' ); foldingStartMarker = '^#*s*d[d@:-]+$'; foldingStopMarker = '^***'; I uses the hash+date line to start folding and the `***` line to stop it. Pretty simple and straightforward. I like it.by Marco @ 11/01/2006 9:02 am • Permalink
9
Yikes. Sorry, I mangled the code entry above. I hope the gist comes through!10
bsag and Marco, thanks to both of you for this. I'm coming from long-time use of emacs-planner, and I thought about a couple of changes to make this fit, just a bit more, how my mind works when making notes and stuff. For my use, I changed Marco's first line and made a second snippet that pastes in an item from my clipboard -- this most closely approximates the "remember" feature of emacs-planner. So, my remember snippet looks like this:
# `date +%Y-%m-%d@%H:%M` --- ${1:title}
`pbpaste`
$0
***
</pre>
I had to change the foldingStartMarker to allow the title to come on the date line -- useful for me to have a clue as to the contents of folded items. I activate my remember snippet with rem[tab].
11
Marco and Alan: Nice! (I've fixed the rendereing of your code snippet, Alan). I've toyed with emacs-planner a bit, and thought it was pretty good, but it seemed to me that you would get the most out of it if you lived your entire computer life in emacs. And I didn't. -----
1
I like it, very cool idea. Could you release this (small) bundle on the web?----- ... wanders away from site with aching brain ...by Mr.D. @ 05/01/2006 12:02 pm • Permalink