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?
How to hide comments
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.
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.
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=“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?
[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? [/quote]
Yeah, I don’t know Python at all…
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.
[quote=“weslly”]actually this is pretty easy, this plugin should solve the problem
cl.ly/312l47310A181h3f1116[/quote]
Nice!
[quote=“facelessuser”]
[quote=“weslly”]actually this is pretty easy, this plugin should solve the problem
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? I’m used to installing things with the package explorer.
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.
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”.
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?
Hi all,
First post, so be gentle if I offend some netiquette you all have going
(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
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.