[wingide-users] Commentblock with ##

James Matthews nytrokiss at gmail.com
Fri Oct 20 11:16:10 MDT 2006


Thanks
On 10/18/06, Wingware Support <support at wingware.com> wrote:
>
> On Wed, 18 Oct 2006, Rob Clewley wrote:
> > I'm new to Wing and I've been benefitting greatly from the powerful
> > debugging environment, among other features. But I would *really* like
> > to be able to comment blocks of code with ## at the beginning of
> > lines, not with a single, indented #.
>
> Since this comes up from time to time, I just wrote up a script
> (pasted in below my signature) that you can drop into your
> 'scripts' directory (preferably the one within your Settings
> Directory, given 5th item in the About box). Then Reload All
> Scripts from the Edit menu and you should be able to bind the
> command 'comment-block-toggle' to some key in preferences.
>
> Stephan Deibel
>
> --
> Wingware
> Wing IDE for Python
> Advancing Software Development
>
> www.wingware.com
>
> ---------------------------
>
> def comment_block_toggle():
>   """Toggle block comment (with ## at start) on the selected lines in
> editor.
>   This is a different style of block commenting than Wing implements by
> default
>   (the default in Wing is intended to work better with some of the other
>   editor functionality)"""
>
>   app = wingapi.gApplication
>   editor = app.GetActiveEditor()
>   eol = editor.GetEol()
>   doc = editor.GetDocument()
>   start, end = editor.GetSelection()
>
>   start_lineno = doc.GetLineNumberFromPosition(start)
>   end_lineno = doc.GetLineNumberFromPosition(end)
>
>   line_start = doc.GetLineStart(start_lineno)
>   line_end = doc.GetLineEnd(end_lineno)
>   line_end = min(line_end, doc.GetLength() - 1)
>
>   txt = doc.GetCharRange(line_start, line_end)
>   txt2 = []
>   if txt.startswith('##'):
>     for line in txt.split(eol):
>       if len(line) >= 2 and line[:2] == '##':
>         line = line[2:]
>       txt2.append(line)
>   else:
>     for line in txt.split(eol):
>       if len(line.strip()) > 0:
>         line = '##' + line
>       txt2.append(line)
>   txt2 = eol.join(txt2) + eol
>
>   doc.BeginUndoAction()
>   try:
>     doc.DeleteChars(line_start, line_end)
>     doc.InsertChars(line_start, txt2)
>   finally:
>     doc.EndUndoAction()
>
>
> _________________________________________________
> Wing IDE users list
> http://wingware.com/lists/wingide
>



-- 
http://www.goldwatches.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/wingide-users/attachments/20061020/e9bc3efa/attachment.html


More information about the wingide-users mailing list