ActiveState Community

autocomment

Posted by pepebe on 2009-10-15 14:45
OS: All / Any

This is another one of my ideas that somebody else has to do because I'm lacking the time and or skills to do that.

The idea is to automatically add "closing comments" into, for example, html files.

Problem:

Imagine you are writing an html file

Usually this will result in something like this:

html
    head
    /head
    body
        div.page
            div#header
                ...
            /div
            div#nav
                ...
            /div 
            div#main
                ...
            /div
            div#footer
                ...
            /div
        /div
    /body
/html

As you will surely agree, sometimes things can get really messy. Especially when you are working on a very large file including an increasing number of nested div elements, there will come a point, when you will ask your self:

"Where have I closed that d*** container"?

You might say that, among other neat things in komodo, we have code folding, and jump to matching brace, but sometimes this just is not enough (especially when accidentally deleted this particular div...).

A possible solution is always to write a tag with the closing div right behind.

div
   ...
/div

I'm sure most of us do this anyway.

Even better would be to add a comment right behind the closing tag telling you what div that particular tag belongs to.

This, for example, would be much easier to read:

html
    head
    /head
    body
        div.page
            div#header
                ...
            /div
            <!-- end: #header -->          
            div#nav .subnav
                ...
            /div 
            <!-- end: div#nav.subnav -->
            div#main
                ...
            /div
            <!-- end: div#main -->
            div#footer
                ...
            /div
            <!-- end: div#footer -->
        /div
        <!-- end: div.page -->
    /body
/html

Putting the closing tag comment into the next line will be very usefull, when you are using code folding, because komodo will fold the code BEHIND the closing tag and therefore you can never be sure wheter it is there or not

Here is my Question: Would you think it would be a useful thing to have an extension that automatically adds such a comment behind a closing tag?

Regards,

pepebe

toddw | Thu, 2009-10-15 15:26

You might find the "Code->Jump to Matching Brace" quite helpful in Komodo - you position your cursor on the <div> tag (or </div>) - then you can easily jump to the other matching div to see where it is opened/closed.

Cheers,
Todd