BBEdit Markers

January 15, 2012 by Gabe | [mmd] |

I’m getting more comfortable with BBEdit. It’s a huge application with too many features to wrap my head around in one sitting. I’m taking it slow. I mostly use it for long-form writing, like the recent post “Developers, A Love Story”. Each writing session I try to explore something new and see how it can help me. I’ll periodically post things that I find useful or interesting. Today’s is about Markers.


There are a couple of meanings to Markers in BBEdit. This post is about bookmark markers. BBEdit provides a mechanism for creating custom bookmarks from search expressions. For example, the following grep expression matches all Markdown end references.

The “Mark with” expression simply says, mark with whatever is inside the first (i.e. 01) parentheses. When the Find and Mark is run, the Bookmark list is populated with all of the URL’s in my end references. Note that I have selected the “Clear Existing Markers” option. Unchecking that allows me to append bookmarks to the list.

If I wanted the bookmark list to be populated with just the reference name, I could use a grep command like this:

(^[.?]): (http(s?):\/\/.)

Notice the extra parentheses around the portion that matches the reference tag. Now the “Mark With” expression populates the bookmark list with just the tag names. I think this is pretty neat.

These expressions can be saved as search patterns which means I don’t have to memorize such nonsense. Once an expression is stored in BBEdit, it can be accessed again from the bookmark contextual menu. Even better, the action can be scripted.

Here’s a pattern to use for listing all footnotes in a document:


Footnote List

I think you see where I’m going. Through a combination of pattern matching and markers, I can generate a quick index of anything I want. I can list all images, links or email addresses in a document. Here’s an example where I created an index of all URL’s contained in the document, in the order that they appear.

Scripted Markers

Rather than dealing with all of the clicks to retrieve a stored grep pattern and repopulate the bookmark list, I wrote some scripts to do it for me. These scripts are then accessible from BBEdit’s AppleScript menu. With one menu selection (or hotkey if I set one) I can repopulate the bookmarks with anything I need.

Here’s where AppleScript in BBEdit can be completely infuriating. Here’s an AppleScript that will automatically populate the bookmark with all end Markdown end references. It looks logical and I’m happy that BBEdit provides scripting access to this function.


tell application "BBEdit"

    tell text of front text window

        set results to mark it options {searching for:"^\\[.*?\\]: (http(s?):\\/\\/.*)", using:"\\01", clearing existing:true}

    end tell

end tell

end try

But look at where I started from. This next script fails. There’s no obvious suggestion in the AppleScript dictionary for BBEdit that the proper syntax for the “mark” function is “mark it” and not just “mark”. Sure, after enough DuckDuckGo searches, I found what I needed, but that’s wasted time and I really didn’t learn anything practical.


tell application "BBEdit"

    tell text of front text window

        set results to Mark Options {searching for:"^\\[.*?\\]: (http(s?):\\/\\/.*)", using:"\\01", clearing existing:true}

    end tell

end tell

end try

Now What

Great, now I have a nice way to generate bookmarks for navigating a large document. What’s the point?

BBEdit also provides “Jump Marks”. These are invisible placeholders in a document. You can find them under the “Search” menu. They are also accessible through shift-cmd-j for “Set Jump Mark” and shift-cmd-b for “Jump Back”. If I need to quickly copy a reference link from the end of a document, I hit shift-cmd-j and then select the reference from the bookmark list. That places me at the end of my document with the reference selected. I can then copy or edit. When I’m done I hit shift-cmd-b to go back to my previous position.

I definitely find this tool helpful. It’s easy to remember and use. It’s also very versatile. Once I learned the basic functionality I could customize it to generate a number of useful indexes.

I’d like this feature to get a bit more attention. For example, there’s no way to save a bookmark expression from the bookmark panel. Bookmarks need to be created in the “Setup: Patterns” panel which is accesible from the “Find” panel. That’s awkward. I’d also like the bookmarking patterns to get their own menu and hotkey assignment. A workaround is to create the AppleScripts, but why make a workaround rather than just make it work. Finally, I’d like an option to paste the bookmark selection, rather than jump to the bookmark. I could see that being very powerful.


UPDATE: So, um, here's Dr.Drang doing the same kind of stuff in 2005. Yeah. Wait for my next post where I describe this new tool I've created. I call it a "wheel"**

blog comments powered by Disqus