I'll just chime in with my own personal prejudice and point out that I
truly loath any style of comments that insists on putting something at
the beginning of each line (*, //, whatever) of comment text. It's
cluttered, makes it next to impossible to edit the text by hand, and
requires extra effort on the part of editor software to handle
correctly to do automatic reformatting.

Syntax-colouring is available, which serves to highlight comments. All
that's needed is a /* before the first line and a */ afterward, and
there you go. Simple and clean.

Assign a keyboard shortcut (mine's command-option-\) to Text > Hard
Wrap, and reformatting is straightforward.

In fact, I even have a script to reformat silly //-delimited comments
and convert them to my desired format. Use at your own risk.

(*
        Update this to match the default wrap width.
*)
set wrapWidth to 80

tell application "BBEdit"
        set selectedText to selection of text window 1 as string
        if selectedText is not "" then
                (*
                        Record the starting and ending line numbers of the 
selection so
that we can restore the selection after the replacement. The
replacement will remove characters from the selection, and the
selected area may encroach upon the next line, which will screw up the
remaining replacement operations.
                *)
                set startLn to startLine of selection of text window 1
                set endLn to endLine of selection of text window 1
                set endLn to endLn - 1

                (*
                        Get rid of the // comment delimiters.
                *)
                replace "^(\\s*)//\\s*(.*$)" using "\\1\\2" searching in 
selection
of text window 1 options {search mode:grep, starting at top:false,
wrap around:false, backwards:false, case sensitive:false, match
words:false, extend selection:false}

                (*
                        Re-select the original lines.
                *)
                select lines startLn thru endLn of text window 1

                (*
                        Trim trailing whitespace.
                *)
                replace "\\s+\\r" using "\\r" searching in selection of text 
window
1 options {search mode:grep, starting at top:true, wrap around:false,
backwards:false, case sensitive:false, match words:false, extend
selection:false}

                (*
                        Re-select the original lines.
                *)
                select lines startLn thru endLn of text window 1

                (*
                        Trim all blank lines before or after the actual comment 
body. We
need to recalculate the index to the last line of the selection as
each blank line is deleted, and then reselect the text, since the
delete command deselects the text
                *)
                repeat while (line startLn of text window 1) as string is ""
                        delete line startLn of text window 1
                        set endLn to endLn - 1
                end repeat

                repeat while (line endLn of text window 1) as string is ""
                        delete line endLn of text window 1
                        set endLn to endLn - 1
                end repeat

                (*
                        It's often the case that the first character in the 
comment is not
capitalized as it should be; make it so. Search only the first line of
the commment, as we don't want to capitalize all of them.
                *)
                select lines startLn thru startLn of text window 1
                replace "^(\\s*)(\\w)" using "\\1\\u\\2" searching in selection 
of
text window 1 options {search mode:grep, starting at top:false, wrap
around:false, backwards:false, case sensitive:false, match
words:false, extend selection:false}

                (*
                        It's also often the case that the last line of the 
comment does not
have a full stop or any other punctuation. If this is the case, add a
full stop.
                *)
                select lines endLn thru endLn of text window 1
                replace "(\\w)$" using "\\1\\." searching in selection of text
window 1 options {search mode:grep, starting at top:false, wrap
around:false, backwards:false, case sensitive:false, match
words:false, extend selection:false}

                (*
                        Reselect the entire set of comment lines and rewrap the 
comment
text. Recalculate the line offsets, as the rewrap may have changed the
number of lines.
                *)
                select lines startLn thru endLn of text window 1

                hard wrap selection of text window 1 limit character width width
wrapWidth indentation same_as_first_line with paragraph fill and
relative
                set startLn to startLine of selection of text window 1
                set endLn to endLine of selection of text window 1
                set endLn to endLn - 1

                (*
                        Finally, put /* */ delimeters before and after the 
entire comment
block, the way it's supposed to be. Note that we do the terminating
delimiter first because inserting it will change the line indices, and
it saves having to recalculate <endLn> again.

                        Also note that we have to insert the proper amount of 
leading
whitespace, so we first do a search on the first line to extract that.
                *)
                find "^(\\s*)" searching in selection of text window 1 options
{search mode:grep, starting at top:false, wrap around:false,
backwards:false, case sensitive:false, match words:false, extend
selection:false}
                set leadSpace to found text of result

                select insertion point after line endLn of text window 1
                set selection to (return & leadSpace & "*/") as string

                select insertion point before line startLn of text window 1
                set selection to (leadSpace & "/*" & return) as string

        end if
end tell


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "[EMAIL PROTECTED]" 
rather than posting to the group.
-~----------~----~----~----~------~----~------~--~---

Reply via email to