Montag, 29. Dezember 2008

ISE - Comment out a block of text

Here the final code using #-comments:

function ISE-CommentOut () {
$text = $psise.CurrentOpenedFile.editor.SelectedText
$lines = $text.Split("`n") |% {
$_ -replace "^", "# "
}
if ($lines[$lines.count -1] -eq "# "){
$lines[$lines.count -1] = ""
}
$text = [string]::join("`n", $lines)
$psise.CurrentOpenedFile.editor.InsertText($text)
}

function ISE-CommentIn () {
$text = $psise.CurrentOpenedFile.editor.SelectedText
$lines = $text.Split("`n") |% {
$_ -replace "^ *# *", ""
}
$text = [string]::join("`n", $lines)
$psise.CurrentOpenedFile.editor.InsertText($text)
}

$psIse.CustomMenu.Submenus.Add("Comment Out", {ISE-CommentOut}, "Ctrl+K")
$psIse.CustomMenu.Submenus.Add("Comment In", {ISE-CommentIn}, "Ctrl+SHift+K")

Keine Kommentare:

Kommentar veröffentlichen