based on ideas from Andy Schneider http://get-powershell.com/2008/12/29/ise-comment-out-a-block-of-text/ I played a little to supply custom menues to ISE for commenting out blocks and removing comments:
function ISE-BlockCommentOut () {
$text = $psise.CurrentOpenedFile.editor.SelectedText
$text = $text -replace "#>", "# >"
$text = $text -replace "<#", "< #"
$text = "<#`n$text`n#>"
#$text = $text -replace "(^|\n)", "$1# "
$psise.CurrentOpenedFile.editor.InsertText($text)
}
function ISE-BlockCommentIn () {
$text = $psise.CurrentOpenedFile.editor.SelectedText
$text = $text -replace "<#(`n)?|(`n)?#>", ''
$Text = $text -replace "# >", "#>"
$Text = $text -replace "< #", "<#" $psise.CurrentOpenedFile.editor.InsertText("$text") } $psIse.CustomMenu.Submenus.Add("Comment Block", {ISE-BlockCommentOut}, "Ctrl+K") $psIse.CustomMenu.Submenus.Add("UnComment Block", {ISE-BlockCommentIn}, "Ctrl+SHift+K")
I'm not convinced that it is a good idea for such an extensions to use block comments symbols. Block comments do not nest neatly. They end with the end of the first included block comment and orphant closing block comment bracket become ordinary Comments.
You better never write anything behind a closing block comment in the first place.
Therefor included block comment symbols have to be escaped one way or other. Example
#> -> # > or #`>. Are there ways to establish conventions?
To be honest the other solution, to comment out every single line with its own #-symbol isn't trivial and besides some fiddeling with regular expressions, it involves temporary modification of the selection and I haven't it working yet.
Bernd
Keine Kommentare:
Kommentar veröffentlichen