parent
b72aa65aa6
commit
8be0b4f112
134
method.py
134
method.py
|
@ -93,7 +93,7 @@ class Method:
|
|||
try:
|
||||
self._pre_execute(w, **vargs)
|
||||
except MethodError, e:
|
||||
w.application.set_error(str(e))
|
||||
w.set_error(str(e))
|
||||
return
|
||||
for arg in self.args:
|
||||
if arg.name not in vargs:
|
||||
|
@ -224,7 +224,7 @@ class SwitchBuffer(Method):
|
|||
b = w.application.bufferlist.get_buffer_by_name(name)
|
||||
w.application.switch_buffer(b)
|
||||
else:
|
||||
w.application.set_error("buffer %r was not found" % name)
|
||||
w.set_error("buffer %r was not found" % name)
|
||||
class KillBuffer(Method):
|
||||
'''Close the current buffer'''
|
||||
force=False
|
||||
|
@ -281,33 +281,33 @@ class SaveBufferAs(Method):
|
|||
curr_buffer_name = curr_buffer.name()
|
||||
data = curr_buffer.make_string()
|
||||
path = os.path.realpath(os.path.expanduser(vargs['path']))
|
||||
w.application.set_error("got %r (%d)" % (path, len(data)))
|
||||
w.set_error("got %r (%d)" % (path, len(data)))
|
||||
if w.application.has_buffer_name(path):
|
||||
w.application.set_error("buffer for %r is already open" % path)
|
||||
w.set_error("buffer for %r is already open" % path)
|
||||
return
|
||||
w.application.file_buffer(path, data, switch_to=True)
|
||||
if curr_buffer_name != '*Scratch*':
|
||||
w.application.methods['kill-buffer'].execute(w, buffername=curr_buffer_name)
|
||||
else:
|
||||
curr_buffer.set_data('')
|
||||
w.application.set_error('Wrote %r' % path)
|
||||
w.set_error('Wrote %r' % path)
|
||||
class SaveBuffer(Method):
|
||||
'''Save the contents of a buffer'''
|
||||
def _execute(self, w, **vargs):
|
||||
if w.buffer.changed():
|
||||
w.buffer.save()
|
||||
w.application.set_error("Wrote %s" % (w.buffer.path))
|
||||
w.set_error("Wrote %s" % (w.buffer.path))
|
||||
else:
|
||||
w.application.set_error("(No changes need to be saved)")
|
||||
w.set_error("(No changes need to be saved)")
|
||||
class RelexBuffer(Method):
|
||||
'''Relex the buffer; this resets syntax highlighting'''
|
||||
def _execute(self, w, **vargs):
|
||||
h = w.get_highlighter()
|
||||
if h is None:
|
||||
w.application.set_error("No lexer for buffer.")
|
||||
w.set_error("No lexer for buffer.")
|
||||
else:
|
||||
h.highlight(w.buffer.lines)
|
||||
w.application.set_error("Buffer relexed.")
|
||||
w.set_error("Buffer relexed.")
|
||||
class ToggleWindow(Method):
|
||||
'''Move between visible windows'''
|
||||
def _execute(self, w, **vargs):
|
||||
|
@ -377,7 +377,7 @@ class KillRegion(Method):
|
|||
'''Kill the region between the mark and the cursor'''
|
||||
def _execute(self, w, **vargs):
|
||||
w.kill_region()
|
||||
w.application.set_error("Region killed by %s" % self.name)
|
||||
w.set_error("Region killed by %s" % self.name)
|
||||
class Copy(Method):
|
||||
'''Copy the contents of the current line'''
|
||||
def _execute(self, w, **vargs):
|
||||
|
@ -387,14 +387,14 @@ class CopyRegion(Method):
|
|||
def _execute(self, w, **vargs):
|
||||
w.copy_region()
|
||||
w.set_active_point(w.mark)
|
||||
w.application.set_error("Region copied")
|
||||
w.set_error("Region copied")
|
||||
class Yank(Method):
|
||||
'''Paste the top item in the kill ring into the buffer'''
|
||||
def _execute(self, w, **vargs):
|
||||
if w.application.has_kill():
|
||||
w.yank()
|
||||
else:
|
||||
w.application.set_error("Kill ring is empty")
|
||||
w.set_error("Kill ring is empty")
|
||||
class ShowKill(Method):
|
||||
'''Display the top item in the kill ring'''
|
||||
def _execute(self, w, **vargs):
|
||||
|
@ -403,9 +403,9 @@ class ShowKill(Method):
|
|||
x = w.application.x
|
||||
if len(s) > x - 40:
|
||||
s = s[:x - 40] + "..."
|
||||
w.application.set_error("Kill ring contains %r" % s)
|
||||
w.set_error("Kill ring contains %r" % s)
|
||||
else:
|
||||
w.application.set_error("Kill ring is empty")
|
||||
w.set_error("Kill ring is empty")
|
||||
class PopKill(Method):
|
||||
'''Pop the top item in the kill ring off'''
|
||||
def _execute(self, w, **vargs):
|
||||
|
@ -414,9 +414,9 @@ class PopKill(Method):
|
|||
x = w.application.x
|
||||
if len(s) > x - 40:
|
||||
s = s[:x - 40] + "..."
|
||||
w.application.set_error("Removed %r from Kill ring" % s)
|
||||
w.set_error("Removed %r from Kill ring" % s)
|
||||
else:
|
||||
w.application.set_error("Kill ring is empty")
|
||||
w.set_error("Kill ring is empty")
|
||||
|
||||
# delete
|
||||
class DeleteLeft(Method):
|
||||
|
@ -532,7 +532,7 @@ class MetaX(Method):
|
|||
if name in w.application.methods:
|
||||
w.application.methods[name].execute(w)
|
||||
else:
|
||||
w.application.set_error('no method named %r found' % name)
|
||||
w.set_error('no method named %r found' % name)
|
||||
|
||||
class ToggleMargins(Method):
|
||||
'''Show or hide column margins'''
|
||||
|
@ -565,11 +565,11 @@ class GetIndentionLevel(Method):
|
|||
def _execute(self, w, **vargs):
|
||||
cursor = w.logical_cursor()
|
||||
if not w.mode.tabber:
|
||||
w.application.set_error('No tabber available')
|
||||
w.set_error('No tabber available')
|
||||
return
|
||||
else:
|
||||
i = w.mode.tabber.get_level(cursor.y)
|
||||
w.application.set_error('Indention level: %r' % i)
|
||||
w.set_error('Indention level: %r' % i)
|
||||
|
||||
class InsertTab(Method):
|
||||
'''Insert tab into buffer, or tabbify line, depending on mode'''
|
||||
|
@ -816,14 +816,14 @@ class Undo(Method):
|
|||
try:
|
||||
w.undo()
|
||||
except Exception, e:
|
||||
w.application.set_error("%s" % (e))
|
||||
w.set_error("%s" % (e))
|
||||
class Redo(Method):
|
||||
'''Redo last undone action'''
|
||||
def _execute(self, w, **vargs):
|
||||
try:
|
||||
w.redo()
|
||||
except Exception, e:
|
||||
w.application.set_error("%s" % (e))
|
||||
w.set_error("%s" % (e))
|
||||
|
||||
# w navigation methods
|
||||
class StartOfLine(Method):
|
||||
|
@ -978,18 +978,18 @@ class FileDiff(Method):
|
|||
status = pipe.wait() >> 8
|
||||
|
||||
if status == 0:
|
||||
w.application.set_error("No difference found")
|
||||
w.set_error("No difference found")
|
||||
elif status == 1:
|
||||
w.application.data_buffer("*Diff*", outdata, switch_to=True, modename='diff')
|
||||
w.application.set_error("Differences were found")
|
||||
w.set_error("Differences were found")
|
||||
else:
|
||||
w.application.data_buffer("*Diff*", errdata, switch_to=True)
|
||||
w.application.set_error("There was an error: %d exited with status %s" % (pid, status))
|
||||
w.set_error("There was an error: %d exited with status %s" % (pid, status))
|
||||
class SvnDiff(Method):
|
||||
'''diff the current file with the version in SVN'''
|
||||
def _execute(self, w, **vargs):
|
||||
if not hasattr(w.buffer, 'path'):
|
||||
w.application.set_error("Buffer has no corresponding file")
|
||||
w.set_error("Buffer has no corresponding file")
|
||||
return
|
||||
|
||||
cmd = "svn diff %r" % w.buffer.path
|
||||
|
@ -998,17 +998,17 @@ class SvnDiff(Method):
|
|||
if status == 0:
|
||||
if data:
|
||||
w.application.data_buffer("*Diff*", data, switch_to=True, modename='diff')
|
||||
w.application.set_error("Differences were found")
|
||||
w.set_error("Differences were found")
|
||||
else:
|
||||
w.application.set_error("No difference found")
|
||||
w.set_error("No difference found")
|
||||
else:
|
||||
w.application.set_error("There was an error (%s)" % (status))
|
||||
w.set_error("There was an error (%s)" % (status))
|
||||
class SvnBlame(Method):
|
||||
'''show blame output for the current version in SVN'''
|
||||
line_re = re.compile('^ *(\d+) *([a-zA-Z0-9_]+) *([-0-9]+) *([:0-9]+) *(-\d{4}) *\(([^\)]+)\) (.*)$')
|
||||
def _execute(self, w, **vargs):
|
||||
if not hasattr(w.buffer, 'path'):
|
||||
w.application.set_error("Buffer has no corresponding file")
|
||||
w.set_error("Buffer has no corresponding file")
|
||||
return
|
||||
|
||||
cmd = ("/usr/bin/svn", 'blame', '-v', w.buffer.path)
|
||||
|
@ -1027,7 +1027,35 @@ class SvnBlame(Method):
|
|||
if status == 0:
|
||||
w.application.data_buffer("*Blame*", data, switch_to=True, modename='blame')
|
||||
else:
|
||||
w.application.set_error("There was an error (%s)" % (status))
|
||||
w.set_error("There was an error (%s)" % (status))
|
||||
|
||||
class CvsCommit(Method):
|
||||
'''diff the current file with the version in CVS'''
|
||||
args = [Argument("msg", type=type(""), prompt="Commit Message: ")]
|
||||
regex = re.compile('^new revision: ([0-9.]+); previous revision: ([0-9.]+)$')
|
||||
def _execute(self, w, **vargs):
|
||||
if not hasattr(w.buffer, 'path'):
|
||||
w.set_error("Buffer has no corresponding file")
|
||||
return
|
||||
|
||||
cwd = os.getcwd() + os.path.sep
|
||||
path = w.buffer.path
|
||||
if path.startswith(cwd):
|
||||
path = path[len(cwd):]
|
||||
|
||||
cmd = "cvs ci -m %r %r" % (vargs['msg'], path)
|
||||
(status, data) = commands.getstatusoutput(cmd)
|
||||
status = status >> 8
|
||||
|
||||
if status == 0:
|
||||
m = self.regex.match(lines[-1])
|
||||
if m:
|
||||
w.set_error("Committed [%s -> %s]" % (m.group(1), m.group(2)))
|
||||
else:
|
||||
w.set_error("Up-to-date")
|
||||
else:
|
||||
w.set_error("Problems with CVS commit: %d" % status)
|
||||
w.application.data_buffer("*Commit*", data, switch_to=True)
|
||||
|
||||
class CvsStatus(Method):
|
||||
regex1 = re.compile('^File: (.+?) *\tStatus: (.*?)$')
|
||||
|
@ -1038,7 +1066,7 @@ class CvsStatus(Method):
|
|||
regex6 = re.compile('^ Sticky Options:\t\((.*)\)$')
|
||||
def _execute(self, w, **vargs):
|
||||
if not hasattr(w.buffer, 'path'):
|
||||
w.application.set_error("Buffer has no corresponding file")
|
||||
w.set_error("Buffer has no corresponding file")
|
||||
return
|
||||
|
||||
cwd = os.getcwd() + os.path.sep
|
||||
|
@ -1051,13 +1079,13 @@ class CvsStatus(Method):
|
|||
status = status >> 8
|
||||
|
||||
if status != 0:
|
||||
w.application.set_error("Problems with CVS status: %d" % status)
|
||||
w.set_error("Problems with CVS status: %d" % status)
|
||||
return
|
||||
|
||||
lines = data.split('\n')
|
||||
|
||||
if lines[0].startswith('cvs status: nothing known about '):
|
||||
w.application.set_error('File is not under CVS control')
|
||||
w.set_error('File is not under CVS control')
|
||||
return
|
||||
|
||||
m = self.regex1.match(lines[1])
|
||||
|
@ -1086,7 +1114,7 @@ class CvsStatus(Method):
|
|||
assert m, "regex6 %r" % lines[7]
|
||||
soptions = m.group(1)
|
||||
|
||||
w.application.set_error('%s %s %s/%s [%s|%s|%s]' % (ffile, fstatus,
|
||||
w.set_error('%s %s %s/%s [%s|%s|%s]' % (ffile, fstatus,
|
||||
wrev, rrev, stag,
|
||||
sdate, soptions))
|
||||
|
||||
|
@ -1094,7 +1122,7 @@ class CvsDiff(Method):
|
|||
'''diff the current file with the version in CVS'''
|
||||
def _execute(self, w, **vargs):
|
||||
if not hasattr(w.buffer, 'path'):
|
||||
w.application.set_error("Buffer has no corresponding file")
|
||||
w.set_error("Buffer has no corresponding file")
|
||||
return
|
||||
|
||||
cwd = os.getcwd() + os.path.sep
|
||||
|
@ -1107,22 +1135,22 @@ class CvsDiff(Method):
|
|||
status = status >> 8
|
||||
|
||||
if status == 0:
|
||||
w.application.set_error("No difference found")
|
||||
w.set_error("No difference found")
|
||||
else:
|
||||
w.application.data_buffer("*Diff*", data, switch_to=True, modename='diff')
|
||||
w.application.set_error("Differences were found")
|
||||
w.set_error("Differences were found")
|
||||
class CvsDiff2(Method):
|
||||
'''diff the current file with the version in CVS'''
|
||||
rev_regex = re.compile('^[0-9]+\.[0-9]+$')
|
||||
args = [Argument("revision", type=type(""), prompt="Old Revision: ")]
|
||||
def _execute(self, w, **vargs):
|
||||
if not hasattr(w.buffer, 'path'):
|
||||
w.application.set_error("Buffer has no corresponding file")
|
||||
w.set_error("Buffer has no corresponding file")
|
||||
return
|
||||
|
||||
rev = vargs['revision']
|
||||
if not self.rev_regex.match(rev):
|
||||
w.application.set_error("Could not parse revision: %r" % rev)
|
||||
w.set_error("Could not parse revision: %r" % rev)
|
||||
return
|
||||
|
||||
cwd = os.getcwd() + os.path.sep
|
||||
|
@ -1135,10 +1163,10 @@ class CvsDiff2(Method):
|
|||
status = status >> 8
|
||||
|
||||
if status == 0:
|
||||
w.application.set_error("No difference found")
|
||||
w.set_error("No difference found")
|
||||
else:
|
||||
w.application.data_buffer("*Diff*", data, switch_to=True, modename='diff')
|
||||
w.application.set_error("Differences were found")
|
||||
w.set_error("Differences were found")
|
||||
class CvsDiff3(Method):
|
||||
'''diff the current file with the version in CVS'''
|
||||
rev_regex = re.compile('^[0-9]+\.[0-9]+$')
|
||||
|
@ -1146,17 +1174,17 @@ class CvsDiff3(Method):
|
|||
Argument("revision2", type=type(""), prompt="New Revision: ")]
|
||||
def _execute(self, w, **vargs):
|
||||
if not hasattr(w.buffer, 'path'):
|
||||
w.application.set_error("Buffer has no corresponding file")
|
||||
w.set_error("Buffer has no corresponding file")
|
||||
return
|
||||
|
||||
rev1 = vargs['revision1']
|
||||
if not self.rev_regex.match(rev1):
|
||||
w.application.set_error("Could not parse revision1: %r" % rev)
|
||||
w.set_error("Could not parse revision1: %r" % rev)
|
||||
return
|
||||
|
||||
rev2 = vargs['revision2']
|
||||
if not self.rev_regex.match(rev2):
|
||||
w.application.set_error("Could not parse revision2: %r" % rev)
|
||||
w.set_error("Could not parse revision2: %r" % rev)
|
||||
return
|
||||
|
||||
|
||||
|
@ -1171,16 +1199,16 @@ class CvsDiff3(Method):
|
|||
status = status >> 8
|
||||
|
||||
if status == 0:
|
||||
w.application.set_error("No difference found")
|
||||
w.set_error("No difference found")
|
||||
else:
|
||||
w.application.data_buffer("*Diff*", data, switch_to=True, modename='diff')
|
||||
w.application.set_error("Differences were found")
|
||||
w.set_error("Differences were found")
|
||||
class CvsBlame(Method):
|
||||
'''show blame output for the current version in SVN'''
|
||||
line_re = re.compile('^([0-9.]+) +\(*([a-zA-Z0-9_]+) +([-0-9A-Za-z]+)\): (.*)$')
|
||||
def _execute(self, w, **vargs):
|
||||
if not hasattr(w.buffer, 'path'):
|
||||
w.application.set_error("Buffer has no corresponding file")
|
||||
w.set_error("Buffer has no corresponding file")
|
||||
return
|
||||
|
||||
cwd = os.getcwd() + os.path.sep
|
||||
|
@ -1213,7 +1241,7 @@ class CvsBlame(Method):
|
|||
if status == 0:
|
||||
w.application.data_buffer("*Blame*", data, switch_to=True, modename='blame')
|
||||
else:
|
||||
w.application.set_error("There was an error (%s)" % (status))
|
||||
w.set_error("There was an error (%s)" % (status))
|
||||
|
||||
class ShowBindingsBuffer(Method):
|
||||
'''Dump all keybindings for current mode into a new buffer'''
|
||||
|
@ -1325,7 +1353,7 @@ class SetMode(Method):
|
|||
mode_name = vargs['mode']
|
||||
m = w.application.modes[mode_name](w)
|
||||
w.set_mode(m)
|
||||
w.application.set_error('Set mode to %r' % (mode_name))
|
||||
w.set_error('Set mode to %r' % (mode_name))
|
||||
|
||||
class WhichCommand(Method):
|
||||
'''Display which command is run for a given key-sequence'''
|
||||
|
@ -1341,7 +1369,7 @@ class Cancel(Method):
|
|||
'''Cancel command in-progress, and return to the main buffer'''
|
||||
def execute(self, w, **vargs):
|
||||
w.application.close_mini_buffer()
|
||||
w.application.set_error('Cancel')
|
||||
w.set_error('Cancel')
|
||||
|
||||
class SplitWindow(Method):
|
||||
'''Split the main window horizontally into upper and lower windows'''
|
||||
|
@ -1358,7 +1386,7 @@ class UnsplitWindow(Method):
|
|||
'''Maximize the current window to fill the screen'''
|
||||
def execute(self, w, **vargs):
|
||||
w.application.single_slot()
|
||||
w.application.set_error('Window has been unsplit back to one window!')
|
||||
w.set_error('Window has been unsplit back to one window!')
|
||||
|
||||
class SomethingCrazy(Method):
|
||||
def _execute(self, w, **vargs):
|
||||
|
@ -1428,9 +1456,9 @@ class GetToken(Method):
|
|||
def _execute(self, w, **vargs):
|
||||
token = w.get_token()
|
||||
if token is None:
|
||||
w.application.set_error('No Token')
|
||||
w.set_error('No Token')
|
||||
else:
|
||||
w.application.set_error('Token: %r' % token.string)
|
||||
w.set_error('Token: %r' % token.string)
|
||||
|
||||
class RegisterSave(Method):
|
||||
MAX_TXT = 30
|
||||
|
|
Loading…
Reference in New Issue