Custom Context-Sensitive Help for Whatever You Are Editing

(This tip specifically discusses TextPad, but the general techique may apply to other advanced text editors .)
TextPad WindowImagine this: TextPad is running and the current file being edited contains something that you are trying to study. Perhaps, it is a source code example from a programming language you need to learn, or it’s a configuration file that you are trying to wrangle, or some bit of legalese with a lot of Latin gobbledygook. Whatever the case, wouldn’t it be nice if at any time that you encounter an unfamiliar term, you could simply place the cursor on that term, hit a magic keystroke, and a — walla! — everything you need to know about that term pops up in your web browser?

It turns out that in TextPad, this is quite easily accomplished using the external tool mechanism. Let’s continue with the legalese example, and let’s say that Wikipedia is our resource of choice. We see the word “redacted” and we don’t know what it means, so we place the cursor on the word, hit Ctrl+1. Our browser pops open and there’s an article entitled “Redaction”.
Wikipedia Article

How to Set it Up: Here are the step-by-step instructions for setting up an external tool (e.g. Wikipedia) to serve as “context sensitive help”:

  1. Pull down the Configure menu, and select Preferences
  2. Select “Tools” in the left pane of the dialog box.
  3. From the Tools form in the right pane, click Add, and then from the drop down list select “DOS Command…”.
    Add Tool
  4. Enter a command of “Start http://en.wikipedia.org/wiki/$SelWord” and Click OK.
  5. The command you just entered will be added to the list of tools. You can rename it by clicking anywhere on that command in the list (a single left click). Give it a short name like “Wikipedia”. Click on Apply.
  6. With the Preferences dialog box open still open, expand the Tools item in the left pane and select the entry you just added
    .Expand
  7. Change it so that the only two options that are checked are “Run minimized” and “Close DOS window on exit”.
    Tool Options
  8. Click on OK to close the Preferences dialog box.

How It Works: There are 24 special placeholders that can be used when defining a link to an external tool. One of them is $SelWord, which represents the word containing the cursor. As you can see, we use that placeholder in the commands that we entered when setting up the external tool. Per our example, the $SelWord placeholder gets replaced with the word “redacted” (since the cursor is on that word), and thus the actual command that gets passed to the operating system is “Start http://en.wikipedia.org/wiki/redacted”. Now, If you’re not familiar with the Windows Start command, it automatically launches whatever program is appropriate to handle the given argument. In this case it sees that we’re referencing a website, and therefore launches the default browser. For Wikipedia, the convention for looking up an article is to add “/wiki/xxx” to the URL, where xxx is the name of the topic.

Variations: Instead of defining an external tool for Wikipedia lookups (or in addition to it), you could set up a tool link that does a generic Google lookup (”start http://www.google.com/search?as_q=$SelWord”). Also, don’t forget that you can restrict a Google search to a particular domain by adding “&as_sitesearch=domain.com” to the end of the URL.

If your company, or your team, or your project has a private wiki wiki web, you could set up a hotkey to look up topics there.

Tip #1: The hotkeys for the external tools are automatically assigned. The first one is Ctrl+1, the second is Ctrl+2, etc. The order of the tools, and therefore the order of the hotkey assignments, can be adjusted using the preferences dialog.

Tip #2: For some situations, “$SelLine” or “$Sel” might work better than “$SelWord”. As you might imagine, $SelLine selects the entire current line and passes that in, rather than just the current word. $Sel assumes that the appropriate text has already been selected, and just uses that. Note: The TextPad documentation refers to these 24 placeholders as “Tool Parameter Macros,” but that’s a misnomer. The word macro implies something that’s user programmable, but these 24 objects were all preprogrammed, albeit dynamic. They are more like system defined environment variables. In any event, to see a list of all 24, open the TextPad help file and search on “Tool Parameter Macros”.

Tip #4: If you wish to prepare your own help reference for other people to use with TextPad in this manner, you could prepare it as a single HTML file where every lookup term is identified by a named anchor tag.

<A name="LogFileType">
...
<A name="LogFileName">
...
<A name="LogFilePath">
...

In which case, the commands to jump to that term would be

Start file:///C:/tmp/config_reference.html#$SelWord

Post a Comment


Your email is never published nor shared. Required fields are marked *



© 2006-2007 Maxim Software Corp.  All rights reserved.