1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# -*- coding: utf-8 -*-
#
# test.py - test module
#
# Copyright (C) 2010 - Jesse van den Kieboom
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
import commander.commands as commands
import gedit
import re
import regex
from xml.sax import saxutils
import finder
__commander_module__ = True
__root__ = ['/', 'find_i', '//', 'r/', 'r//']
class TextFinder(finder.Finder):
def __init__(self, entry, flags):
finder.Finder.__init__(self, entry)
self.flags = flags
def do_find(self, bounds):
buf = self.view.get_buffer()
if self.findstr:
buf.set_search_text(self.findstr, self.flags)
ret = map(lambda x: x.copy(), bounds)
if buf.search_forward(bounds[0], bounds[1], ret[0], ret[1]):
return ret
else:
return False
def __default__(entry, argstr):
"""Find in document: find <text>
Quickly find phrases in the document"""
fd = TextFinder(entry, gedit.SEARCH_CASE_SENSITIVE)
yield fd.find(argstr)
def _find_insensitive(entry, argstr):
"""Find in document (case insensitive): find-i <text>
Quickly find phrases in the document (case insensitive)"""
fd = TextFinder(entry, 0)
yield fd.find(argstr)
def replace(entry, argstr):
"""Find/replace in document: find.replace <text>
Quickly find and replace phrases in the document"""
fd = TextFinder(entry, gedit.SEARCH_CASE_SENSITIVE)
yield fd.replace(argstr, False)
def replace_i(entry, argstr):
"""Find/replace all in document (case insensitive): find.replace-i <text>
Quickly find and replace phrases in the document (case insensitive)"""
fd = TextFinder(entry, 0)
yield fd.replace(argstr, True)
def replace_all(entry, argstr):
"""Find/replace all in document: find.replace-all <text>
Quickly find and replace all phrases in the document"""
fd = TextFinder(entry, gedit.SEARCH_CASE_SENSITIVE)
yield fd.replace(argstr, True)
def replace_all_i(entry, argstr):
"""Find/replace all in document (case insensitive): find.replace-all-i <text>
Quickly find and replace all phrases in the document (case insensitive)"""
fd = TextFinder(entry,0)
yield fd.replace(argstr, True)
locals()['/'] = __default__
locals()['find_i'] = _find_insensitive
locals()['//'] = replace
locals()['r/'] = regex.__default__
locals()['r//'] = regex.replace
# vi:ex:ts=4:et
|