See subject line
Useful to me how:
1) Run some regular expression search to bookmark certain lines
2) Run some regular expression replace only on bookmark lines
I had to write a Visual Basic program to accomplish what I wanted:
If line contains a certain keyword Then
Add an astrisk to the beginning of the line.
EndIf
Ability to limit Find/Replace scope to bookmarked lines
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
Sort of both.... Sorry if I was not clear.
I am suggesting that when you go to Search/Replace, there should be an option under Scope for bookmaked lines.
Search > Replace
Scope:
o Active document
o Selected text
o All documents
o Bookmarked lines
There could be a similar option for Search > Find, but that's less important to me.
Hope that makes more sense.
I am suggesting that when you go to Search/Replace, there should be an option under Scope for bookmaked lines.
Search > Replace
Scope:
o Active document
o Selected text
o All documents
o Bookmarked lines
There could be a similar option for Search > Find, but that's less important to me.
Hope that makes more sense.
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
This missing feature is bothering me, so I wrote a tool for TextPad. (It's crashed TextPad a few times, though--so use at your own risk.)
Maybe someone will find it useful--until the feature I've requested becomes part of TextPad
Script requires AutoIt3.exe from http://www.hiddensoft.com/autoit3/
Maybe someone will find it useful--until the feature I've requested becomes part of TextPad
Script requires AutoIt3.exe from http://www.hiddensoft.com/autoit3/
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; AutoIt 3.0.73 script for TextPad 4.71 ;
; Philip Gump - philipgump@yahoo.com - 6 Nov 2003 ;
; Allow user to perform a Replace operation only on bookmarked lines ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Script requires AutoIt3.exe from http://www.hiddensoft.com/autoit3/
; 0. Assign a user-defined tool with [change paths as appropriate]:
; Command "C:\Program Files\AutoIt3\AutoIt3.exe"
; Parameters "D:\My Scripts\Bookmark Replace.au3" $line
; 1. Open the Replace Dialog window and type in the "find what" and
; "replace with" information.
; 2. Choose "selected text" as the scope, then click "Replace All"
; 3. Click OK, then close the Replace Dialog window.
; 4. Finally, run the user defined tool.
; NOTE: One disadvantage is that your Undo buffer may fill up fast
; since each bookmarked line replace counts as an action...
; Tested under Windows XP Pro sp1 with TextPad 4.71 and
; TextPad keystroke compatibility is set to "Microsoft Applications"
; HOW IT WORKS:
; This script works by jumping to the next bookmark, selecting the line,
; then performs the previous Replace operation on selected text.
; In order for the script to know when to terminate, I position the
; cursor at the top of the document .... and keep jumping to the next
; bookmark until the Status Bar says "Search passed the end of file"
; Enough comments. Here's the code:
If Not WinActive("TextPad - ") Then
Exit ;just in case I accidently launch this script without TextPad active
EndIf
AutoItSetOption("SendKeyDelay",0) ;help speed things up (default is 10 ms)
AutoItSetOption("WinWaitDelay",0) ;default is 250 milliseconds
; Prompt user for the status of Word Wrap. [You may want to remove this!]
$wrapStat = MsgBox(3,"Replace in bookmarked lines...","Is Word Wrap Enabled?")
Select
case $wrapStat = 6 ;YES button clicked
fixWordWrap()
case $wrapStat = 2 ;CANCEL clicked
Exit
EndSelect
Sleep(50)
WinActivate("TextPad - ") ;needed to give right window focus
; Capture the "find what" information the user entered in the Replace dialog.
; (This step is necessary because selecting a line overwrites the info!)
Send("^h") ;launch Replace dialog with Ctrl+H hotkey
WinWaitActive("Replace")
$text = StringTrimLeft(WinGetText("Replace", ""), 12)
$text = StringLeft($text, StringInStr($text, @LF)-1)
$findWhat = $text
Send("!{F4}") ;close the Replace dialog via Alt+F4 hotkey
; Jump to the very first bookmark
Send("^{END}") ;move cursor to end of document via Ctrl+End hotkey
WinMenuSelectItem("TextPad - ", "", "&Search", "N&ext Bookmark")
Send("{HOME}") ;makes the status bar is blank
; this loop checks the text on the Status Bar to know when reach end of file
While Not WinActive("TextPad - ", "Search passed the end of file")
;select current line via Shift+End hotkey
WinActivate("TextPad -")
Send("+{END}")
;launch Replace dialog window (Ctrl+H) and supply info
Send("^h")
WinWaitActive("Replace")
Send($findWhat, 1) ;supply the raw "find what" info
WinActivate("Replace")
Send("!s!a") ;scope is selected text; click Replace All button
Sleep(5) ;just in case Replace pops up with error box...
If WinActive("TextPad", "Cannot find") Then
Send("{SPACE}") ;close error box
WinWaitActive("Replace")
EndIf
Send("!{F4}") ;close the Replace dialog via Alt+F4 hotkey
; jump to next bookmark [you cannot put this command at top of loop]
WinMenuSelectItem("TextPad - ", "", "&Search", "N&ext Bookmark")
Wend ;loop
; Return user to original line he was on by checking the $line param.
If $CmdLine[0] = 1 Then ;user has $line in the user-defined tool param
WinMenuSelectItem("TextPad - ", "", "&Search", "&Go To...")
WinWaitActive("Go To")
Send($CmdLine[1] & "!l{TAB}{TAB}{SPACE}")
EndIf
fixWordWrap()
Exit
Func fixWordWrap() ;toggle word wrap--but only if user had it enabled!
If $wrapStat = 6
WinMenuSelectItem("TextPad - ", "", "&Configure", "&Word Wrap")
EndIf
EndFunc
Although this is nearly 18 years old I also vote for "bookmarks" as a new scope in the search/replace dialog: it would be nice to perform everything only on bookmarked lines.
Enhanced example: I've bookmarked line 1, 3 and 8. When searching with a regex over two lines it should match either lines 1+3 or 3+8.
Simple example: count all matches, restricted to bookmarked lines only.
Enhanced example: I've bookmarked line 1, 3 and 8. When searching with a regex over two lines it should match either lines 1+3 or 3+8.
Simple example: count all matches, restricted to bookmarked lines only.