First, there is an additional, minor change. Earlier, I'd described a
prependEnvironmentAppleScript handler. This proves to be too specific. A slightly simpler
modeEnvironmenthandler seems to be a better fit. It is defined as:
Hopefully, that is straightforward enough.
With the infrastructure set up, the logic for the AppleScript becomes pretty straightforward. We first get some needed information from the SEE document. We use that information to read out the environment using
modeEnvironmentand to build a
pipelinestring calling our
comment.shshell script. Then, we adjust the text selection to select complete lines, transform that text by running it through
pipeline, and set the selection to the transformed text. Additionally, we define
seescriptsettingsto integrate our AppleScript into SEE. The settings are patterned after those of the Objective C mode. Here is the relevant fragment of the AppleScript:
Note that the comment string can be set with the
SEE_LATEX_COMMENTenvironment variable, defaulting to a "%".
The result is fairly nice, but not without shortcomings. There is a brief, but noticable, hesitation between activating the script and seeing the results. It's reasonably clear that building up the environment string is the problem; I'm not sure whether it's worth fixing or not. More significantly, there is a subtle logic problem. Implicitly, I've assumed that the LaTeX document is using Unix-style ("\n") line endings. That's a pretty safe assumption, most of the time, but can be wrong; we'll fix that next time.