Sublime Forum

Bookmarks

#1

I noticed this as a feature of Coda 2:

[quote]Add Custom Bookmarks to the Navigator
It’s fine and dandy to have your named HTML elements show up in the navigator, but what if you could add any line to it, like a bookmark? You totally can. In any syntax mode, just type a comment and prefix its contents with a !, like so:
/* !Page start */
Or, single-line-comment style:
// !Bookmark
It’ll then show up as a bookmark in the Code Navigator[/quote]

http://www.panic.com/blog/2012/07/top-20-secrets-of-coda-2/

This is exactly what I have been asking about in Sublime. Is this possible, to show up in Goto Symbol?

0 Likes

Pragma marks or equivalent?
#2

You can do it with a .tmPreferences file like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comment Markers</string>
    <key>scope</key>
    <string>source comment</string>
    <key>settings</key>
    <dict>
        <key>showInSymbolList</key>
        <integer>1</integer>
        <key>symbolTransformation</key>
        <string>s/^^!]*!(^\n]*).*/$1/g</string>
    </dict>
</dict>
</plist>
0 Likes

#3

Can you just drop this into your prefs? I’m a noob with Sublime, but I’ve been using coda for awhile now… and I love being able to have a bookmarks pane that lets me jump to sections of my code quickly (like the first poster was stating).

[quote=“jps”]You can do it with a .tmPreferences file like this:

[code]

<?xml version="1.0" encoding="UTF-8"?> name Comment Markers scope source comment settings showInSymbolList 1 symbolTransformation s/^^!]*!(^\n]*).*/$1/g [/code][/quote]
0 Likes

#4

[quote=“jps”]You can do it with a .tmPreferences file like this:

[code]

<?xml version="1.0" encoding="UTF-8"?> name Comment Markers scope source comment settings showInSymbolList 1 symbolTransformation s/^^!]*!(^\n]*).*/$1/g [/code][/quote]

Pretty cool, but that just shows ALL my comments, not just the ones I marked with a !

0 Likes

#5

Then just change the regex string to whatever you want.

0 Likes

#6

Hi,

I took a stab at this.

Save the following to Packages/User/Comment Bang.tmPreferences (or whatever):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comment Bang</string>
    <key>scope</key>
    <string>comment</string>
    <key>settings</key>
    <dict>
        <key>showInSymbolList</key>
        <integer>1</integer>
        <key>symbolTransformation</key>
        <string>
        	s/^\S+\s*//g		# strip opening punctuation + spacing
        	s/^^!].*//g		# remove all comments that DON'T begin with a bang
        	s/^!\s*//g			# strip bang and subsequent spaces (if any)
        	s/^(.*?)\n.*/$1/g	# keep only 1st line (in case of multiline comment)
        </string>
    </dict>
    <key>uuid</key>
    <string>7fdae8f0-c6c7-11e1-9b21-0800200c9a66</string>
</dict>
</plist>

I’m pretty to new to writing regular expressions, so this is probably not the most efficient way to do it, but it works so long as you put at least one space or tab before the bang.

So:

!this works

#!this doesn’t

BUGS:

  • Doesn’t work in CSS, although it works for other syntaxes with C-style comments (/* xxx */). Need to investigate.

TODO:

  • Strip common punctuation from end of single comments (such as, -->)
  • Re-write so that you don’t need to space before the bang (while still ignoring HTML punctuation)
0 Likes

#7

[quote=“quodlibet”]Hi,

I took a stab at this.

Save the following to Packages/User/Comment Bang.tmPreferences (or whatever):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comment Bang</string>
    <key>scope</key>
    <string>comment</string>
    <key>settings</key>
    <dict>
        <key>showInSymbolList</key>
        <integer>1</integer>
        <key>symbolTransformation</key>
        <string>
        	s/^\S+\s*//g		# strip opening punctuation + spacing
        	s/^^!].*//g		# remove all comments that DON'T begin with a bang
        	s/^!\s*//g			# strip bang and subsequent spaces (if any)
        	s/^(.*?)\n.*/$1/g	# keep only 1st line (in case of multiline comment)
        </string>
    </dict>
    <key>uuid</key>
    <string>7fdae8f0-c6c7-11e1-9b21-0800200c9a66</string>
</dict>
</plist>

I’m pretty to new to writing regular expressions, so this is probably not the most efficient way to do it, but it works so long as you put at least one space or tab before the bang.

So:

!this works

#!this doesn’t

BUGS:

  • Doesn’t work in CSS, although it works for other syntaxes with C-style comments (/* xxx */). Need to investigate.

TODO:

  • Strip common punctuation from end of single comments (such as, -->)
  • Re-write so that you don’t need to space before the bang (while still ignoring HTML punctuation)[/quote]

Thanks, guys, for this thread. It gave me the clues I needed to get past my mental roadblock.

In the process, I fixed a few of the “bugs” listed above.

At least with my copy of Sublime Text, I have a CSS package that was interfering. It had a file ‘Symbol List Group.tmPreferences’ that I removed to solve the conflict.

To strip the punctuation from the line end, I added:

s/\W*$//g

as the last statement.

0 Likes

#8

Isn’t this a bit irrelevant?

Sublime has already a bookmarks system…

0 Likes

#9

[quote=“pier”]Isn’t this a bit irrelevant?

Sublime has already a bookmarks system…[/quote]

A poor system. They don’t get named and they don’t get saved (unless you add a plug-in).

0 Likes

#10

Really nice, and much more intuitive to jump to “named” bookmarks :smile:

0 Likes

#11

Edit: Jons version works I’ve got something to work from now :smile:

This works well for me.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comment Markers</string>
    <key>scope</key>
    <string>source comment</string>
    <key>settings</key>
    <dict>
        <key>showInSymbolList</key>
        <integer>1</integer>
        <key>symbolTransformation</key>
        <string>
          s/^^!]*!(^\n]*).*/$1/g
          s/\W*$//g
        </string>
    </dict>
</dict>
</plist>
0 Likes

#12

If I want drop down menu then?

0 Likes

#13

CMD+R on OSX. Not sure about Windows.

0 Likes

#14

This is an old thread but I found it useful and wanted to submit my bug fixes and updates.

First I used http://en.wikipedia.org/wiki/Comment_%28computer_programming%29#In_context to learn about various comment formats.

[quote=“quodlibet”]# !this works
#!this doesn’t[/quote]

Changed the “\S+” in the first regex to “\S^!]*” which replaces everything except “!”. The “\S+” matched the exclamation mark and removed it. I included the “\S” at the start because Fortran 90 uses “!” to denote a comment. I also added an HTML-specific string so it isn’t thrown off by the “!” in “<!–”.

Of course this won’t work with languages like Haskell which place no text before the comment. You could probably fix this by including a space before the “!”.

Can’t figure this one out.

I found a package called “Scope Hunter” that tells you the scope of the text under your cursor. In a CSS comment it shows “source.css” and “comment.block.css” just like my PHP example which shows “source.php.embedded.block.html” and “comment.block.php” (both have “source” and “comment” scopes).

HTML didn’t work for me either but Sublime doesn’t include “source” in the scope for HTML files. I assume that Sublime knows what a comment is regardless of its context so I took “source” out and now HTML works.

ScopeHunter: https://packagecontrol.io/packages/ScopeHunter

The second line in the symbolTransformations below was added.

Here is my modified version of the code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Comment Bang</string>
    <key>scope</key>
    <string>comment</string>
    <key>settings</key>
    <dict>
        <key>showInSymbolList</key>
        <integer>1</integer>
        <key>symbolTransformation</key>
        <string>
            s/^(&lt;!--|\S)^!]*\s*//g                # strip opening punctuation + spacing
            s/\s*(\*\/|--&gt;|-\}|#&gt;)$//g          # strip closing text on block comments
            s/^^!].*//g                              # remove all comments that DON'T begin with a bang
            s/^!\s*//g                                # strip the leading exclamation and spacing
            s/^(.*?)\n.*/$1/g                         # keep only 1st line (in case of multiline comment)
        </string>
    </dict>
    <key>uuid</key>
    <string>7fdae8f0-c6c7-11e1-9b21-0800200c9a66</string>
</dict>
</plist>
0 Likes

#15

Hey,

I haven’t used it in a while but I had put together a slightly improved version here:
github.com/alehandrof/BetterGoT … references

The readme explains more things: github.com/alehandrof/BetterGoTo

Hope this helps,
Alex

0 Likes