Hello,
I recently built my first TextMate bundle (http://sadilek.blogspot.com/2008/04/dna-sequence-analysis-with-textmate.html ) for some simple DNA sequence analysis. It was really easy to accomplish this with TextMate. However, I'm missing one feature: is there any way to programmatically configure syntax highlighting? What I want to achieve is that a user can configure pairs of string and color. All occurences of the string should be highlighted in the given color. I have already built a corresponding dialog (very similar to the preference dialog of the TODO bundle) in which I can enter strings and select a color for each. The "only" thing missing is using this information for highlighting the text.
Best regards Daniel Sadilek
P.S. This sort of function would be interesting for the TODO bundle, as well: for highlighting the TODO markers in the text.
On 7 Apr 2008, at 20:09, Daniel Sadilek wrote:
[...] is there any way to programmatically configure syntax highlighting? What I want to achieve is that a user can configure pairs of string and color. All occurences of the string should be highlighted in the given color.
Are your grammar already assigning different scopes to these different elements?
If so, I assume what you want is to augment the current theme with custom colors that the user sets up in your editor!?!
If you look e.g. in the Diff bundle you will see that among its preferences it has some to define colors for added and removed text.
I think conceptually it is the same you want to do. So while the following does break a few “rules” what I would suggest is to have the color editor placed in a custom bundle which also contains color preferences for your additional elements.
Then when the editor is launched (from within TextMate) it can use the TM_BUNDLE_PATH environment variable to get the path for these preferences, edit them, and issue a ‘tell app "TextMate" to reload bundles’ AppleScript command to have TextMate re-read modifications done.
You may want to “touch” the Preferences folder in the bundle, to ensure TextMate sees the changes (when it (re)loads bundles it favors the cache if a folder date hasn’t been updated since last read).
I found a solution: writing .tmLanguage and .tmTheme files. Unfortunately, TextMate must be restarted for the changes to take effect. You can download the code here: http://sadilek.blogspot.com/2008/04/update-of-sequence-analysis-textmate.htm...
In a later post Ciarán Walsh points out: "If you look at the Diff bundle, it includes Preference items with some foreground/background colour definitions, I would imagine this would be better suited to what you are doing (since reloading bundles should work fine then)."
Best regards Daniel Sadilek
On Mon, Apr 7, 2008 at 8:09 PM, Daniel Sadilek d.sadilek@gmx.net wrote:
Hello,
I recently built my first TextMate bundle (http://sadilek.blogspot.com/2008/04/dna-sequence-analysis-with-textmate.html) for some simple DNA sequence analysis. It was really easy to accomplish this with TextMate. However, I'm missing one feature: is there any way to programmatically configure syntax highlighting? What I want to achieve is that a user can configure pairs of string and color. All occurences of the string should be highlighted in the given color. I have already built a corresponding dialog (very similar to the preference dialog of the TODO bundle) in which I can enter strings and select a color for each. The "only" thing missing is using this information for highlighting the text.
Best regards Daniel Sadilek
P.S. This sort of function would be interesting for the TODO bundle, as well: for highlighting the TODO markers in the text.