Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:41:31+00:00 2026-06-16T00:41:31+00:00

I want to write a syntax definition file for Sublime Text 2 for the

  • 0

I want to write a syntax definition file for Sublime Text 2 for the Find Results that respects the file extensions for each place it finds the searched for term. The documentation mentions that “Syntax definitions from separate files can be combined” but does not mention how.

Does anyone have any examples of how that works? An answer to this question: Sublime Text 2: Setting file syntax inside the file itself (as Vim modelines) would work also.

EDIT

Ok, so tip one from a friend: http://manual.macromates.com/en/language_grammars

That uses the ‘include’ tag with a name to reference another language. That would work for me, but unfortunately I’d need to write a plugin to re-compile the file every time Sublime Text opened and re-write it with the various language extensions…Any chance y’all have a better idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:41:32+00:00Added an answer on June 16, 2026 at 12:41 am

    Recently, I obsessively tricked out my ST2 CSS syntax highlighting. My understanding of these *.tmLanguage files is based on trial and error–mostly error. I mention this to note my grasp is spotty, at best.

    I think the file you want to modify is ~/Library/Application Support/Sublime Text 2/Packages/Default/Find Results.hidden-tmLanguage

    Long story short, I think you want to set it up like this gist (which has liberal commenting):

    https://gist.github.com/4333623#file-find-results-hidden-tmlanguage

    A typical Find in files results will look something like this:

    Searching 11 files for "feedback-assistance-form" (regex)
    
    /_projects/___/group_reg.js:
       60       });
       61  
       62:      $asstForm = $help.find('#feedback-assistance-form');
       63  
       64       if (!$asstForm.length) {
       65:          console.log('WARN: Feedback assistance: #feedback-assistance-form not found');
       66           return;
       67       }
    
    /_projects/___/group_register_help_tmpl.html:
        6  <div id="group-reg-help">
        7  
        8:  <form id="feedback-assistance-form" class="js-popover help-content hide" action="{% url info.views.assistance_request %}" method="post">
        9       
       10       <legend>Need Assistance?</legend>
    
    3 matches across 2 files
    

    The Find Results.hidden-tmLanguage parses the results into 3 relevant parts:

    • The line with the filename
    • An excerpted line without a match
    • An excerpted line with a match

    The rules for this are in the <patterns> section:

    <key>patterns</key>
    <array>
        <dict>
            <key>match</key>
            <string>^([^ ].*):$</string>
            <key>captures</key>
            <dict>
                <key>1</key>
                <dict>
                    <key>name</key>
                    <string>entity.name.filename.find-in-files</string>
                </dict>
            </dict>
        </dict>
        <dict>
            <key>match</key>
            <string>^ +([0-9]+) </string>
            <key>captures</key>
            <dict>
                <key>1</key>
                <dict>
                    <key>name</key>
                    <string>constant.numeric.line-number.find-in-files</string>
                </dict>
            </dict>
        </dict>
        <dict>
            <key>match</key>
            <string>^ +([0-9]+):</string>
            <key>captures</key>
            <dict>
                <key>1</key> <!-- capture group 1 -->
                <dict>
                    <key>name</key>  <!-- name it so it can be colored -->
                    <string>constant.numeric.line-number.match.find-in-files</string>
                </dict>
            </dict>
        </dict>
    </array>
    

    These just go through the file, line-by-line, and look for a match. If a match is found, one or more <key>name</key> definitions are applied to the capturing group(s) of the match, if there are any. These name definitions are referenced in the theme definition file (for instance, Monokai) and the color is applied to the characters matched by the named capturing group.

    The patterns above are just matches with capturing groups. I think a limitation of this is the match (or it’s capturing groups) can’t be further processed.

    What’s applied in the gist are patterns of the format:

    <key>patterns</key>
    <array>
        <dict>
            <key>begin</key>
    
    <!-- add the filetype extensions, here -->
    <!-- these are XML formatted files: -->
    
            <string>^([^ ].*\.(?:xml|tmLanguage|hidden-tmLanguage|tmTheme):)$</string>
            <key>beginCaptures</key>
            <dict>
                <key>1</key>
                <dict>
                    <key>name</key>
                    <string>entity.name.filename.find-in-files</string>
                </dict>
            </dict>
            <key>end</key>
            <string>^[^ ]</string>
            <key>patterns</key>
            <array>
                <dict>
                    <key>include</key>
                    <string>#line-numbers</string>
                </dict>
                <dict>
                    <key>include</key>
    
    
    <!-- which syntax should match up to the filetype extensions listed above: -->
    <!-- to find out what the "scopeName" is, refer to the corresponding *.tmLanguage file -->
    <!-- for XML, this is ~/Library/Application Support/Sublime Text 2/Packages/XML/XSL.tmLanguage -->
    
                    <string>text.xml</string>
                </dict>
            </array>
        </dict>
        <!-- ... can have many more -->
    </array>
    

    The main thing with this type of pattern is it has a <begin> and an <end>, then it has it’s own <pattern> section. When the <begin> regex is matched, the contents of <patterns> are applied until (this is where I get really spotty) an unmatched token is encountered, at which point the <end> is tested. I think.

    In any event, the gist defines several of these begin-end-patterns blocks, one for each XML, HTML, JavaScript and CSS file types and syntaxes. The <being> regex matches the line with the filename and a particular file extension. This is used to create the start of the “context” for a given syntax. The context ends when elements in the subsequent <patterns> block stop matching and the <end> regex matches. I think you will basically just want to flesh this out for whichever syntaxes you want to highlight in find results…

    Here is a screenshot of the syntax-highlighted find results I am getting using that gist:

    Blingwear

    I should note, a big issue I encountered is when a block-comment starts in an excerpt but the excerpt doesn’t include the characters that end the block-comment. The block-comment just continues until the terminating token is encountered somewhere else in the find results. This extends into subsequent searches, as well.

    Update:

    I meant to add that you shouldn’t need to recompile anything on startup. Although, it’s worth mentioning that you have to restart sublime for the changes in Find Results.hidden-tmLanguage to take effect. If you make this a plugin of some sort, seems like changes would primarily consist of adding new languages, which could just be an infrequent plugin-update.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a simple text editor for iPhone with syntax highlighting support
I want to write a syntax highlighting extension for Emacs, but I Googling of
I want to write a SQL query like the following. Its syntax is not
I want to write a program in Prolog that confirms if a b-tree of
I am embarking on some learning and I want to write my own syntax
i want this bellow syntax write by using the lambda expression from p in
I want to write a greasemonkey script/chrome user script that takes any images with
I want to write a query return me search results from multiple tables. I'm
I want to write a txt file (just like i'd do in visual studio
I'm trying to write the contents of an array to a text file. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.