2007-10-12 22:58:17 -04:00
|
|
|
import string
|
2007-10-12 16:26:17 -04:00
|
|
|
import color, mode2
|
|
|
|
from lex3 import Grammar, PatternRule, RegionRule
|
2007-10-15 15:35:06 -04:00
|
|
|
from method import Method, Argument
|
|
|
|
from point2 import Point
|
2007-10-12 16:26:17 -04:00
|
|
|
|
|
|
|
class HexGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'zero', r"00"),
|
|
|
|
PatternRule(r'byte', r'[0-f][0-f]'),
|
|
|
|
]
|
|
|
|
|
|
|
|
class Hex(mode2.Fundamental):
|
|
|
|
grammar = HexGrammar
|
|
|
|
colors = {
|
|
|
|
'zero': ('magenta', 'default'),
|
|
|
|
'byte': ('white', 'default'),
|
|
|
|
}
|
|
|
|
def __init__(self, w):
|
|
|
|
mode2.Fundamental.__init__(self, w)
|
2007-10-12 22:58:17 -04:00
|
|
|
|
2007-10-15 15:35:06 -04:00
|
|
|
self.add_action_and_bindings(GotoWord(), ('M-g',))
|
|
|
|
|
2007-10-12 22:58:17 -04:00
|
|
|
# create all the insert actions for the basic text input
|
|
|
|
for c in string.letters + string.digits + string.punctuation:
|
|
|
|
if c in string.hexdigits:
|
|
|
|
self.add_binding('overwrite-char-%s' % c.lower(), c)
|
|
|
|
else:
|
|
|
|
self.del_binding(c)
|
|
|
|
|
2007-10-12 16:26:17 -04:00
|
|
|
def name(self):
|
|
|
|
return "Hex"
|
2007-10-15 15:35:06 -04:00
|
|
|
|
|
|
|
class GotoWord(Method):
|
|
|
|
'''Jump to the specified line number'''
|
|
|
|
args = [Argument("wordno", type=type(0), prompt="Goto word: ")]
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
n = vargs["wordno"]
|
|
|
|
if n < 0:
|
|
|
|
w.set_error("Negative word counts not supported.")
|
|
|
|
try:
|
|
|
|
p = Point((n % 4) * 9, n / 4)
|
|
|
|
w.goto(p)
|
|
|
|
except:
|
|
|
|
w.goto_end()
|