From 0bbd3f52e35c49332da11b6538418124173a7d10 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Fri, 17 Jul 2009 15:02:03 -0400 Subject: [PATCH 1/3] improved glob support etc --HG-- branch : pmacs2 --- mode/perl.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mode/perl.py b/mode/perl.py index a22f253..31f6842 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -42,7 +42,7 @@ wchr2 = '[a-zA-Z0-9_]' wchr3 = '[-a-zA-Z0-9_]' hword = wchr3 + '+' word1 = wchr1 + wchr2 + '*' -word2 = '(?:' + word1 + '::)*' + word1 +word2 = '(?:' + word1 + "(?:'|::))*" + word1 pname = '[.a-zA-Z0-9_]+' def _make_string_rules(forbidden): @@ -149,7 +149,7 @@ class PerlGrammar(Grammar): MatchGrammar6, r'\>[a-z]*'), # match regexes - RegionRule('perl.match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)|(?<=if)|(?<=unless)|(?<=while)|(?<=until)|(?<=\|\|)) *(?P/)', MatchGrammar1, '/[a-z]*'), + RegionRule('perl.match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)|(?<=if)|(?<=unless)|(?<=while)|(?<=until)|(?<=\|\|)|(?<=&&)|(?<==)) *(?P/)', MatchGrammar1, '/[a-z]*'), RegionRule('perl.match', 'm *(?P/)', MatchGrammar1, '/[a-z]*'), RegionRule('perl.match', 'm *(?P[^ #a-zA-Z0-9_])', StringGrammar, '%(delim)s[a-z]*'), @@ -222,7 +222,7 @@ class PerlGrammar(Grammar): PatternRule('perl.function', word2 + r"(?= *\()"), PatternRule('perl.class', word2 + "(?=->)"), - PatternRule('perl.glob', r'(?:(?<=[^a-zA-Z0-9_])|(?<=^)) *\*[^ ]+'), + PatternRule('perl.glob', r'(?:(?<=[^a-zA-Z0-9_])|(?<=^)) *\*' + word2), # some basic stuff PatternRule('delimiter', r"::|->|=>|(? Date: Fri, 17 Jul 2009 16:56:32 -0400 Subject: [PATCH 2/3] gory perl fixes inspired by gory perl modules --HG-- branch : pmacs2 --- mode/perl.py | 58 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/mode/perl.py b/mode/perl.py index 31f6842..5610a3d 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -58,6 +58,14 @@ def _make_string_rules(forbidden): PatternRule('cast', r"[\$\@\%\&]{.+?}"), PatternRule('array', r"@\$*" + word2), ] + if forbidden == ')': + rules.append(PatternRule('data', r"\([^\(\)]*\)")) + elif forbidden == '}': + rules.append(PatternRule('data', r"{[^{}]*}")) + elif forbidden == ']': + rules.append(PatternRule('data', r"\[[^\[\]]*\]")) + elif forbidden == '>': + rules.append(PatternRule('data', r"<[^<>]*>")) return rules class QuotedWords(Grammar): rules = [ @@ -72,9 +80,14 @@ class NoAngle(Grammar): rules = [PatternRule('data', '[^>]+')] class NoHash(Grammar): rules = [PatternRule('data', '[^#]+')] class DataGrammar(Grammar): rules = [PatternRule('data', '.+')] -class StrictStringGrammar(Grammar): rules = [PatternRule('escaped', r"\\'")] -class StringGrammar(Grammar): rules = _make_string_rules('"') -class EvalGrammar(Grammar): rules = _make_string_rules('`') +class StrictStringGrammar(Grammar): rules = [ + PatternRule('escaped', r"\\[\\']"), + PatternRule('data', r"[^\\']+"), +] +class StringGrammar(Grammar): + rules = _make_string_rules('"') + [PatternRule('data', '[^\\"]+')] +class EvalGrammar(Grammar): + rules = _make_string_rules('`') + [PatternRule('data', '[^\\`]+')] class TranslateGrammar1(Grammar): rules = [PatternRule('data', r"(?:\\.|[^\\/])")] @@ -83,6 +96,7 @@ class TranslateGrammar2(Grammar): class TranslateGrammarX(Grammar): rules = [PatternRule('data', r"(?:\\.|[^\\%(delim)s])")] +class MatchGrammar0(Grammar): rules = _make_string_rules(None) class MatchGrammar1(Grammar): rules = _make_string_rules('/') class MatchGrammar2(Grammar): rules = _make_string_rules('#') class MatchGrammar3(Grammar): rules = _make_string_rules(')') @@ -122,13 +136,26 @@ class PerlGrammar(Grammar): RegionRule('perl.string', '"', StringGrammar, '"'), RegionRule('perl.string', "'", StrictStringGrammar, "'"), RegionRule('perl.evalstring', "`", EvalGrammar, "`"), - PatternRule('perl.number', r'0?\.[0-9]+|[0-9]+(?:\.[0-9]+)?'), - PatternRule('perl.keyword', "(?)(?:STDIN|STDERR|STDOUT|continue|do|else|elsif|eval|foreach|for|if|last|my|next|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])"), + PatternRule('perl.keyword', "(?)(?:STDIN|STDERR|STDOUT|continue|do|else|elsif|eval|foreach|for|if|last|my|next|no|our|package|require|return|sub|undef|unless|until|use|while)(?![a-zA-Z0-9_])"), PatternRule('perl.hash_key', '(?<={)' + wchr2 + '+(?=})'), PatternRule('perl.method', '(?<=->)' + word1), PatternRule('perl.hash_key', wchr2 + '+(?= *=>)'), PatternRule('perl.length', r"\$#" + word2), PatternRule('perl.cast', r'[\$\@\%\&\*](?= *{)'), + + PatternRule('perl.number', r'0[xX][0-9A-Fa-f]+'), + PatternRule('perl.number', r'0?\.[0-9]+|[0-9]+(?:\.[0-9]+)?'), + + # built-in scalars + PatternRule('perl.scalar', r'\$[_ab&`\'\+\*\./|,\\";#\%=\-~\^:\?!@\$<>()\[\]](?!' + wchr2 + ')'), + PatternRule('perl.scalar', r'\$\d+(?!' + wchr2 +')'), + PatternRule('perl.scalar', r'\$\^(?:' + word1 + '|' + wchr1 + ')'), + PatternRule('perl.scalar', r'\$\^O'), + PatternRule('perl.scalar', r'\${\^' + word1 + '}'), + + PatternRule('perl.array', r'\@[\+\-]'), + PatternRule('perl.hash', r'\%(?:[!]|^H)'), + PatternRule('perl.scalar', r"\$[\[\]<>ab/'\"_@\?#\$!%^|&*()](?!" + wchr2 + ")"), PatternRule('perl.array', "@_"), @@ -152,18 +179,10 @@ class PerlGrammar(Grammar): RegionRule('perl.match', r'(?:(?<==~)|(?<=!~)|(?<=\()|(?<=split)|(?<=if)|(?<=unless)|(?<=while)|(?<=until)|(?<=\|\|)|(?<=&&)|(?<==)) *(?P/)', MatchGrammar1, '/[a-z]*'), RegionRule('perl.match', 'm *(?P/)', MatchGrammar1, '/[a-z]*'), RegionRule('perl.match', 'm *(?P[^ #a-zA-Z0-9_])', - StringGrammar, '%(delim)s[a-z]*'), + MatchGrammar0, '%(delim)s[a-z]*'), RegionRule('perl.match', 'm(?P#)', MatchGrammar2, '#[a-z]*'), # match regexes; paired delimiters - #RegionRule('perl.replace', r's *(?P\()', MatchGrammar3, - # r'\) *\(', MatchGrammar3, r'\)[a-z]*'), - #RegionRule('perl.replace', r's *(?P\[)', MatchGrammar4, - # r'\] *\[', MatchGrammar4, r'\][a-z]*'), - #RegionRule('perl.replace', r's *(?P\{)', MatchGrammar5, - # r'\} *\{', MatchGrammar5, r'\}[a-z]*'), - #RegionRule('perl.replace', r's *(?P\<)', MatchGrammar6, - # r'\> *\<', MatchGrammar6, r'\>[a-z]*'), RegionRule('perl.replace', r's *(?P\()', MatchGrammar3, r'\)', WhitespaceGrammar, '\(', MatchGrammar3, r'\)[a-z]*'), RegionRule('perl.replace', r's *(?P\[)', MatchGrammar4, @@ -177,8 +196,8 @@ class PerlGrammar(Grammar): RegionRule('perl.replace', 's *(?P/)', MatchGrammar1, '/', MatchGrammar1, '/[a-z]*'), RegionRule('perl.replace', 's *(?P[^ a-zA-Z0-9_])', - StringGrammar, '%(delim)s', - StringGrammar, '%(delim)s[a-z]*'), + MatchGrammar0, '%(delim)s', + MatchGrammar0, '%(delim)s[a-z]*'), RegionRule('perl.replace', 's(?P#)', MatchGrammar2, '#', MatchGrammar2, '#[a-z]*'), @@ -195,6 +214,7 @@ class PerlGrammar(Grammar): PatternRule('perl.package', "(?<=package )" + word2), PatternRule('perl.sub', "(?<=sub )" + word2), PatternRule('perl.use', "(?<=use )" + word2), + PatternRule('perl.use', "(?<=no )" + word2), PatternRule('perl.require', "(?<=require )" + word2), PatternRule('perl.label', word1 + ':(?!:)'), PatternRule('perl.function', r"&\$*" + word2), @@ -207,8 +227,8 @@ class PerlGrammar(Grammar): RegionRule('perl.quoted', r'q[rqx] *(?P\[)', QuotedGrammar4, r'\]'), RegionRule('perl.quoted', "q[rqx] *(?P')", Grammar, "'"), RegionRule('perl.quoted', 'q[rqx] *(?P[^ a-zA-Z0-9#])', - StringGrammar, '%(delim)s'), - RegionRule('perl.quoted', 'q[rqx](?P#)', StringGrammar, '#'), + MatchGrammar0, '%(delim)s'), + RegionRule('perl.quoted', 'q[rqx](?P#)', MatchGrammar0, '#'), # quote operator: q() and qw() do not interpolate RegionRule('perl.quoted', r'qw? *\(', QuotedWords, r'\)'), @@ -781,6 +801,7 @@ class Perl(Fundamental): # match regex 'match.start': ('cyan', 'default', 'bold'), 'match.end': ('cyan', 'default', 'bold'), + 'match.data': ('cyan', 'default', 'bold'), 'match.null': ('cyan', 'default', 'bold'), # replace regex @@ -788,6 +809,7 @@ class Perl(Fundamental): 'replace.middle0': ('cyan', 'default', 'bold'), 'replace.middle1': ('cyan', 'default', 'bold'), 'replace.end': ('cyan', 'default', 'bold'), + 'replace.data': ('cyan', 'default', 'bold'), 'replace.null': ('cyan', 'default', 'bold'), 'replace.escaped': ('magenta', 'default', 'bold'), 'replace.deref': ('yellow', 'default', 'bold'), From e8d4bcbc7e49e6ed1c7ee498b5bc8c53631badc3 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Mon, 20 Jul 2009 19:08:27 -0400 Subject: [PATCH 3/3] cvs-blame2 added --HG-- branch : pmacs2 --- method/cvs.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/method/cvs.py b/method/cvs.py index 1009708..57060b3 100644 --- a/method/cvs.py +++ b/method/cvs.py @@ -209,19 +209,25 @@ class CvsDiff3(Method): w.set_error("Differences were found") class CvsBlame(Method): - '''show blame output for the current version in SVN''' + '''show blame output for the current version in CVS''' line_re = re.compile('^([0-9.]+) +\(*([a-zA-Z0-9_]+) +([-0-9A-Za-z]+)\): (.*)$') + 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) + return ("/usr/bin/cvs", 'annotate', path) + 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 = ("/usr/bin/cvs", 'annotate', path) + cmd = self._get_cmd(w, **vargs) pipe = Popen(cmd, stdout=PIPE, stderr=PIPE) linetokens = [] @@ -265,3 +271,11 @@ class CvsBlame(Method): w.application.color_data_buffer("*Blame*", data, switch_to=True) else: w.set_error("There was an error (%s)" % (status)) + +class CvsBlame2(CvsBlame): + '''show blame output for the current version in CVS''' + args = [arg("revision", t=type(""), p="Revision: ", h="revision number")] + line_re = re.compile('^([0-9.]+) +\(*([a-zA-Z0-9_]+) +([-0-9A-Za-z]+)\): (.*)$') + def _get_cmd(self, w, **vargs): + path = self._get_path(w, **vargs) + return ("/usr/bin/cvs", 'annotate', '-r', vargs['revision'], path)