e / TextMate Command - Open Target Document

Posted by Dan on Feb 17, 2008 @ 9:48 PM

[UPDATED: Saturday, March 08, 2008 at 10:26:56 AM]

I've been playing around with e - TextEditor this weekend to see if maybe it'll replace Textpad for me. I've always liked the speed of Textpad and it does a really good job on large files. I use Eclipse as my main IDE, so when it comes to a Notepad replacement my two main requirements are fast load times and the ability to handle large text files (for reading logs.)

However I keep seeing some of the really cool things that TextMate can do, so I've been keeping an eye out on e - TextEditor. It has a couple of features that would make quick editing of HTML files extremely easy. I really like the ability to selected a bunch of words or tags in a document and easily replace them.

One of the key features of e is it's TextMate bundle support—which really allows you to extend the functionality of the program. While surfing the e forums, I came across a Bundle command which allows you to open the file you have selected in the document (or the file where the caret is positioned.) This script makes it really easy to open files being loading from <script />, <style /> or any other tag you may use for loading files.

The original script, posted by tanguyr, I found either needed you to add e.exe to the Windows PATH environment or you needed to hard code the path to e.exe. I fixed the problem by using one of e's environmental variables. The $TM_SUPPORT_PATH variable points to a sub-directory above where the e.exe file exists, so I just use a relative path to get to the e.exe executable.

To add this command to e, go to the Bundles > Edit Bundles > Show Bundle Editor. I added this script to the Source bundle, as it seemed to make the most sense to me. Select the Source folder and click the + button and select the "New Command" option. I decided to call the command "Open Target Document", if you don't like the name choice something you like better.

Paste the following Bash script into the source area.

UPDATE: As of e v1.0.13 they've fixed a bug with UNC pathing, so I've updated the snippet so that it works with v1.0.13.
#split the current line in two: before and after cursor LN_BEFORE=${TM_CURRENT_LINE:0:$TM_LINE_INDEX} LN_AFTER=${TM_CURRENT_LINE:$TM_LINE_INDEX} #the part of the line before from the last double quotes #to the end plus the part of the line after from the start #up to the first double quotes = the target href TARGETREF=${LN_BEFORE##*\"}${LN_AFTER%%\"*} #for every "../" at the start of the target href, go "up" #one story in TM_DIRECTORY (i.e. remove rightmost dir) while [[ "$TARGETREF" =~ "^\.\./.*$" ]] do TM_DIRECTORY=${TM_DIRECTORY%/*} TARGETREF=${TARGETREF#../} done # if the directory path ends with a slash, then don't append one if [[ $TM_DIRECTORY =~ /$ ]]; then #the absolute path to the target file, in cygwin notation ABSPATH=${TM_DIRECTORY}${TARGETREF} else #the absolute path to the target file, in cygwin notation ABSPATH=${TM_DIRECTORY}/${TARGETREF} fi #test if the file exists if [[ ! -f "$ABSPATH" ]]; then echo file $ABSPATH does not exist >&2 exit 1 fi #change cygwin style path to windows style path, #and call e to open file if [[ "$ABSPATH" =~ ^//(.*)$ ]]; then # get the path to the file to edit WINPATH=${ABSPATH//\//\\} echo "WINPATH=$WINPATH" # invoke "e/Textmate" from the command line and open the file "$TM_SUPPORT_PATH\\..\\e" "$WINPATH" elif [[ "$ABSPATH" =~ /cygdrive/([a-z|A-Z])/(.*)$ ]]; then # get the path to the file to edit WINPATH=${BASH_REMATCH[1]}":\\"${BASH_REMATCH[2]//\//\\} echo "WINPATH=$WINPATH" # invoke "e/Textmate" from the command line and open the file "$TM_SUPPORT_PATH\\..\\e" "$WINPATH" else echo $ABSPATH is not a cygwin path? >&2 exit 1 fi

Here's a screenshot that shows off the settings I'm using:

e._texteditor_open_target_doc

I use the keyboard shortcut of [CTRL]+[SHIFT]+[O] to open files—this seemed like an appropriate keyboard shortcut for opening a file.

One thing I find counter intuitive with e is that there is no "Ok" or "Cancel" buttons. All the changes you make are active immediately. To close the dialog box, just click the "X" close button on the dialog's titlebar.

At this point I think I'll end up keeping e - TextEditor in my "Developers Toolbox." It certainly has it's quirks, but it also has a ton of really useful functionality I haven't found in any other Windows Text Editors. Hopefully others will find this script useful.

Categories: HTML/ColdFusion, Source Code

3 Comments

  • This morning I realized that the Bash script did not work if the file you're working on was on a UNC path. I've modified the code and it now seems to work for files you're editing on a UNC share.
  • Neat! I've tinkered with E a bit as well. There is a nice ColdFusion bundle someone is working on...  I'm so used to Notepad++ though it's tough to use something else :)
  • @Jim:

    There's a CF bundle on the Textmate site that you can download. I haven't really done anything extensive with it yet, but it seems pretty darn complete. Just type in a tag name and press [TAB] to autofill in the text.

    Another neat feature of Textmate is the autocomplete functionality. Just start typing and press [ESC] and a list of words/variables in the document is displayed matching the criteria. This makes it very easy to find variable names.

Comments for this entry have been disabled.