[TxMt] Regex for id/class generation

Brett Terpstra brett at circlesixdesign.com
Thu Oct 26 18:57:03 UTC 2006


I'm experimenting with a way to generate id/class names from the  
selected text when I trigger one of my headline commands.  I really  
like the way this turned out and thought I would share it.  Unless  
someone comes back and asks me to make changes, I promise I'll stop  
now.  I prefer camel case in CSS files, but I've been known to be  
inconsistent.  I made commands to switch between the two as well.  I  
apologize to anyone who is currently rolling their eyes ;->.

I'm attaching the command for an h1 tag with a shortcut key of  
command-1 that will take selected text or the whole line and turn it  
into a headline.  It removes leading spaces and tabs and there's a  
camel case version and an underscore version.  On a long headline the  
id name gets ridiculous, so there's a command that will work on both  
to shorten it to the first three words.  And lastly, in case you  
can't make up your mind either, or need to correct your own  
inconsistency like I do, there's a convert command that will switch  
back and forth.  The shorten and convert commands are set to  
command-! (exclamation point).  I also used an h1 tab trigger on the  
h1 commands which you may want to remove if you keep the original h1  
snippets.  If used with the tab trigger, they behave just like the  
old snippets, except they'll mirror and transform the text you type  
between the tags.

Enough rambling.

Brett

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Make h1 from selection or line (CamelCase).tmCommand
Type: application/octet-stream
Size: 980 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20061026/dc5823f4/attachment.tmCommand>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Make h1 from selection or line (Underscore).tmCommand
Type: application/octet-stream
Size: 949 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20061026/dc5823f4/attachment-0001.tmCommand>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Shorten generated classname.tmCommand
Type: application/octet-stream
Size: 1009 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20061026/dc5823f4/attachment-0002.tmCommand>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Convert camelCase:underscore.tmCommand
Type: application/octet-stream
Size: 1134 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20061026/dc5823f4/attachment-0003.tmCommand>


More information about the textmate mailing list