Sublime Forum

How to hide comments

#1

Is there a way to hide comments? I have to heavily comment my code. I’d love to be able to turn comments on and off so that it would show or hide comments. Is this possible?

0 Likes

Fold all functions?
Fold all functions?
RegReplace Plugin
#2

It is possible, but not out of the box. You could write a plugin that finds all comments, and then fold all of those regions with one command, and then with another command unfolds all of those comments.

0 Likes

#3

Hm… I can’t be the only human being to want this functionality. I guess I got to start researching how to write a Sublime Text 2 plugin.

0 Likes

#4

Basically, it is:

view.fold(view.find_by_selector('comment'))

Now if you want a nice result, you must probably tweak a little bit the regions returned by find_by_selector (join adjacent regions, add/remove line ending, …)

0 Likes

#5

[quote=“bizoo”]Basically, it is:

view.fold(view.find_by_selector('comment'))

Now if you want a nice result, you must probably tweak a little bit the regions returned by find_by_selector (join adjacent regions, add/remove line ending, …)[/quote]

Do you happen to have that in a nice package already? :wink:

0 Likes

#6

[quote=“jbrooksuk”]

[quote=“bizoo”]Basically, it is:

view.fold(view.find_by_selector('comment'))

Now if you want a nice result, you must probably tweak a little bit the regions returned by find_by_selector (join adjacent regions, add/remove line ending, …)[/quote]

Do you happen to have that in a nice package already? :wink:[/quote]

Yeah, I don’t know Python at all… :unamused:

0 Likes

#7

If I get some time in the next couple of days (and someone else hasn’t beaten me to the punch), I may take a swing at this; we shall see.

If you end up giving it a try and have issues, just post your questions here, and I am sure you will get help; there are a lot of people here with python/plugin experience, and most are pretty helpful.

0 Likes

#8

actually this is pretty easy, this plugin should solve the problem :smile:

cl.ly/312l47310A181h3f1116

0 Likes

#9

[quote=“weslly”]actually this is pretty easy, this plugin should solve the problem :smile:

cl.ly/312l47310A181h3f1116[/quote]

Nice!

0 Likes

#10

[quote=“facelessuser”]

[quote=“weslly”]actually this is pretty easy, this plugin should solve the problem :smile:

cl.ly/312l47310A181h3f1116[/quote]

Nice![/quote]

Wow! Super nice community! Thank you!

Now… I’m kind of a n00b to this Sublime Text 2 thing. How do I install & use this? :smiley: I’m used to installing things with the package explorer.

0 Likes

#11

Go to Preferences->Browse Pakages and drop the FoldComments folder in there.

He added two commands in the command palette: “fold comments” and “unfold comments”. So just press Ctrl+Shift+p and start typing the command, you should see it pop up; select it and go.

0 Likes

#12

Here is another effort: github.com/mmavko/FoldComments

0 Likes

#13

Hi people,

I’ve extended upon the work of the other plugins in this thread and created my own plugin, with additional features such as concatenating adjacent single/block comments, and making sure the fold-indicator isn’t munged together with adjacent code.

It is available here: https://github.com/oskarols/foldcomments

It’s also added to the Package Manager as “Fold Comments”.

0 Likes

#14

the first one linked is my favorite, however I need it to have an end of line character after the last folded block in succession.
How would I accomplish this? Current code is:

class FoldCommentsCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.fold(self.view.find_by_selector('comment'))


class UnfoldCommentsCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        for region in self.view.find_by_selector('comment'):
            self.view.unfold(region)

But I want to add in an end of line and then remove it after… or is there a way to change the way folding works?

0 Likes

#15

Awesome Job dude, really appreciated.

0 Likes

#16

Hi all,

First post, so be gentle if I offend some netiquette you all have going :smile:
(I did a cursory google search on this, but perhaps I don’t know the right vernacular.)

I have a followup question.

Can someone tell me (or point me to documentation) that explains what happens when one adds a plugin (like the download above) or writes their own, and then a newer ‘official release’ includes the same functionality?

Do you just need to attend to the change-log to see what is new, and is there a recommended method of documenting your ‘add-on’ (contributed and home-grown) plugins (like a personal change-log to your copy)? Is there a coding standard (like doxygen) that can ‘harvest’ this data dynamically?

Regards,
Brad

0 Likes

#17

This is extremely useful! Thank you guys for the hard work!

0 Likes

#18

And if you’d like to replace the distracting yellow icon that replaces folded text, here’s a clean grey icon with transparency.
Save this image:

Rename it fold.png, and move it to Packages > Theme - Default.

Don’t forget to backup the old yellow fold icon by saving the original fold.png under an alternative name.

1 Like

#19

And here’s an example of how it looks:

0 Likes