improved rc error handling

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-10-19 07:01:34 +00:00
parent 7a374ea5b1
commit 437c9bacb2
1 changed files with 15 additions and 51 deletions

View File

@ -2,23 +2,10 @@
import curses, curses.ascii, getpass, os, re, string, sets, sys, termios, time import curses, curses.ascii, getpass, os, re, string, sets, sys, termios, time
import traceback import traceback
import buffer2, bufferlist, color, completer, keyinput, method, minibuffer import buffer2, bufferlist, color, completer, keyinput, method, minibuffer, mode2
import util, window2 import util, window2
from point2 import Point from point2 import Point
# modes
import mode2
import mode.mini, mode.search, mode.replace, mode.which
import mode.console, mode.consolemini
import mode.c, mode.python, mode.perl, mode.nasm, mode.sql, mode.java
import mode.sh, mode.make
import mode.lisp, mode.elisp, mode.scheme, mode.ocaml
import mode.blame, mode.diff, mode.dir
import mode.xml, mode.tt, mode.css, mode.javascript, mode.html, mode.hex
import mode.text, mode.text2, mode.mutt
#import mode.bds
import mode.rst
def run(buffers, jump_to_line=None, init_mode=None): def run(buffers, jump_to_line=None, init_mode=None):
# save terminal state so we can restore it when the program exits # save terminal state so we can restore it when the program exits
attr = termios.tcgetattr(sys.stdin) attr = termios.tcgetattr(sys.stdin)
@ -93,39 +80,14 @@ class Application(object):
self.mode_extensions = {} self.mode_extensions = {}
self.mode_detection = {} self.mode_detection = {}
#mode2.Fundamental.install(self) # ok, now let's load all the "standard" modes
mode2.install(self) mode2.install(self)
mode.blame.install(self) for name in ('blame', 'c', 'console', 'consolemini', 'css', 'diff',
mode.c.install(self) 'dir', 'elisp', 'hex', 'html', 'java', 'javascript',
mode.console.install(self) 'lisp', 'make', 'mini', 'mutt', 'nasm', 'ocaml', 'perl',
mode.consolemini.install(self) 'python', 'replace', 'rst', 'scheme', 'search', 'sh',
mode.css.install(self) 'sql', 'tt', 'text', 'text2', 'which', 'xml'):
mode.diff.install(self) exec("import mode.%s; mode.%s.install(self)" % (name, name))
mode.dir.install(self)
mode.elisp.install(self)
mode.hex.install(self)
mode.html.install(self)
mode.java.install(self)
mode.javascript.install(self)
mode.lisp.install(self)
mode.make.install(self)
mode.mini.install(self)
mode.mutt.install(self)
mode.nasm.install(self)
mode.ocaml.install(self)
mode.perl.install(self)
mode.python.install(self)
mode.replace.install(self)
mode.rst.install(self)
mode.scheme.install(self)
mode.search.install(self)
mode.sh.install(self)
mode.sql.install(self)
mode.tt.install(self)
mode.text.install(self)
mode.text2.Text2.install(self)
mode.which.install(self)
mode.xml.install(self)
# initialize our methods # initialize our methods
self.methods = {} self.methods = {}
@ -153,6 +115,9 @@ class Application(object):
# note that the first buffer in buffers will be initially visible # note that the first buffer in buffers will be initially visible
buffers.append(buffer2.ScratchBuffer()) buffers.append(buffer2.ScratchBuffer())
buffers.append(buffer2.ConsoleBuffer()) buffers.append(buffer2.ConsoleBuffer())
if self.rcerror:
buffers.insert(0, buffer2.DataBuffer('*RcError*', self.rcerror))
self.bufferlist = bufferlist.BufferList(height, width) self.bufferlist = bufferlist.BufferList(height, width)
self.active_slot = 0 self.active_slot = 0
@ -197,6 +162,8 @@ class Application(object):
curses.noecho() curses.noecho()
curses.nonl() curses.nonl()
# this sets up a mode, as well as optionally adding information on when to
# auto-load the mode
def setmode(self, name, cls, paths=[], basenames=[], extensions=[], detection=[]): def setmode(self, name, cls, paths=[], basenames=[], extensions=[], detection=[]):
self.modes[name] = cls self.modes[name] = cls
for p in paths: for p in paths:
@ -439,10 +406,6 @@ class Application(object):
def eval(self, s): def eval(self, s):
return eval(s) return eval(s)
#
def loadmode(self, name, path):
pass
# load user configuration NOW # load user configuration NOW
def loadrc(self): def loadrc(self):
path = os.path.join(os.getenv('HOME'), '.pmc', 'conf') path = os.path.join(os.getenv('HOME'), '.pmc', 'conf')
@ -450,7 +413,8 @@ class Application(object):
try: try:
execfile(path) execfile(path)
except Exception, e: except Exception, e:
self.rcerror = e s = traceback.format_exc()
self.rcerror = 'There was an error during startup:\n\n%s' % s
# the mighty run-loop! # the mighty run-loop!
def run(self): def run(self):