Sublime Forum

TODO Syntax highlighting

#1

Hi there!

I was wondering how I would go about modifying a sublime-syntax in order to highlight TODO, FIXME, HACK and/or NOTE like the Atom editor.

See the images for details!

Atom:

Sublime Text:

I know there’s the SublimeLinter-Annotations plugin for the linter (they talk about that here), but having them turn up as linter warnings or errors isn’t ideal. Atom’s got it down well.

Any ideas on what I’d have to do?
I would think it would be editing each sublime-syntax file, one by one. Not sure if there’s any way to do it across all languages at once though…

2 Likes

#2

have you considered using https://packagecontrol.io/packages/HighlightWords instead?

because maintaining your own copy of the syntaxes is a lot of unnecessary work


this one seems to have slipped through though: https://github.com/sublimehq/Packages/blob/d15cd7fb209c5ff7a53f47d1fac235f406f903b5/C%23/C%23.sublime-syntax#L79

2 Likes

#3

This is why I’m asking the question - I don’t want to maintain a copy of each syntax! haha

I had considered that package, but that creates markers in the Sublime View - which isn’t ideal (by my standards anyway).
I was looking for something lighter, like inside a syntax or similar, which has the added bonus of colouring the text (whereas markers can only create outlines, underlines, or filled rects, etc).

Good find in that syntax though! haha - if only they had that for each of the syntaxes…

Is there a way to run another syntax over all syntaxes? Maybe I could create a mini-syntax of sorts in order to do it globally.

0 Likes

#4

you could write a plugin to automatically update the syntax definitions, but I’m not sure that would be any less work… there’s no way to do a second pass with another syntax.

having it as part of the syntax definition (and scoping the whole line in a meta scope in addition to the TODO etc.) would allow users to choose to put those comments in the symbol list for easier navigation

0 Likes

#5

https://packagecontrol.io/packages/TodoReview might work instead

1 Like

#6

@rppn all good options, but unfortunately I simply wanted them to be syntax highlighted - nothing more, nor less.

@kingkeith I may go with building a plugin to update them, although I may not as well! Depends on how much this gets to me.

Appreciate the effort from you all though! :+1:

0 Likes

#7

Depending upon the time you have on hand, you could submit PRs to:

The Scope Naming guide however does not explicitely list any scopes for TODOs, though. Until Jon and Will have decided on those, a plugin might be best indeed.

0 Likes

#8

@rppn I would start doing that, so I could contribute, however the only thing that stops me is I think that Jon and @wbond don’t want this in Sublime Text at the moment (judging by @wbond’s comment here).

Otherwise I’m more than keen to submit some PRs.

0 Likes

#9

What I wouldn’t want is a drive-by addition to a single syntax for a user’s preferred style of todo.

I would be open to consider a standardization of “todo” scoping if we can come up with:

  • A list of either common conventions or standards for the default syntaxes
  • A standardized scope name that color schemes can target

The first bullet it going to be the main bit of work. We don’t need to have 100% coverage of default syntaxes, but it would make sense to me that we try to cover most of the popular languages like:

  • JavaScript
  • C/C++
  • PHP
  • Ruby
  • Python
  • C#
  • Java
  • Go
  • Rust
  • Scala
  • TCL
  • D

For each of these, we should probably collect links documenting the common conventions (todo:, @todo, XXX, etc).

Then finally we need to come up with scope name specialization for comments to apply to the marker and the text.

8 Likes

#10

Bad option from my point of view. It might always be a tricky and buggy thing to keep those hacked files sync with their ancestors - this is what I’ve learned from struggling with patched color schemes files of SublimeLinter or patched themes by A File Icon.

This is no solution but a hack, only!

2 Likes

#11

@wbond I believe that most of these “TODO” comments began in different IDEs, but there are some specifications (like PEP which has standardised rules for such comments).

Here’s the result of a small search:

IDEs

Organisations

Misc

From what I can tell though, most IDEs offer a default selection, and then have a configurable pattern in which the user can add / remove their own tags as desired (hence my thoughts for a mini-syntax or overlay-syntax, etc).

I’m not entirely sure if a “standard” exists, but from these I’m sure we can gather together a list of common conventions since it seems to be widely used.


I think this is definitely important, and as @kingkeith said:

As for what it should be, here I really don’t know. Some ideas:

  • As linked before, TODO comments have crept into sublime-syntaxes in the past, and they’ve used comment.line.todo.
  • Atom marks them as type.class.todo.
3 Likes

#12

Did this go anywhere? What’s the best way to highlight TODO et al run ST4?

0 Likes

#13

Have you tried this https://packagecontrol.io/packages/Colored%20Comments ?

2 Likes

#14

Cool! I’ll try that. I was a bit worried with all the previous suggestions as they seem like abandoned plugins.

0 Likes

#15

I just tried installing that add-on again and still seems broken in ST4. How are ppl colouring their TODOs in ST4? It seems trivial in all other editors.

0 Likes

#16

Still works here on ST4

0 Likes

#17

Cool, how did you run Colored Comments: Generate Color Scheme when it doesn’t exist in the Command Palette as per instructions? It’s completely broken for me and the GitHub repo seems neglected.

0 Likes

#18

There is also this plugin (works with ST4): https://packagecontrol.io/packages/SublimeLinter-annotations

1 Like

#19

I would really like to see this implemented as well.

I had a look at HighlightWords, but I couldn’t get it to change the foreground colour, only the background one, which is not what I want.
I had a look at SublimeLinter-annotations, but I don’t want a linter to begin with, and I certainly don’t want these tokens to show up as errors or warnings.
I had a look at ColoredComments, but again it would only change the background colour, even when I explicitly set foreground colours, but it also has the issue of only matching tokens at the beginning of comments, and requiring a whitespace afterwards. Just a “// TODO” line with nothing after it can’t be made to match.

1 Like