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