(Edited Nov 5 so script runs under AutoIt 3.0.73)
Hello, I've written a program (which you assign to a user-defined tool) that comments out a block of code based on the file class. (You no longer have to define a macro for every programming language you use!)
The script needs to be compiled with AutoIt v3--a free download only 580 KB from http://www.hiddensoft.com/autoit3/
Requirements: Section 2 needs to be modified as needed.
I would appreciate any feedback if you decide to try it out!
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoIt 3.0.73 script Designed for TextPad 4.7.1 ;
; to comment out a SELECTED block of text ;
; Philip Gump - philipgump@yahoo.com ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;FIRST, determine the class (file extension) of the active document.
$titles = WinGetText("TextPad - ","")
$tmp = StringLeft($titles, StringInStr($titles, Chr(10))) ; file path
While StringInstr($tmp, ".") <> 0 ; path may contain many dots
$tmp = StringTrimLeft($tmp, StringInstr($tmp, "."))
WEnd
If StringInstr($tmp, "*") <> 0 ; file was modified since last save
$class = StringTrimRight($tmp, 3)
Else
$class = StringTrimRight($tmp, 1) ; need to remove carriage return
EndIf
; We now have the file extension (stored in variable $class)!
;;SECOND, hard code the different comment types as needed
Select
Case $class = "sim"
$comment = "''"
Case $class = "java" OR $class = "c"
$comment = "//"
Case $class = "perl"
$comment = "#"
Case $class = "bat" OR $class = "au3"
$comment = ";"
Case 1=1;Else
$comment = "#NDEF#"
EndSelect
;;THIRD, send keystrokes to TextPad to do a Search and Replace...
AutoItSetOption("SendKeyDelay",0)
Send("^h") ; Launch Replace dialog ("!s#r") is more compatible
WinWaitActive("Replace")
Send("{^}") ; Find What == [beginning of line]
Send("{TAB}")
Send($comment & " ", 1) ; Replace With == [comment char and a space]
Send("{TAB 3}") ; move to the Reg Exp checkbox
; If the Reg Exp checkbox is not checked, then check it!
AutoItSetOption("MouseCoordMode",0) ;needed due to bug in AutoIt?
AutoItSetOption("PixelCoordMode",0) ;set coords relative to active window
If PixelGetColor(25,165) <> 0 ;looks for black checkmark
Send("{SPACE}")
EndIf
Send("!s{TAB}{SPACE}") ;move to Replace All button and click it
WinWaitActive("Replace")
Send("{TAB}{SPACE}") ;close dialog window
; Comment should have been successfully inserted!!! THE END
Code: Select all
;;THIRD, send keystrokes to TextPad to do a Search and Replace...
AutoItSetOption("SendKeyDelay",0)
Send("^h") ;Launch Replace dialog ("!s#r") is more compatible
WinWaitActive("Replace")
Send("^" & $comment & " ", 1) ;Find What == [comment char and a space]
Send("{TAB}")
Send("{DEL}") ;Replace With nothing
Send("{TAB 3}") ;move to the Reg Exp checkbox
; If the Reg Exp checkbox is not checked, then check it!
AutoItSetOption("MouseCoordMode",0) ;needed due to bug in AutoIt?
AutoItSetOption("PixelCoordMode",0) ;set coords relative to active window
If PixelGetColor(25,165) <> 0 ;looks for black checkmark
Send("{SPACE}")
EndIf
Send("!s{TAB}{SPACE}") ;move to Replace All button and click it
WinWaitActive("Replace")
Send("{TAB}{SPACE}") ;close dialog window