[wingide-users] Scripting search
Wing IDE Support
support at wingware.com
Fri Oct 26 17:51:15 EDT 2012
On 10/26/12 5:03 PM, Porlo wrote:
> Can anyone give me any tips on using the search API? Using [wingapi.py] in
> conjunction with [editor-extensions.py] I've had some success in writing a
> couple of very basic scripts, and now I'd like to have a go at writing a
> third search script. Unfortunately I can't find any examples - either in the
> docs or on the internet - which subclass CAPISearch. Thus far I think I've
> managed to run a search, but I can't fathom how to process the results.
>
> def remove_debug_statements():
> """"""
> doc = wingapi.gApplication.GetActiveDocument()
> f = doc.GetFilename()
> searcher = wingapi.CAPISearch("^.+# debug-assist$", match_case=True,
> search_style="regex")
> searcher.SearchFile(f)
> # now what?
The search api is asynchronous so what you need to do is connect
functions to signals. I think you want something like the following:
def remove_debug_statements():
""""""
doc = wingapi.gApplication.GetActiveDocument()
f = doc.GetFilename()
searcher = wingapi.CAPISearch("^.+# debug-assist$", match_case=True,
search_style="regex")
def process_matches(filename, match_list):
for lineno, linestart, line_text, line_matches in match_list:
# Do something with the matches for the line
searcher.connect('match', process_matches)
searcher.SearchFile(f)
Cheers,
John
More information about the wingide-users
mailing list