more pychecker-inspired cleanup

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-11-11 23:45:03 -05:00
parent 683afdf129
commit 74ab76836c
12 changed files with 46 additions and 52 deletions

View File

@ -25,7 +25,6 @@ import keyinput
import method import method
from minibuffer import MiniBuffer, MiniBufferError from minibuffer import MiniBuffer, MiniBufferError
import mode import mode
from point import Point
import util import util
from window import Window from window import Window
@ -59,31 +58,31 @@ class Application(object):
default = ('default', 'default') default = ('default', 'default')
# magenta is for keywords/builtins, translation, globs # magenta is for keywords/builtins, translation, globs
lo_magenta = ('magenta202', 'default') #lo_magenta = ('magenta202', 'default')
hi_magenta = ('magenta505', 'default') hi_magenta = ('magenta505', 'default')
# red is for comments, pods, endblocks # red is for comments, pods, endblocks
lo_red = ('red300', 'default') #lo_red = ('red300', 'default')
hi_red = ('red511', 'default') hi_red = ('red511', 'default')
# orange are for arrays and hashes # orange are for arrays and hashes
hi_orange = ('yellow531', 'default') #hi_orange = ('yellow531', 'default')
lo_orange = ('yellow520', 'default') #lo_orange = ('yellow520', 'default')
# yellow is for scalars and prototypes # yellow is for scalars and prototypes
hi_yellow = ('yellow551', 'default') #hi_yellow = ('yellow551', 'default')
lo_yellow = ('yellow330', 'default') #lo_yellow = ('yellow330', 'default')
# green is for strings and hash keys # green is for strings and hash keys
lo_green = ('green030', 'default') lo_green = ('green030', 'default')
hi_green = ('green050', 'default') hi_green = ('green050', 'default')
# cyan is for quotes, evals, regexes, subs # cyan is for quotes, evals, regexes, subs
lo_cyan = ('cyan033', 'default') #lo_cyan = ('cyan033', 'default')
hi_cyan = ('cyan155', 'default') hi_cyan = ('cyan155', 'default')
# blue is unused # blue is unused
lo_blue = ('blue113', 'default') #lo_blue = ('blue113', 'default')
hi_blue = ('blue225', 'default') hi_blue = ('blue225', 'default')
# let's prepopulate some default token colors # let's prepopulate some default token colors

1
gdb.py
View File

@ -1,7 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import os, re, sys import os, re, sys
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
import cache
_can_debug = os.system('which gdb > /dev/null 2>&1') == 0 _can_debug = os.system('which gdb > /dev/null 2>&1') == 0

View File

@ -19,21 +19,6 @@ def setup():
color_dict[color_names[i]] = color_list[i] color_dict[color_names[i]] = color_list[i]
setup() setup()
#def token_match(self, token, name, data=None):
# return token.fqname() == name and data is None or token.string == data
#def token_match2(self, token, name, regex):
# return token.fqname() == name and regex.match(token.string)
#def token_vmatch(self, token, *pairs):
# for (name, data) in pairs:
# if token_match(token, name, data):
# return True
# return False
#def token_vmatch2(self, token, *pairs):
# for (name, regex) in pairs:
# if token_match(token, name, regex):
# return True
# return False
class Highlighter(object): class Highlighter(object):
def __init__(self, lexer): def __init__(self, lexer):
self.lexer = lexer self.lexer = lexer
@ -87,7 +72,7 @@ class Highlighter(object):
y += 1 y += 1
def highlight(self, lines): def highlight(self, lines):
self.tokens = [[] for l in lines] self.tokens = [[] for _ in lines]
for token in self.lexer.lex(lines, y=0, x=0): for token in self.lexer.lex(lines, y=0, x=0):
self.tokens[token.y].append(token) self.tokens[token.y].append(token)
@ -203,7 +188,7 @@ class Highlighter(object):
# ok, so now we need to "adjust" the (x,y) coordinates of all the tokens # ok, so now we need to "adjust" the (x,y) coordinates of all the tokens
# after the change. first we will copy over the pre-deletion tokens. # after the change. first we will copy over the pre-deletion tokens.
newtokens = [[] for x in range(0, len(self.tokens) - y2 + y1)] newtokens = [[] for _ in range(0, len(self.tokens) - y2 + y1)]
for y in range(0, y1): for y in range(0, y1):
for token in self.tokens[y]: for token in self.tokens[y]:

2
lex.py
View File

@ -488,7 +488,7 @@ class Lexer(object):
def get_line(self): def get_line(self):
return self.lines[self.y] + '\n' return self.lines[self.y] + '\n'
def lex_all(self, lines): def lex_all(self, lines):
lextokens = [[] for l in lines] lextokens = [[] for _ in lines]
for t in self.lex(lines): for t in self.lex(lines):
lextokens[t.y].append(t) lextokens[t.y].append(t)
return lextokens return lextokens

View File

@ -1,4 +1,6 @@
import parser, symbol, sys, token import parser
import sys
import token
from pprint import pprint from pprint import pprint
def proc(asttup): def proc(asttup):
@ -15,10 +17,11 @@ def proc(asttup):
queue.insert(i, node[i + 1]) queue.insert(i, node[i + 1])
return pairs return pairs
for name in sys.argv[1:]: if __name__ == "__main__":
f = open(name, 'r') for name in sys.argv[1:]:
code = f.read() f = open(name, 'r')
f.close() code = f.read()
ast = parser.suite(code) f.close()
pairs = proc(ast.totuple()) ast = parser.suite(code)
pprint(pairs) pairs = proc(ast.totuple())
pprint(pairs)

View File

@ -43,10 +43,10 @@ class String(Rule):
def __init__(self, s): def __init__(self, s):
self.string = s self.string = s
def _match(self, tokens): def _match(self, tokens):
if token.string == self.string: for token in tokens:
return [1] if token.string == self.string:
else: return [1]
return [] return []
class Strings(Rule): class Strings(Rule):
def __init__(self, ss): def __init__(self, ss):
self.strings = ss self.strings = ss
@ -113,12 +113,12 @@ class Repeat(Rule):
self.maximum = maximum self.maximum = maximum
def match(self, tokens): def match(self, tokens):
n = 0 n = 0
for i in range(0, self.minimum): for _ in range(0, self.minimum):
result = self.rule.match(tokens[n:]) result = self.rule.match(tokens[n:])
if not result: if not result:
return [] return []
n += result[0] n += result[0]
for i in range(self.minimum, self.maximum): for _ in range(self.minimum, self.maximum):
result = self.rule.match(tokens[n:]) result = self.rule.match(tokens[n:])
if not result: if not result:
return [n] return [n]

View File

@ -1,3 +1,4 @@
import curses
import color import color
from point import Point from point import Point
@ -37,7 +38,7 @@ class RenderString(object):
s = self.string s = self.string
s2 = s.encode('utf-8') s2 = s.encode('utf-8')
cwin.addstr(self.y + y, self.x + x, s2, self.attrs) cwin.addstr(self.y + y, self.x + x, s2, self.attrs)
except Exception, e: except curses.error:
raise raise
#v = (self.y, y, self.x, x, self.string, self.attrs, str(e)) #v = (self.y, y, self.x, x, self.string, self.attrs, str(e))
#raise Exception, "cwin.addstr(%d + %d, %d + %d, %r, %r) failed:\n%s" % v #raise Exception, "cwin.addstr(%d + %d, %d + %d, %r, %r) failed:\n%s" % v

View File

@ -1,5 +1,4 @@
import re import re
import regex
from point import Point from point import Point
from render import HighlightRegion from render import HighlightRegion

2
tab.py
View File

@ -1,4 +1,4 @@
import regex, util import regex
from point import Point from point import Point
class Marker(object): class Marker(object):

10
term.py
View File

@ -36,6 +36,10 @@ def make_cbuf(fg, bg, xt):
class Dumb: class Dumb:
name = 'dumb' name = 'dumb'
cbuf = False cbuf = False
# style info
_fg = 'default'
_bg = 'default'
_xt = set()
def _term_insert(self, s): def _term_insert(self, s):
assert self.i <= len(self.outc) assert self.i <= len(self.outc)
if self.i == len(self.outc): if self.i == len(self.outc):
@ -48,13 +52,15 @@ class Dumb:
self.outs = '' self.outs = ''
self.i = 0 self.i = 0
self.outc = [] self.outc = []
if self.cbuf: self._term_insert(make_cbuf(self._fg, self._bg, self._xt)) if self.cbuf:
self._term_insert(make_cbuf(self._fg, self._bg, self._xt))
def term_do_clear_bol(self): def term_do_clear_bol(self):
pass pass
def term_do_clear_eol(self): def term_do_clear_eol(self):
del self.outc[self.i:] del self.outc[self.i:]
if self.cbuf: self._term_insert(make_cbuf(self._fg, self._bg, self._xt)) if self.cbuf:
self._term_insert(make_cbuf(self._fg, self._bg, self._xt))
def term_do_clear_eos(self): def term_do_clear_eos(self):
pass pass
def term_do_home(self): def term_do_home(self):

View File

@ -137,9 +137,9 @@ except:
dict.__repr__(self)) dict.__repr__(self))
def decode(s): def decode(s):
for format in ('utf-8', 'latin-1'): for coding in ('utf-8', 'latin-1'):
try: try:
return s.decode(format) return s.decode(coding)
except: except:
pass pass
return s.decode('ascii', 'replace') return s.decode('ascii', 'replace')

View File

@ -1,5 +1,7 @@
import os.path, string import os.path
import color, highlight, regex import color
import highlight
import regex
from point import Point from point import Point
from render import RenderString from render import RenderString
@ -453,7 +455,7 @@ class Window(object):
self.goto(Point(0, y)) self.goto(Point(0, y))
def forward_chars(self, n): def forward_chars(self, n):
(x, y) = self.logical_cursor().xy() (x, y) = self.logical_cursor().xy()
for i in range(0, n): for _ in range(0, n):
if x == len(self.buffer.lines[y]): if x == len(self.buffer.lines[y]):
y += 1 y += 1
x = 0 x = 0