tabbing is starting

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-06-19 15:36:39 +00:00
parent 49dd8bc386
commit aebb6e5815
7 changed files with 68 additions and 76 deletions

View File

@ -1,5 +1,13 @@
package TBB::Reporting2; package TBB::Reporting2;
{
'foo',
'bar',
}
foo();
my $cat = "cat"; my $cat = "cat";
$cat =~ s/cat/dog/g; $cat =~ s/cat/dog/g;

View File

@ -442,6 +442,19 @@ class DeleteRightWhitespace(Method):
w.kill(c, p) w.kill(c, p)
# random stuff # random stuff
class DumpMarkers(Method):
'''Dump all tab markers (tab debugging)'''
def _execute(self, w, **vargs):
lines = []
if w.mode.tabber:
for i in range(0, len(w.mode.tabber.lines)):
line = w.mode.tabber.lines[i]
lines.append("LINE %d: %r" % (i, line))
lines.append(" %s" % repr(w.mode.tabber.markers[i]))
else:
lines.append("no tokens")
output = "\n".join(lines)
w.application.data_buffer("marker-dump", output, switch_to=True)
class DumpTokens(Method): class DumpTokens(Method):
'''Dump all lexical tokens (syntax highlighting debugging)''' '''Dump all lexical tokens (syntax highlighting debugging)'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
@ -506,15 +519,19 @@ class InsertTab(Method):
'''Insert tab into buffer, or tabbify line, depending on mode''' '''Insert tab into buffer, or tabbify line, depending on mode'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
cursor = w.logical_cursor() cursor = w.logical_cursor()
#i = w.mode.get_indentation_level(cursor.y) if w.mode.tabber:
i = w.mode.tabber.get_level(cursor.y)
else:
i = None i = None
if i is None: if i is None:
#raise Exception, repr(w.mode.tabber.lines)
w.insert_string_at_cursor(' ') w.insert_string_at_cursor(' ')
else: else:
j = w.buffer.count_leading_whitespace(cursor.y) j = w.buffer.count_leading_whitespace(cursor.y)
if i != j: if i != j:
KillWhitespace().execute(w) KillWhitespace().execute(w)
w.insert(Point(0, cursor.y), ' ' * i) w.insert_string(Point(0, cursor.y), ' ' * i * 4)
else: else:
w.goto(Point(j, cursor.y)) w.goto(Point(j, cursor.y))
class KillWhitespace(Method): class KillWhitespace(Method):
@ -1291,11 +1308,6 @@ class CloseTag(Method):
closetags = {')': '(', '}': '{', ']': '['} closetags = {')': '(', '}': '{', ']': '['}
mytag = ')' mytag = ')'
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
# if w.mode doesn't do tag matching, just insert the character return
if not w.mode.tag_matching:
w.insert_string_at_cursor(self.mytag)
return
# first, de-reference some variables and actually do the insertion # first, de-reference some variables and actually do the insertion
# NOTE: we derence the cursor *before* inserting the character, so it is # NOTE: we derence the cursor *before* inserting the character, so it is
# expecected that the cursor variable should be the point the new # expecected that the cursor variable should be the point the new

View File

@ -152,7 +152,6 @@ class Fundamental(Handler):
self.add_binding('insert-string-%s' % c, c) self.add_binding('insert-string-%s' % c, c)
# initialize some stuff # initialize some stuff
self.tag_matching = False
self.grammar = None self.grammar = None
self.lexer = None self.lexer = None
self.tabber = None self.tabber = None

View File

@ -1,10 +1,7 @@
import os import os, sets, string
import sets, string import color, lex2
import color, default, method, point
DEBUG = False DEBUG = False
#DEBUG = True
class Handler: class Handler:
def __init__(self): def __init__(self):
@ -58,12 +55,20 @@ class Handler:
class Fundamental(Handler): class Fundamental(Handler):
'''This is the default mode''' '''This is the default mode'''
tabbercls = None
grammar = None
lexer = None
tabber = None
def __init__(self, w): def __init__(self, w):
self.window = w self.window = w
# we need to defer this due to curses startup
self.default_color = color.pairs('default', 'default')
self.colors = {}
Handler.__init__(self) Handler.__init__(self)
self.bindings = {} # first let's add all the "default" actions
self.add_bindings('start-of-line', ('C-a', 'HOME',)) self.add_bindings('start-of-line', ('C-a', 'HOME',))
self.add_bindings('end-of-line', ('C-e', 'END',)) self.add_bindings('end-of-line', ('C-e', 'END',))
self.add_bindings('backward', ('C-b', 'L_ARROW',)) self.add_bindings('backward', ('C-b', 'L_ARROW',))
@ -136,26 +141,18 @@ class Fundamental(Handler):
self.add_bindings('cmd-help-buffer', ('M-h',)) self.add_bindings('cmd-help-buffer', ('M-h',))
self.add_bindings('set-mode', ('C-x m',)) self.add_bindings('set-mode', ('C-x m',))
self.add_bindings('cancel', ('C-]',)) self.add_bindings('cancel', ('C-]',))
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
# create all the insert actions for the character ranges we like # create all the insert actions for the basic text input
for c in string.letters + string.digits + string.punctuation: for c in string.letters + string.digits + string.punctuation:
# closing tags are handled differently
if c == ')' or c == ']' or c == '}':
continue
self.add_binding('insert-string-%s' % c, c) self.add_binding('insert-string-%s' % c, c)
# initialize some stuff # lexing for highlighting, etc.
self.tag_matching = False if self.grammar:
self.grammar = None self.lexer = lex2.Lexer(self.name(), self.grammar)
self.lexer = None
self.tabber = None
# initialize the default colors, highlighter, etc. # tab handling
self.default_color = color.pairs('default', 'default') if self.tabbercls:
self.colors = {} self.tabber = self.tabbercls(self)
# get mode name # get mode name
def name(self): def name(self):
@ -190,3 +187,10 @@ class Fundamental(Handler):
else: else:
err = "%s in mode '%s'" % (e, self.name()) err = "%s in mode '%s'" % (e, self.name())
self.window.application.set_error(err) self.window.application.set_error(err)
def region_added(self, p, newlines):
if self.tabber is not None:
self.tabber.region_added(p, newlines)
def region_removed(self, p1, p2):
if self.tabber is not None:
self.tabber.region_removed(p1, p2)

View File

@ -1,5 +1,5 @@
import re, sets, string, sys import re, sets, string, sys
import color, commands, default, lex2, method, mode2, regex import color, commands, default, lex2, method, mode2, regex, tab2
from point2 import Point from point2 import Point
from lex2 import Grammar, ConstantRule, PatternRule, ContextPatternRule, \ from lex2 import Grammar, ConstantRule, PatternRule, ContextPatternRule, \
RegionRule, DualRegionRule RegionRule, DualRegionRule
@ -101,13 +101,14 @@ class PerlGrammar(Grammar):
] ]
class Perl(mode2.Fundamental): class Perl(mode2.Fundamental):
#tabbercls = tab2.Tabber
tabbercls = tab2.StackTabber
grammar = PerlGrammar()
opentags = {'(': ')', '[': ']', '{': '}'}
closetags = {')': '(', ']': '[', '}': '{'}
def __init__(self, w): def __init__(self, w):
mode2.Fundamental.__init__(self, w) mode2.Fundamental.__init__(self, w)
self.tag_matching = True
self.grammar = PerlGrammar()
self.lexer = lex2.Lexer(self.name(), self.grammar)
self.add_action_and_bindings(PerlCheckSyntax(), ('C-c s',)) self.add_action_and_bindings(PerlCheckSyntax(), ('C-c s',))
self.add_action_and_bindings(PerlHashCleanup(), ('C-c h',)) self.add_action_and_bindings(PerlHashCleanup(), ('C-c h',))
#self.add_action_and_bindings(PerlHashCleanup2(), ('C-c h',)) #self.add_action_and_bindings(PerlHashCleanup2(), ('C-c h',))

View File

@ -121,26 +121,24 @@ class PythonGrammar(Grammar):
] ]
class Python(mode2.Fundamental): class Python(mode2.Fundamental):
grammar = PythonGrammar #tabbercls = tab2.Tabber
tabber = tab2.Tabber grammar = PythonGrammar()
opentags = {'(': ')', '[': ']', '{': '}'}
closetags = {')': '(', ']': '[', '}': '{'}
def __init__(self, w): def __init__(self, w):
mode2.Fundamental.__init__(self, w) mode2.Fundamental.__init__(self, w)
self.tag_matching = True # add python-specific methods
self.grammar = PythonGrammar()
self.lexer = lex2.Lexer(self.name(), self.grammar)
self.add_action_and_bindings(PythonCheckSyntax(), ('C-c s',)) self.add_action_and_bindings(PythonCheckSyntax(), ('C-c s',))
self.add_action_and_bindings(PythonDictCleanup(), ('C-c h',)) self.add_action_and_bindings(PythonDictCleanup(), ('C-c h',))
self.add_action_and_bindings(PythonUpdateTags(), ('C-c t',)) self.add_action_and_bindings(PythonUpdateTags(), ('C-c t',))
self.add_action_and_bindings(PythonTagComplete(), ('C-c k',)) self.add_action_and_bindings(PythonTagComplete(), ('C-c k',))
# we want to do these kinds of tag matching
self.add_bindings('close-paren', (')',)) self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',)) self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',)) self.add_bindings('close-bracket', (']',))
self.default_color = color.build('default', 'default')
self.colors = { self.colors = {
'keyword': color.build('cyan', 'default'), 'keyword': color.build('cyan', 'default'),
'reserved': color.build('cyan', 'default'), 'reserved': color.build('cyan', 'default'),
@ -155,9 +153,6 @@ class Python(mode2.Fundamental):
'string.format': color.build('yellow', 'default'), 'string.format': color.build('yellow', 'default'),
'string.end': color.build('green', 'default'), 'string.end': color.build('green', 'default'),
#'integer': color.build('red', 'default'),
#'float': color.build('red', 'default'),
#'imaginary': color.build('red', 'default'),
'integer': color.build('default', 'default'), 'integer': color.build('default', 'default'),
'float': color.build('default', 'default'), 'float': color.build('default', 'default'),
'imaginary': color.build('default', 'default'), 'imaginary': color.build('default', 'default'),
@ -172,37 +167,9 @@ class Python(mode2.Fundamental):
'comment': color.build('red', 'default'), 'comment': color.build('red', 'default'),
'continuation': color.build('red', 'default'), 'continuation': color.build('red', 'default'),
#'operator': color.build('yellow', 'default'),
#'delimiter': color.build('magenta', 'default'),
'system_identifier': color.build('cyan', 'default'), 'system_identifier': color.build('cyan', 'default'),
#'bound method': color.build(color.build('yellow', 'default'), 'default'),
'import': color.build('magenta', 'default'),
#'bizzaro': color.build('magenta', 'default'),
} }
# self.colors = {
# 'keyword' : color.build('cyan', 'default', 'bold'),
# 'pseudo-keyword' : color.build('cyan', 'default', 'bold'),
# 'built-in method' : color.build('cyan', 'default', 'bold'),
# 'method declaration' : color.build('blue', 'default', 'bold'),
# 'class declaration' : color.build('green', 'default'),
# 'string4' : color.build('green', 'default'),
# 'string3' : color.build('green', 'default'),
# 'string2' : color.build('green', 'default'),
# 'string1' : color.build('green', 'default'),
# 'comment' : color.build('red', 'default'),
# 'continuation' : color.build('red', 'default'),
# #'operator' : color.build('yellow', 'default'),
# #'delimiter' : color.build('magenta', 'default'),
# 'system_identifier' : color.build('cyan', 'default', 'bold'),
# #'bound method' : color.build('yellow', 'default'),
# 'import statement' : color.build('magenta', 'green'),
# 'bizzaro' : color.build('magenta', 'green'),
# }
#self.tabber = tab_python.PythonTabber(self)
#self.ctagger = ctag_python.PythonCTagger()
def name(self): def name(self):
return "Python" return "Python"
@ -248,7 +215,6 @@ class PythonTagComplete(method.Method):
start = cursor.x start = cursor.x
word_chars = string.letters + string.digits + '_' word_chars = string.letters + string.digits + '_'
#word_chars = string.letters + string.digits + string.punctuation
if start == 0: if start == 0:
w.application.set_error('walrus 1') w.application.set_error('walrus 1')
return return

View File

@ -152,6 +152,7 @@ class Window(object):
self.cursor = Point(len(newlines[-1]) + x - p.x, y + l - 1) self.cursor = Point(len(newlines[-1]) + x - p.x, y + l - 1)
elif y == p.y and x >= p.x: elif y == p.y and x >= p.x:
self.cursor = Point(x + len(newlines[0]), y) self.cursor = Point(x + len(newlines[0]), y)
self.mode.region_added(p, newlines)
self.assure_visible_cursor() self.assure_visible_cursor()
# region removed # region removed
@ -166,6 +167,7 @@ class Window(object):
self.cursor = Point(self.cursor.x - p2.x + p1.x, p1.y) self.cursor = Point(self.cursor.x - p2.x + p1.x, p1.y)
else: else:
self.cursor = Point(self.cursor.x, self.cursor.y - p2.y + p1.y) self.cursor = Point(self.cursor.x, self.cursor.y - p2.y + p1.y)
self.mode.region_removed(p1, p2)
self.assure_visible_cursor() self.assure_visible_cursor()
def point_is_visible(self, p): def point_is_visible(self, p):