--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2010-04-26 00:01:18 -04:00
commit fee24fd1f4
8 changed files with 110 additions and 69 deletions

View File

@ -318,7 +318,8 @@ class Application(object):
lines = list(candidates) lines = list(candidates)
data = '\n'.join(lines) data = '\n'.join(lines)
b = self.data_buffer("*Completions*", data, switch_to=False) b = self.data_buffer("*Completions*", data, switch_to=False)
b._completion = s b._completion = s
b._opened = opened b._opened = opened
b._previous = previous b._previous = previous

View File

@ -490,14 +490,25 @@ class InsertTab(Method):
# if no lvl, insert a literal tab # if no lvl, insert a literal tab
if lvl is None: if lvl is None:
w.insert_string_at_cursor(' ' * w.mode.tabwidth) #w.insert_string_at_cursor(' ' * w.mode.tabwidth)
if w.buffer.usetabs:
# see HACK in buffer
w.insert_string_at_cursor('\t \t')
else:
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
return return
# insert the correct amount of whitespace # insert the correct amount of whitespace
ws = w.buffer.count_leading_whitespace(y) ws = w.buffer.count_leading_whitespace(y)
if lvl != ws: if lvl != ws:
w.delete(Point(0, y), Point(ws, y)) w.delete(Point(0, y), Point(ws, y))
w.insert_string(Point(0, y), ' ' * lvl) if w.buffer.usetabs:
nt = lvl // w.mode.tabwidth
ns = lvl % w.mode.tabwidth
s = ('\t \t' * nt) + (' ' * ns)
else:
s = ' ' * lvl
w.insert_string(Point(0, y), s)
x2 = max(x, lvl) x2 = max(x, lvl)
if w.logical_cursor().x < x2: if w.logical_cursor().x < x2:
w.goto(Point(x2, y)) w.goto(Point(x2, y))

View File

@ -5,6 +5,7 @@ import buffer, default, dirutil, lex, regex, util, window
from point import Point from point import Point
from method import Method, Argument, arg from method import Method, Argument, arg
from method.vc import VcBlame, VcRevView, VcDateView
class CvsCommit(Method): class CvsCommit(Method):
'''diff the current file with the version in CVS''' '''diff the current file with the version in CVS'''
@ -273,48 +274,27 @@ class CvsBlame(Method):
w.set_error("There was an error (%s)" % (status)) w.set_error("There was an error (%s)" % (status))
class CvsBlame2(CvsBlame): class CvsBlame2(CvsBlame):
'''show blame output for the current version in CVS''' '''show blame output for the given version in CVS'''
args = [arg("revision", t=type(""), p="Revision: ", h="revision number")] args = [arg("revision", t=type(""), p="Revision: ", h="revision number")]
line_re = re.compile('^([0-9.]+) +\(*([a-zA-Z0-9_]+) +([-0-9A-Za-z]+)\): (.*)$') line_re = re.compile('^([0-9.]+) +\(*([a-zA-Z0-9_]+) +([-0-9A-Za-z]+)\): (.*)$')
def _get_cmd(self, w, **vargs): def _get_cmd(self, w, **vargs):
path = self._get_path(w, **vargs) path = self._get_path(w, **vargs)
return ("/usr/bin/cvs", 'annotate', '-r', vargs['revision'], path) return ("/usr/bin/cvs", 'annotate', '-r', vargs['revision'], path)
class CvsRevView(Method): class CvsRevView(VcRevView):
'''show blame output for the current version in CVS''' '''show blame output for the current version in CVS'''
args = [arg("revision", t=type(""), p="Revision: ", h="revision number")] args = [arg("revision", t=type(""), p="Revision: ", h="revision number")]
def _get_path(self, w, **vargs): namebase = 'CVS'
cwd = os.getcwd() + os.path.sep _is_method = True
path = w.buffer.path
if path.startswith(cwd):
path = path[len(cwd):]
return path
def _get_cmd(self, w, **vargs): def _get_cmd(self, w, **vargs):
path = self._get_path(w, **vargs) path = self._get_path(w, **vargs)
return ("/usr/bin/cvs", 'up', '-p', '-r', vargs['revision'], path) return ("/usr/bin/cvs", 'up', '-p', '-r', vargs['revision'], path)
def _get_name(self, w, **vargs): class CvsDateView(VcDateView):
return '*CVS:%s-%s' % (w.buffer.name(), vargs['revision'])
def _execute(self, w, **vargs):
if not hasattr(w.buffer, 'path'):
w.set_error("Buffer has no corresponding file")
return
cmd = self._get_cmd(w, **vargs)
name = self._get_name(w, **vargs)
mname = w.mode.name.lower()
status, out, err = util.communicate(cmd)
w.application.data_buffer(name, out, switch_to=True, modename=mname)
class CvsDateView(CvsRevView):
'''show blame output for the current version in CVS''' '''show blame output for the current version in CVS'''
args = [arg("date", t=type(""), p="Date: ", h="date specifier")] args = [arg("date", t=type(""), p="Date: ", h="date specifier")]
namebase = 'CVS'
_is_method = True
def _get_cmd(self, w, **vargs): def _get_cmd(self, w, **vargs):
path = self._get_path(w, **vargs) path = self._get_path(w, **vargs)
return ("/usr/bin/cvs", 'up', '-p', '-D', vargs['date'], path) return ("/usr/bin/cvs", 'up', '-p', '-D', vargs['date'], path)
def _get_name(self, w, **vargs):
return '*CVS:%s-%s' % (w.buffer.name(), vargs['date'])

View File

@ -4,9 +4,9 @@ from subprocess import Popen, PIPE, STDOUT
import buffer, default, dirutil, lex, regex, util, window import buffer, default, dirutil, lex, regex, util, window
from point import Point from point import Point
import buffer.colors import buffer.colors
from method.vc import VcBlame from method.vc import VcBlame, VcRevView
from method import Method, Argument from method import Method, Argument, arg
if os.system('which svn >/dev/null 2>/dev/null') == 0: if os.system('which svn >/dev/null 2>/dev/null') == 0:
has_svn = True has_svn = True
@ -275,3 +275,19 @@ class SvnBlame(VcBlame):
def _open_pipe(self, w, **vargs): def _open_pipe(self, w, **vargs):
cmd = ("svn", 'blame', '-v', w.buffer.path) cmd = ("svn", 'blame', '-v', w.buffer.path)
return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
class SvnBlame2(SvnBlame):
'''show file contents in SVN at revision'''
args = [arg("revision", t=type(""), p="Revision: ", h="revision number")]
def _open_pipe(self, w, **vargs):
cmd = ("svn", 'blame', '-v', '-r', vargs['revision'], w.buffer.path)
return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
class SvnRevView(VcRevView):
'''show file contents in SVN at date'''
args = [arg("revision", t=type(""), p="Revision: ", h="revision number")]
namebase = 'SVN'
_is_method = True
def _get_cmd(self, w, **vargs):
path = self._get_path(w, **vargs)
return ("svn", 'cat', '-r', vargs['revision'], path)

View File

@ -1,4 +1,5 @@
from method import Method import os
from method import Method, arg
import buffer.colors import buffer.colors
import util import util
import lex import lex
@ -68,3 +69,39 @@ class VcBlame(Method):
data = ''.join(self._build_lines(groups, gsizes, w, **vargs)) data = ''.join(self._build_lines(groups, gsizes, w, **vargs))
w.application.color_data_buffer("*Blame*", data, switch_to=True) w.application.color_data_buffer("*Blame*", data, switch_to=True)
class VcRevView(Method):
'''show file contents at revision'''
_is_method = False
namebase = 'VC'
def _get_path(self, w, **vargs):
cwd = os.getcwd() + os.path.sep
path = w.buffer.path
if path.startswith(cwd):
path = path[len(cwd):]
return path
def _get_cmd(self, w, **vargs):
path = self._get_path(w, **vargs)
raise Exception("unimplemented")
def _get_name(self, w, **vargs):
return '*%s:%s-%s' % (self.namebase, w.buffer.name(), vargs['revision'])
def _execute(self, w, **vargs):
if not hasattr(w.buffer, 'path'):
w.set_error("Buffer has no corresponding file")
return
cmd = self._get_cmd(w, **vargs)
name = self._get_name(w, **vargs)
mname = w.mode.name.lower()
status, out, err = util.communicate(cmd)
w.application.data_buffer(name, out, switch_to=True, modename=mname)
class VcDateView(VcRevView):
'''show file contents at date'''
args = [arg("date", t=type(""), p="Date: ", h="date specifier")]
def _get_name(self, w, **vargs):
return '*%s:%s-%s' % (self.namebase, w.buffer.name(), vargs['date'])

View File

@ -1,5 +1,9 @@
import math
import os
import string
import sys
import traceback
from util import defaultdict from util import defaultdict
import math, os, string
import color, method import color, method
from lex import Lexer from lex import Lexer
from point import Point from point import Point
@ -458,8 +462,11 @@ class Fundamental(Handler):
except Exception, e: except Exception, e:
if DEBUG: if DEBUG:
raise raise
else: exc_type, exc_value, exc_traceback = sys.exc_info()
self.window.set_error(str(e)) data = ''.join(traceback.format_tb(exc_traceback))
self.window.application.data_buffer("*Exception*", data,
switch_to=False)
self.window.set_error(str(e))
def region_added(self, p, newlines): def region_added(self, p, newlines):
if self.lexer is not None: if self.lexer is not None:

View File

@ -17,9 +17,10 @@ class ErrorGrammar(Grammar):
PatternRule('continuation', r'\\\n$'), PatternRule('continuation', r'\\\n$'),
] ]
chr1 = '[a-zA-Z_]' chr1 = '[a-zA-Z_]'
chr2 = '[a-zA-Z0-9_]' chr2 = '[a-zA-Z0-9_]'
word = chr1 + chr2 + '*' word = chr1 + chr2 + '*'
spaces = r'[\t ]+'
class MacroGrammar(Grammar): class MacroGrammar(Grammar):
rules = [ rules = [
@ -36,7 +37,7 @@ class MacroGrammar(Grammar):
class CGrammar(Grammar): class CGrammar(Grammar):
rules = [ rules = [
PatternRule('spaces', r' +'), PatternRule('spaces', spaces),
PatternMatchRule('x', r'(\()( *)(' + word + r')(\**)( *)(\))( *)(?=[a-zA-Z0-9_\(])', PatternMatchRule('x', r'(\()( *)(' + word + r')(\**)( *)(\))( *)(?=[a-zA-Z0-9_\(])',
'delimiter', 'spaces', 'c.type', 'c.operator', 'delimiter', 'spaces', 'c.type', 'c.operator',
@ -212,7 +213,7 @@ class C(Fundamental):
closetokens = ('delimiter',) closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'} closetags = {')': '(', ']': '[', '}': '{'}
actions = [CCheckSyntax, CMake] actions = [CCheckSyntax, CMake]
format = "%(flag)s %(bname)s (%(mname)s) %(indent)s %(cursor)s %(perc)s [%(func)s]" format = "%(flag)s %(bname)s (%(mname)s) %(indent)s %(cursor)s %(perc)s [%(func)s] %(vc-info)s"
commentc = '//' commentc = '//'
colors = { colors = {

View File

@ -26,7 +26,7 @@ word1 = wchr1 + wchr2 + '*'
word2 = '(?:' + word1 + "(?:'|::))*" + word1 word2 = '(?:' + word1 + "(?:'|::))*" + word1
pname = '[.a-zA-Z0-9_]+' pname = '[.a-zA-Z0-9_]+'
spaces = PatternRule('spaces', ' +') spaces = PatternRule('spaces', '[\t ]+')
eol = PatternRule('eol', r'\n') eol = PatternRule('eol', r'\n')
length = PatternRule('perl.length', r"\$#" + word2) length = PatternRule('perl.length', r"\$#" + word2)
@ -86,6 +86,9 @@ def _make_string_rules(forbidden):
else: else:
rules.insert(0, PatternRule('data', "\\$(?=" + forbidden + ')')) rules.insert(0, PatternRule('data', "\\$(?=" + forbidden + ')'))
if forbidden != '/':
rules.append(PatternRule('perl.scalar', r'\$/'))
if forbidden == ')': if forbidden == ')':
return rules + [PatternRule('data', r"[^$\%@\(\)]+")] return rules + [PatternRule('data', r"[^$\%@\(\)]+")]
elif forbidden == '}': elif forbidden == '}':
@ -168,7 +171,7 @@ PerlGrammar.rules = [
PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"), PatternRule('perl.function', r"\$\$*" + word2 + "(?=-> *\()"),
# special scalar; doesn't interpolate well # special scalar; doesn't interpolate well
#PatternRule('perl.scalar', r'\$/'), PatternRule('perl.scalar', r'\$/'),
] + scalar_rules + [ ] + scalar_rules + [
# match regexes; paired delimiters # match regexes; paired delimiters
@ -570,11 +573,6 @@ class PerlWrapParagraph(WrapParagraph):
margin = 80 margin = 80
comment_re = re.compile('( *)(#+)( *)(.*)') comment_re = re.compile('( *)(#+)( *)(.*)')
def _is_newline(self, t):
return t.name == 'eol'
def _is_space(self, t):
return t.name == 'spaces'
def _detect_line_type(self, w, y): def _detect_line_type(self, w, y):
h = w.buffer.highlights[w.mode.name] h = w.buffer.highlights[w.mode.name]
ltype = None ltype = None
@ -582,20 +580,13 @@ class PerlWrapParagraph(WrapParagraph):
fqname = t.fqname() fqname = t.fqname()
if fqname == 'spaces' or fqname == 'eol': if fqname == 'spaces' or fqname == 'eol':
pass pass
elif fqname.startswith('comment'): elif fqname == 'perl.comment':
if ltype and ltype != 'comment': return self.LT_COMMENT
ltype = None elif fqname.startswith('perl.pod'):
break return self.LT_POD
ltype = self.LT_COMMENT
elif fqname.startswith('pod'):
if ltype and ltype != 'pod':
ltype = None
break
ltype = self.LT_POD
else: else:
ltype = None return None
break return None
return ltype
def _fix_comments(self, c, w): def _fix_comments(self, c, w):
y1 = c.y y1 = c.y
@ -610,7 +601,7 @@ class PerlWrapParagraph(WrapParagraph):
m = self.comment_re.match(lines[0]) m = self.comment_re.match(lines[0])
assert m assert m
prepend = m.group(1) + m.group(2) prepend = m.group(1) + m.group(2)
rmargin = self.margin - len(prepend) rmargin = self.margin - len(prepend) - 1
dpad = m.group(3) dpad = m.group(3)
segments = [] segments = []
@ -645,9 +636,6 @@ class PerlWrapParagraph(WrapParagraph):
w.buffer.insert_lines(p1, lines2) w.buffer.insert_lines(p1, lines2)
w.set_error("wrapped comment lines %d-%d" % (y1 + 1, y2 + 1)) w.set_error("wrapped comment lines %d-%d" % (y1 + 1, y2 + 1))
def _fix_pod(self, c, w):
w.set_error("pod wrapping not yet supported")
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
c = w.logical_cursor() c = w.logical_cursor()
ltype = self._detect_line_type(w, c.y) ltype = self._detect_line_type(w, c.y)