branch : pmacs2
This commit is contained in:
moculus 2008-11-10 15:18:08 +00:00
parent 34571d027d
commit 277cd82b68
2 changed files with 109 additions and 0 deletions

View File

@ -108,6 +108,7 @@ class Application(object):
'latex', 'insertmini', 'conf', 'haskell', 'erlang',
'iperl', 'iperlmini', 'ipython', 'ipythonmini', 'awk',
'shell', 'shellmini', 'fstab', 'yacc', 'pipe',
'mbox',
)
for name in names:
exec("import mode.%s; mode.%s.install(self)" % (name, name))

108
mode/mbox.py Normal file
View File

@ -0,0 +1,108 @@
import commands, dirutil, grp, mailbox, method, mode, os.path, pwd, re
import buffer, default, window
from lex import Grammar, PatternRule, RegionRule, PatternGroupRule
from point import Point
from buffer import Buffer
from method import Method, Argument, arg
class MboxMsgBuffer(Buffer):
btype = 'mboxmsg'
def __init__(self, path, lineno, msg):
Buffer.__init__(self)
self.path = os.path.realpath(path)
self.base = os.path.basename(self.path)
self.lineno = lineno
self.msg = msg
def changed(self): return False
def readonly(self): return True
def path_exists(self): raise Exception
def _make_path(self, name): raise Exception
def save(self, force=False): raise Exception, "can't save an mbox message"
def save_as(self, path): raise Exception, "can't save an mbox message"
def name(self): return 'mbox:%s:%s' % (self.base, self.lineno)
def _get_lines(self):
return ['to', 'from', 'headers', 'subject', 'body']
def open(self):
self.lines = self._get_lines()
def reload(self):
lines = self._get_lines()
self.set_lines(lines, force=True)
class MboxListBuffer(Buffer):
btype = 'mboxlist'
format = '%(pos)4d %(flags)5.5s %(subject)s'
re1 = re.compile('[\n\t ]+')
def __init__(self, path):
Buffer.__init__(self)
self.path = os.path.realpath(path)
self.base = os.path.basename(self.path)
self.size = 0
def changed(self): return False
def readonly(self): return True
def path_exists(self): raise Exception
def _make_path(self, name): raise Exception
def save(self, force=False): raise Exception, "can't save an mbox"
def save_as(self, path): raise Exception, "can't save an mbox"
def name(self): return 'mbox:%s' % (self.base)
def _get_lines(self):
f = open(self.path, 'r')
self.size = len(f.read())
f.close()
self.mbox = mailbox.mbox(self.path)
#
lines = []
pos = 1
for msg in self.mbox:
subject = self.re1.sub(' ', msg['subject'])
msize = len(str(msg))
d = {
'pos': pos,
'flags': ''.join(msg.get_flags()),
'subject': subject,
}
s = self.format % d
lines.append(s)
pos += 1
#
return lines
def open(self):
self.lines = self._get_lines()
def reload(self):
lines = self._get_lines()
self.set_lines(lines, force=True)
class MboxRefresh(Method):
def _execute(self, w, **vargs):
w.buffer.reload()
class MboxOpenMsg(Method):
def _execute(self, w, **vargs):
w.set_error('your implementation here')
class MboxOpenPath(Method):
args = [arg('mbox', dt="path", p="Open Mbox: ", dv=default.path_dirname,
ld=True, h="mbox to open")]
def _execute(self, w, **vargs):
b = MboxListBuffer(vargs['mbox'])
b.open()
window.Window(b, w.application, height=0, width=0, mode_name='mbox')
w.application.add_buffer(b)
w.application.switch_buffer(b)
class Mbox(mode.Fundamental):
modename = 'Mbox'
colors = {}
actions = [MboxRefresh, MboxOpenPath, MboxOpenMsg]
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('mbox-refresh', ('C-c r',))
self.add_bindings('mbox-open-msg', ('RETURN',))
#self.add_bindings('open-path', ('RETURN',))
#self.add_bindings('dir-grep', ('C-c G',))
#self.add_bindings('chmod', ('C-c m',))
#self.add_bindings('chown', ('C-c o',))
#self.add_bindings('chgrp', ('C-c g',))
#self.add_bindings('touch-path', ('C-c t',))
#self.add_bindings('remove-path', ('DELETE', 'BACKSPACE', 'C-d'))
install = Mbox.install