Sublime Forum

Pragma marks or equivalent?

#1

It would be great to define a comment to show up when you view the “go to symbol”, so we can add arbitrary markers for ourselves.

Or is this there, and I’m just missing it?

0 Likes

#2

Bump!

Did you ever find out an answer to this? It’s about the one thing I haven’t been able to figure out in this amazing editor (despite persistent searching).

For those unaware, the idea is that you can write these comment lines into your source code:

  • #pragma mark blah-blah”, to add a comment entry to the symbol list;
  • #pragma mark -”, to add a separator to the symbol list.

Handy in larger class files, for keeping things arranged into different categories of methods, etc.

Does anyone know how to achieve this in ST2, either with a native feature or some kind of plugin?

Thanks!

0 Likes

#3

Hey,

@handycam raised a similar issue here --> Bookmarks

I picked up on that and put together a little addition to the Go To Symbol list. You can find it here: github.com/alehandrof/BetterGoTo

It works like this:

# ! This will appear on your goto symbol list

Use whatever comment is appropriate for your language, add a space and a bang and then the label you want to show in the symbol list. You can use it in multiline comments, but only the first line will be preserved.

If you’re looking to replicate the syntax of pragma marks specifically, I might be able to help, although if you can write regular rexpressions, it should be fairly simple to write it yourself by looking at Comment Bang.tmPreferences.

I plan to extend this somewhat (hence the repo), but I work with HTML & CSS mostly, so those are the languages I have in mind. Also bear in mind that I’m not a programmer, so if whatever you’re looking for extends into plugin territory, which requires python, I won’t be able to help. (But may be someone else will :smile: )

Alex

0 Likes

#4

Hi Alex,

Thanks so much! That works perfectly :smile:

Are you aware of any way of applying text-formatting to the rows in the Symbol Popup?

I am familiar with regex, so I’m currently applying a cheesy way of making these new entries stand out in the list, with asterisks.

Final regex transformation rule:

s/^(!\s*)(.*)$/*** $2 ***/g # reformat output

Thanks again!

0 Likes

#5

This is great, thanks. I think this is an essential feature when you’ve got long and complex html, css, sass, or js

0 Likes

#6

I’ve posted a new version. It should play nice with CSS now (which it didn’t before). There are still some issues with the SCSS (not the SASS) package. I’ll look into it.

You can also add rulers now like so:

# !-

This will appear as a row of 66 middots. I got the idea from googling pragma marks, so thanks for that :smile:

Note that you can extend the comment so that it looks like a ruler in your code as well. E.g.,

/* !- * * * * * * * * * * * * * */

I don’t think it’s possible – in the sense that I’ve never seen anyone else do it – but I’ll investigate. In the meantime, your “cheesy” formatting is the only trick available. That said, empty space grabs your attention more readily than a bunch of characters. Maybe try something like:

        	s/^(!\s*)(.*)$/!\t$2/g      # reformat output

I’ve just modified your additional line here. I’m still looking for the best (i.e., the least bad) way to output this stuff to the Go To Symbol List. I’ll then re-write it as appropriate. I have some rough drafts of symbol list preferences to override the defaults for HTML and CSS, because by default these aren’t very useful (IMHO). But that’s a work in progress :wink:

I’d also be inclined to keep the bang, so I can press Ctrl+R, Shift+1 to get a list of all the “comment bangs”.

SCSS is still problematic. Sorry about that!

Alex

0 Likes

#7

Only thing I see in SCSS is that the comment has to be at the start of a line, it can’t be indented. Otherwise it works fine.

EDIT: Sorry, spoke to soon.

This doesn’t work:

// ! MEMBERSHIP AD // top right next to leaderboard on desktop

But this does

[code]// ! MEMBERSHIP AD

// top right next to leaderboard on desktop[/code]

Needs a blank line

0 Likes

#8

Thanks for pointing this out. I hadn’t noticed it.

Heh :smile: I’ve been looking at the CSS, LESS, SASS & SCSS language files and each has its own quirks that have to be accounted for. The SCSS, unlike the other syntaxes I’ve looked at, includes the whitespace before and after the comment (such as indentation and linebreaks) inside the comment scope (which is what I’m running the regex on). This is very annoying :imp: But I’ll keep at it and I hope to have a fix soon! :smile:

Thanks for the interest and please let me know if anything else goes wrong.

Edit: I looked t your post again, and you may be using an older version. The first example (without the blank line) works fine for me. (The first line appears in the GoTo, while the second doesn’t.) Note that the repo now contains some attempts at re-writing the output of CSS & HTML. As it’s still quite messy, you may just want to grab the Comment Bang.tmPreferences, which works independently from the rest.

0 Likes

#9

I’ve pushed a fix for the indent issue. The consecutive comments with bangs issue is more complicated. The more I look at it, the more I think it would be simpler to rewrite the syntaxes :astonished:

0 Likes