Sublime Forum

How to add a global custom symbol marker?

#1

After searching everywhere I cannot find an example on how to add a custom symbol to be included in the CMD+R list.

I want to add my own comment/marker within the code.

Like so: // ! DID STUFF HERE

Then have it show up in the CMD-R symbol list.

I used this a lot when I used Coda, but cannot seem to find a way to make this happen in ST3?

I primarily want this in PHP and HTML files, but also any syntax.

for example in CSS I could do this /* // ! STYLED IT */

Anyone have a solution to this? An example sure would be helpful.

Thanks.

0 Likes

#2

As you’ve already seen, Goto Symbol behavior can be influenced by tmPreferences metadata files.

However, they operate on scopes, which are defined in the syntax definitions. So, by default, the syntax definitions likely won’t assign any special scope to your // ! examples. Therefore, you will need to edit the syntax definitions as well.

Example for CSS:

  1. Install PackageResourceViewer from Package Control if it isn’t installed already
  2. Open the Command Palette
  3. Type PRV: O and select PackageResourceViewer: Open Resource
  4. Select CSS
  5. Select css.sublime-syntax
  6. Find the line where comments are defined https://github.com/sublimehq/Packages/blob/4db940a44b74727ade298927d5ffdb8826fc9769/CSS/CSS.sublime-syntax#L120
  7. Under that line, create a new match regular expression pattern that will match your desired markers i.e. - match: '// !'
  8. under that line, push into a new anonymous context: push:
  9. assign the context a scope - meta_scope: meta.toc-list.yabdab.css
  10. pop when the end of comment or end of line is reached - match: '(?=\*/|$)'
    pop: true
  11. save the file

Because the meta.toc-list scope is already defined for showing in Goto Symbol in the Packages/Default/Symbol List.tmPreferences file, you won’t need to change anything else. Although I found I had to edit Packages/Default/Indexed Symbol List.tmPreferences and it would only show up in Goto Symbol in Project…

Note that you are overriding the default CSS syntax that comes with ST, so you may want to delete and re-apply your changes after every ST update so that you are working with the latest syntax definition.

4 Likes

Python syntax specific symbol for GoTo
#3

Thanks for the sample. I wanted it mainly for the PHP syntax, so here is what I did.

I edited the PHP Source.sublime-syntax

After restarting ST, still no go.

Did I miss a step?

0 Likes

#4

Nevermind. That works. BUT you gotta use > // // ! My Comment

I will tweak to make it work.

Thanks again for the help.

0 Likes