added quote/dequote to perl

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-11-08 15:54:40 -05:00
parent 00edb537b3
commit 7ea3fd3855
1 changed files with 40 additions and 0 deletions

View File

@ -406,6 +406,45 @@ class PerldocWord(Perldoc):
return
return Perldoc._execute(self, w, name=word)
class PerlQuoteWord(Method):
word_re = re.compile('^[a-zA-Z0-9_]+$')
def _execute(self, w, **vargs):
t = w.get_token()
if t.fqname().endswith('string.data'):
return w.set_error('word is already quoted')
word = t.string
if word is None:
return w.set_error('no word selected')
if not self.word_re.match(word):
return w.set_error('not a perl word: %r' % word)
w.insert_string(Point(t.x, t.y), "'")
w.insert_string(Point(t.end_x(), t.y), "'")
class PerlDequoteWord(Method):
word_re = re.compile('^[a-zA-Z0-9_]+$')
def _execute(self, w, **vargs):
p = w.logical_cursor()
x1, x2 = p.x, p.end_x()
tokens = w.get_line_token_list_at_point(p)
data_token = None
saw_start = False
for token in tokens:
if token.end_x() < x1:
continue
elif token.fqname().endswith('string.start'):
saw_start = True
elif token.fqname().endswith('string.data'):
data_token = token
elif saw_start:
break
if not data_token:
w.set_error('no suitable quoted word found!')
return
w.set_error('going to dequote %r' % token.data)
class PerlInitFunctions(Method):
'''Jump to a function defined in this module'''
def _execute(self, w, **vargs):
@ -882,6 +921,7 @@ class Perl(Fundamental):
PerldocWord, Perldoc, PerldocF, PerlWrapParagraph, PerlInitFunctions,
PerlGotoFunction, PerlWhichFunction, PerlListFunctions, PerlOpenModule,
PerlOpenModuleWord, PerlSemanticComplete,
PerlQuoteWord, PerlDequoteWord,
]
completers = {
'perlfunction': PerlFunctionCompleter(None),