Home Download Buy Blog Forum Support

Global syntax to highlight a specific word

Global syntax to highlight a specific word

Postby mrmccormack on Fri Aug 16, 2013 12:45 pm

I have a need to highlight ALL occurrences of

Code: Select all
???


in every document in Sublime Text.

Any ideas to get me started?

Thanks
Rob


Note:
I read this, but seems to be specific to one language or scope.

http://docs.sublimetext.info/en/latest/ ... definition

Code: Select all
{ "name": "Syntax Name",
  "scopeName": "source.syntax_name",
  "fileTypes": [""],
  "patterns": [
  ],
  "uuid": "ca03e751-04ef-4330-9a6b-9b99aae1c418"
}
mrmccormack
 
Posts: 18
Joined: Wed Jul 17, 2013 4:28 pm

Re: Global syntax to highlight a specific word

Postby skuroda on Sat Aug 17, 2013 6:24 pm

You can't apply more than one syntax file to a given file, so you would have to modify every language file you used. As an alternative, you can try PersistentRegexHighlight
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: Global syntax to highlight a specific word

Postby mrmccormack on Sun Aug 18, 2013 12:37 pm

Thanks! I'll try that plugin.
Rob
mrmccormack
 
Posts: 18
Joined: Wed Jul 17, 2013 4:28 pm

Re: Global syntax to highlight a specific word

Postby mrmccormack on Sun Aug 18, 2013 1:11 pm

This worked perfectly so far.

??? is now highlighted in all documents.

Here is my setting file, with regex pattern.
thanks again
Rob

/Users/YourNameLibrary/Application Support/Sublime Text 2/Packages/PersistentRegexHighlight/PersistentRegexHighlight.sublime-settings
Code: Select all
{
   // Please see the README for more information on settings.

   // Array of objects containing a regular expression
   // and an optional coloring scheme
   "regex":[{
        "pattern": "[?][?][?]",
        "color_scope": "color.scope.name",
        "ignore_case": true
    }]

   ,

   // If highlighting is enabled
   "enabled": true,

   // If highlighting should occur when a view is loaded
   "on_load": true,

   // If highlighting should occur as modifications happen
   "on_modify": true,

   // File pattern to disable on. Should be specified as Unix style patterns
   // Note, this looks at the absolute path to match the pattern. So if trying
   // ignore a single file (e.g. README.md), you will need to specify "**/README.md"
   "disable_pattern": [],

   // Maximum file size to run the the PersistentRegexHighlight on.
   // Any value less than or equal to zero will be treated as a non limiting value.
   "max_file_size": 0
}

mrmccormack
 
Posts: 18
Joined: Wed Jul 17, 2013 4:28 pm

Re: Global syntax to highlight a specific word

Postby mrmccormack on Sun Aug 18, 2013 1:23 pm

I modified it a bit more, now all occurrences of TODO and ??? will be highlighted in ALL documents.

Code: Select all
{
   // Please see the README for more information on settings.

   // Array of objects containing a regular expression
   // and an optional coloring scheme
   "regex":[
   {
        "pattern": "[?][?][?]",
        "color_scope": "color.scope.name",
        "ignore_case": true
    },
    {
        "pattern": "TODO",
        "color_scope": "color.scope.name",
        "ignore_case": false
    }
    ]
   ,
   // If highlighting is enabled
   "enabled": true,

   // If highlighting should occur when a view is loaded
   "on_load": true,

   // If highlighting should occur as modifications happen
   "on_modify": true,

   // File pattern to disable on. Should be specified as Unix style patterns
   // Note, this looks at the absolute path to match the pattern. So if trying
   // ignore a single file (e.g. README.md), you will need to specify "**/README.md"
   "disable_pattern": [],

   // Maximum file size to run the the PersistentRegexHighlight on.
   // Any value less than or equal to zero will be treated as a non limiting value.
   "max_file_size": 0
}

mrmccormack
 
Posts: 18
Joined: Wed Jul 17, 2013 4:28 pm

Re: Global syntax to highlight a specific word

Postby skuroda on Mon Aug 19, 2013 11:22 pm

Glad it worked for you. I'd recommend placing your settings in "Packages/User/PersistentRegexHighlight.sublime-settings". Everything will be merged automatically. This helps keep all your configurations together and from being overridden on accident in the future.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: Global syntax to highlight a specific word

Postby mrmccormack on Thu Aug 22, 2013 3:03 pm

Skuroda:

Hey thanks for followup.

I'd recommend placing your settings in "Packages/User/PersistentRegexHighlight.sublime-settings"


I'm was very aware of the importance of the
Code: Select all
/User/

directory, but I was only using it for ST-like settings files. I will definitely do as you suggested.

Rob
mrmccormack
 
Posts: 18
Joined: Wed Jul 17, 2013 4:28 pm


Return to Plugin Development

Who is online

Users browsing this forum: Google [Bot] and 7 guests