-
Adding #pragma mark to EVERY LANGUAGE you work with (in TextMate)
If you’re an old school Mac hacker you know about #pragma mark. I’m told this started with MPW, then was implemented by every IDE on the Mac since that point. (I think I started using it under CodeWarrior, but I think I preferred BBEdit’s implementation at the time). Anyway, moving to other languages I’ve missed this way to organize code. Today I got frustrated and implemented this for every language I ever use, thanks to TextMate. The short version of this tale: I created a language in my source bundle, implemented like so:
{ scopeName = 'source'; fileTypes = ( '.rb' ); foldingStartMarker = '/\*\*|\{\s*$'; foldingStopMarker = '\*\*/|^\s*\}'; patterns = ( { name = 'meta.section'; match = '.*(#\s*(pragma\s+mark)\s+(.*))'; captures = { 1 = { name = 'meta.preprocessor.c'; }; 2 = { name = 'keyword.control.import.pragma.c'; }; 3 = { name = 'meta.toc-list.pragma-mark.c'; }; }; }, ); }The source bundle has the following items on the function popup: entity.name.function, entity.name.type, meta.toc-list. So, because our third regex group is given the scopemeta.toc-list.pragma-mark.c(which is under the meta.toc-list namespace, so we’re good). In every language that I use I need to:- Find the patterns section of that language’s grammer
- Add
{ include = 'source'; },to that section
... patterns = ( { include = 'source'; }, { name = 'meta.class.ruby'; match = '^\s*(class)\s+(([.a-zA-Z0-9_:]+(\s*( Now I can write code like:# #pragma mark "Hello world" def hello_world endor# ====================== #pragma mark "Hello world" ================== def hello_world endAnd have “Hello world” show up on my function popup. I dislike this solution because it requires me modifying every source bundle I work with… but I guess I can live with that. See also: