I recently read this post [1] where it shows how to define a regular expression (using the PCRE) syntax that looks very much like a proper grammar. A reduced example for the post looks like this:
/
(?(DEFINE)
(?<addr_spec> (?&local_part) @ (?&domain) )
(?<local_part> (?&dot_atom) | (?"ed_string) | (?&obs_local_part) )
(?<domain> (?&dot_atom) | (?&domain_literal) | (?&obs_domain) )
)
^(?&addr_spec)$
/x
The three capture groups “addr_spec”, “local_part” and “domain” would be the grammar rules. It uses the (?&name) syntax to refer to another subgroup. TextMate does not support that syntax but supports the following syntax: \g<name>, which the documentation refers to as Subexp call [2]. This syntax seems to have the same semantics. (DEFINE) is something that seems to be PCRE specific and basically means that the following patterns will not be tried to match. It basically gives a place to define subpatterns. I didn’t find anything corresponding in the TextMate regular expression syntax but defining an optional group can be used as a workaround.
Here’s an example where I tried this technique to match a module declaration in the D language:
(?:
(?<module_declaration>(?<module>module)\s+\g<module_fully_qualified_name>\s*;)
(?<module_fully_qualified_name>\g<module_name>|\g<packages>\.\g<module_name>)
(?<module_name>\g<identifier>)
(?<packages>\g<package_name>|\g<package_name>\.\g<packages>)
(?<package_name>\g<identifier>)
(?<identifier>\w+)
)?
\g<module_declaration>
This is exactly according to the specified grammar [3] and it seems to be working as expected. Not sure if the optional group workaround causes some performance implications.
This technique seems like it could be a viable alternative to supporting variables in the TextMate grammar as has been discussed before. What’s missing from this to make it really useful would be something like (DEFINE) in PCRE and a place in the TextMate grammar to place generic patterns used in multiple rules, like a pattern for identifiers.
[1] https://nikic.github.io/2012/06/15/The-true-power-of-regular-expressions.ht… <https://nikic.github.io/2012/06/15/The-true-power-of-regular-expressions.ht…>
[2] https://macromates.com/manual/en/regular_expressions <https://macromates.com/manual/en/regular_expressions>
[3] https://dlang.org/spec/grammar.html#ModuleDeclaration
--
/Jacob Carlborg
I've used Whitesmith bracing style for *decades*, and had it kinda-sorta working in TM 1.5.x, though not perfectly. Now I've lost those old settings and for the life of me can't figure out how to get it even close in 2.0. There's clearly something fundamental that I'm missing, but I've spent hours on this off and on over the past few months, and I'm guessing that someone who really understands the rules (and regex) better than I, could get me on the right path in short order. I'd definitely appreciate it.
For those (unfortunate souls) who are not familiar with Whitesmith:
http://en.wikipedia.org/wiki/Indent_style#Whitesmiths_style
Also, just as a general suggestion, it seems like it would be really helpful to have just a handful of "packaged" example indentation rules for the small handful of common bracing styles, i.e. Allman, K&R, Whitesmith, maybe Gnu. Of course it wouldn't be perfect for everyone, but it could be really helpful as a starting point. If you know of such a set of examples, please point me to them (yes, I've looked). Thanks!
Dear all,
Since I moved to a new laptop, I noticed a strange behavior with text-selection in TextMate version 2.0-rc.4 (on Mac OS 10.12.6).
Whenever I have a a text-file open in TextMate 2 and click outside of the window (to activate a terminal window, switch to another program, click on a menu item etc.), this ‘click’ will change my selection in the currently opened file.
So, instead of directly deactivating the window, it still takes the action as input for text-selection.
This is of course very annoying, as it constantly changes my selected text / moves the active line etc. without my intention.
It does not always happen, and does not replicate consistently.
Somehow it seems to depend on the time between my last action in the active textmate window and clicking outside of the textmate window.
Is this known behavior and is there a way to fix it?
Thank you!
I use Textmate to prepare material for classes I teach. Most of what I do
is to write explations formatted with Github version Markdown. When OS 10
came out the formatting failed to produce the styled image. Has anyone else
had this problem?
—Lewy
--
Sent from my icebreaker in the Bering Strait
I've been trying the public beta of macOS Mojave and noticed there are two issues with colors in TextMate.
* With a window open, and the File Browser visible, the color of the vertical line on the left side of the gutter view is darker than the one of the right side. On High Sierra these have the same color.
* When viewing a autocomplete popup/window from a bundle, that is a bundle that is using "TextMate::UI.complete". When selecting an item/row the foreground color doesn't change to white. This makes it a bit difficult to read the text. The same thing happens when selecting an item/row in the bundle editor.
These issues both appear in light and dark mode.
Since the application looks different compared to High Sierra, won't that be considered a bug in the operating system?
--
/Jacob Carlborg
HI:
I installed textmate a few evenings ago and it appeared to be working, but then I went to Finder to preview some Matlab files (.m) and when I clicked on them in the Finder Window Preview Panel (not to be confused with Preview the app), it shows the text that is in the file, but NOT like it used to. Instead of the normal OS-X white background and black text, it shows the text in the same colors and format as TextMate! (Black background, white and drab brown and green text for quoted text etc. ).
How did this happen, in that all I did was install TextMate from the download link.
I’m not feeling a warm fuzzy when an application I install that modifies an operating system function and appearance, when I’m not thinking it should.
Thanks!
Herbert U. Fluhler
256-651-5673 [C]
The feature of wrapping comments (even when line wrap is off) doesn’t work well with my work flow.
Suggestion: Add a preference to not do this.
Otherwise a question: Is there a way to turn this off?