regex-replace completed

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-08-11 15:38:29 +00:00
parent d056a9b61b
commit 5e4cc8398c
5 changed files with 30 additions and 6 deletions

5
IDEAS
View File

@ -1,3 +1,8 @@
2007/08/11:
Instead of storing method state in the method objects (for mode callback stuff),
we should probably store it in the buffer.
2007/07/19:
Convert all classes to subclass object.

View File

@ -157,7 +157,8 @@ class RegexReverseSearch(RegexSearch):
class Replace(Method):
'''Replace occurances of string X with string Y'''
args = [Argument('before', prompt="Replace: ",
is_literal = True
args = [Argument('before', prompt="Replace String: ",
default=default.last_replace_before, load_default=True),
Argument('after', prompt="Replace With: ",
default=default.last_replace_after, load_default=True)]
@ -167,6 +168,19 @@ class Replace(Method):
a.last_replace_after = self.after = vargs['after']
self.old_window = w
a.open_mini_buffer('I-Replace: ', lambda x: None, self, None, 'replace')
class RegexReplace(Method):
'''Replace occurances of string X with string Y'''
is_literal = False
args = [Argument('before', prompt="Replace Regex: ",
default=default.last_replace_before, load_default=True),
Argument('after', prompt="Replace With: ",
default=default.last_replace_after, load_default=True)]
def _execute(self, w, **vargs):
w.application.last_replace_before = self.before = vargs['before']
w.application.last_replace_after = self.after = vargs['after']
self.old_window = w
f = lambda x: None
w.application.open_mini_buffer('I-RegexReplace: ', f, self, None, 'replace')
# navigating between buffers
class OpenFile(Method):

View File

@ -133,7 +133,8 @@ class PythonTabber(tab2.StackTabber):
elif self.is_rightmost_token(y, i):
pass
else:
self._pop()
#self._pop()
pass
elif fqname == 'keyword':
if token.string in self.endlevel_names:
# we know we'll unindent at least once

View File

@ -53,11 +53,14 @@ class CancelReplace(method.Method):
w.set_error("Replace cancelled")
def _find_next(m, move=False):
s = m.before
w = m.old_window
c = w.logical_cursor()
s = m.before
w = m.old_window
c = w.logical_cursor()
try:
r = re.compile(searchutil.escape_literal(s))
if m.is_literal:
r = re.compile(searchutil.escape_literal(s))
else:
r = re.compile(s)
except:
(m.p1, m.p2) = (None, None)
return False

View File

@ -126,6 +126,7 @@ class Fundamental(Handler):
self.add_bindings('regex-reverse-search', ('M-C-r',))
self.add_bindings('toggle-margins', ('M-m',))
self.add_bindings('replace', ('M-%',))
self.add_bindings('regex-replace', ('M-$',))
self.add_bindings('open-file', ('C-x C-f',))
self.add_bindings('kill-buffer', ('C-x k',))
self.add_bindings('list-buffers', ('C-x C-b',))