h4ck3r+=boi v 2.0

  1. Search
  2. About
  3. Subscribe
  4. Archive
  5. Random

h4ck3r+=boi v 2.0

Newer
Older
  • 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 scope meta.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
    So, for example, this added to the Ruby language grammar makes my Ruby grammar look like: ... 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 end or # ====================== #pragma mark "Hello world" ================== def hello_world end And 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:
    • Trailing whitespace to EVERY LANGUAGE you work with (in TextMate)

    Posted on April 7, 2010

  • staff

Field Notes Theme. Designed by Manasto Jones. Powered by Tumblr.