Latest in Code

Image credit:

Friday Favorite: Snippets


Welcome to Friday Favorites! Every Friday, one of us will get all sloppy over an app, web service, or Mac feature that makes us grin like an idiot every time we use it. This week, Brett tells us about his favorite new snippet manager.

If you write code, you probably reuse blocks of it. Whether you're working in HTML, CSS, AppleScript, Objective-C ... it's all code, and a really well-written chunk of it deserves to be used again. You can put a few of your most commonly used snippets into TextExpander, sure, but the biggest problem is finding that function you know you wrote last year but haven't used since. This common little conundrum has given rise to some very elegant applications that aim to solve this and other related problems.

There have been a few great options lately for snippet organization. CodeCollector Pro has been my long-running favorite, with Snippet a close second. I like Snippet's sexiness, but miss having a nice, big, multi-pane window to organize with. CodeCollector Pro is a solid workhorse, but actions such as adding new snippets are a little more cumbersome than I'd like. I often just clip things into Evernote when I'm in a hurry ...

Then, along came Snippets (note the 's' that differentiates it from Snippet) to steal my heart. It's got Code Collector's utility, Evernote's searchability, and it's got an extra dash of sexy, ala Snippet. It has the standard sytax-highlighted code viewer, and a sidebar with groups and folders. Snippets are classified by language, which can be set in a dropdown or by just dragging a snippet to a language folder. It functions on a hybrid folder/tag concept, which happens to be the way I do just about everything. Each snippet can have a description, as well as labels (tags) and all full-text indexed for searching. You've also got groups, which are like folders, but a snippet can belong to multiple groups. It has smart folders which, as you know, function like automatic groups with boolean criteria. On top of all that, folders, smart folders and groups can all be gathered hierarchically in nested folders, with parent folders showing all of the contents of their child folders. Whew!

One of the things that hooked me right away was the way that Snippets handles importing of plain text files. You can just drag whole folders of code snippets (manually created or exported from another app) to the library and have them translated into snippets automatically. It does a pretty good job of determining languages and makes it easy to tab through and add descriptions and labels.

I had my whole snippet library up and running in Snippets in about 30 minutes, which is pretty good considering the number of inane lines of code I keep around. And it works both ways: drag a snippet from the library to your desktop and get a new file, named for the title of the snippet and with a language-specific extension. Drag, drop, copy, paste ... it's all quite intuitive.

There's a menubar item which can optionally keep running even when Snippets isn't. It has a search-as-you-type field, and a dropdown folder browser, and both can be triggered with custom hotkeys. Snippets selected in the menubar can be automatically pasted into the current application. It's not a unique feature (actually pretty standard), but it's a great implementation. There's also a url-handler, which responds system-wide to the snippet: protocol. It's ostensibly for providing links on a website that will automatically create library items in the reader's copy of Snippets, but it can be massaged into System Services and other bits of fun. Overall, I've found that Snippets really bridges the gap between Snippet and Code Collector Pro.

Snippets is in beta, and some bugs are to be expected (there's some funkiness with the menubar item after changing its preferences, for example). It's free for the duration of the early development, though, so it's worth a test run. I'm not sure what it will cost when it's fully-fledged, but I have a feeling I'll want to keep using it even after it has a price on it. If you are, or aspire to be, an efficient coder (or just a code packrat), give it a try and see what you think.

From around the web

ear iconeye icontext filevr