aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2007-04-04 14:48:47 +0000
committerStefan Monnier2007-04-04 14:48:47 +0000
commitade817bdf2fbe321a756e44f5e3ef62a31f80fa2 (patch)
treebff821de158c181f4c522b3f7339107eeddc97bc
parent8ea81ae0ef5d73b270ac8ebecdf20249eb4eab33 (diff)
downloademacs-ade817bdf2fbe321a756e44f5e3ef62a31f80fa2.tar.gz
emacs-ade817bdf2fbe321a756e44f5e3ef62a31f80fa2.zip
(format_exception): New function.
(eexecfile): Use it instead of traceback.print_exception. Don't use execfile to avoid a bug in w32.
-rw-r--r--etc/ChangeLog16
-rw-r--r--etc/emacs.py52
2 files changed, 55 insertions, 13 deletions
diff --git a/etc/ChangeLog b/etc/ChangeLog
index 2f9e52c03c6..a93960ea9ef 100644
--- a/etc/ChangeLog
+++ b/etc/ChangeLog
@@ -1,3 +1,9 @@
12007-04-04 Slawomir Nowaczyk <slawomir.nowaczyk.847@student.lu.se>
2
3 * emacs.py (format_exception): New function.
4 (eexecfile): Use it instead of traceback.print_exception.
5 Don't use execfile to avoid a bug in w32.
6
12007-04-04 Glenn Morris <rgm@gnu.org> 72007-04-04 Glenn Morris <rgm@gnu.org>
2 8
3 * MACHINES: Mention preprocessor to use with /opt/SUNWspro/bin/cc 9 * MACHINES: Mention preprocessor to use with /opt/SUNWspro/bin/cc
@@ -367,7 +373,7 @@
367 (section{TODO Items and Checkboxes}): Checkbox keys moved to this 373 (section{TODO Items and Checkboxes}): Checkbox keys moved to this
368 section, added documentation for the key `C-c #'. 374 section, added documentation for the key `C-c #'.
369 375
3702006-11-05 Slawomir Nowaczyk <slawek@cs.lth.se> (tiny change) 3762006-11-05 Slawomir Nowaczyk <slawek@cs.lth.se>
371 377
372 * emacs.py (eargs): Provide eldoc message for builtin types. 378 * emacs.py (eargs): Provide eldoc message for builtin types.
373 Make sure eargs always outputs sentinel, to avoid Emacs freeze. 379 Make sure eargs always outputs sentinel, to avoid Emacs freeze.
@@ -462,7 +468,7 @@
462 (eimport): Use __main__ rather than `emacs' namespace. 468 (eimport): Use __main__ rather than `emacs' namespace.
463 (modpath): New fun. 469 (modpath): New fun.
464 470
4652006-08-20 Slawomir Nowaczyk <slawomir.nowaczyk.847@student.lu.se> (tiny change) 4712006-08-20 Slawomir Nowaczyk <slawomir.nowaczyk.847@student.lu.se>
466 472
467 * emacs.py (eexecfile): Use the __main__ rather than `emacs' namespace. 473 * emacs.py (eexecfile): Use the __main__ rather than `emacs' namespace.
468 474
@@ -725,8 +731,8 @@
725 * pl-refcard.tex (section{Info}): Ditto. Translation suggested by 731 * pl-refcard.tex (section{Info}): Ditto. Translation suggested by
726 Slawomir Nowaczyk <slawomir.nowaczyk.847@student.lu.se>. 732 Slawomir Nowaczyk <slawomir.nowaczyk.847@student.lu.se>.
727 733
728 * cs-refcard.tex (section{Info}): Use `s' instead of `M-s'. Entry 734 * cs-refcard.tex (section{Info}): Use `s' instead of `M-s'.
729 for `i' is not translated yet. 735 Entry for `i' is not translated yet.
730 736
731 * pt-br-refcard.tex (section{Info}): Ditto. 737 * pt-br-refcard.tex (section{Info}): Ditto.
732 738
@@ -1455,7 +1461,7 @@
1455 1461
1456 * NEWS: Lots of clarifications and cleanups. 1462 * NEWS: Lots of clarifications and cleanups.
1457 1463
14582005-05-05 Slawomir Nowaczyk <slawek@cs.lth.se> (tiny change) 14642005-05-05 Slawomir Nowaczyk <slawek@cs.lth.se>
1459 1465
1460 * TUTORIAL.pl: Updated header. 1466 * TUTORIAL.pl: Updated header.
1461 1467
diff --git a/etc/emacs.py b/etc/emacs.py
index e38ee70fab5..0d0f2e75ed3 100644
--- a/etc/emacs.py
+++ b/etc/emacs.py
@@ -25,20 +25,56 @@ from sets import Set
25 25
26__all__ = ["eexecfile", "eargs", "complete", "ehelp", "eimport", "modpath"] 26__all__ = ["eexecfile", "eargs", "complete", "ehelp", "eimport", "modpath"]
27 27
28def format_exception (filename, should_remove_self):
29 type, value, tb = sys.exc_info ()
30 sys.last_type = type
31 sys.last_value = value
32 sys.last_traceback = tb
33 if type is SyntaxError:
34 try: # parse the error message
35 msg, (dummy_filename, lineno, offset, line) = value
36 except:
37 pass # Not the format we expect; leave it alone
38 else:
39 # Stuff in the right filename
40 value = SyntaxError(msg, (filename, lineno, offset, line))
41 sys.last_value = value
42 res = traceback.format_exception_only (type, value)
43 # There are some compilation errors which do not provide traceback so we
44 # should not massage it.
45 if should_remove_self:
46 tblist = traceback.extract_tb (tb)
47 del tblist[:1]
48 res = traceback.format_list (tblist)
49 if res:
50 res.insert(0, "Traceback (most recent call last):\n")
51 res[len(res):] = traceback.format_exception_only (type, value)
52 # traceback.print_exception(type, value, tb)
53 for line in res: print line,
54
28def eexecfile (file): 55def eexecfile (file):
29 """Execute FILE and then remove it. 56 """Execute FILE and then remove it.
30 Execute the file within the __main__ namespace. 57 Execute the file within the __main__ namespace.
31 If we get an exception, print a traceback with the top frame 58 If we get an exception, print a traceback with the top frame
32 (ourselves) excluded.""" 59 (ourselves) excluded."""
60 # We cannot use real execfile since it has a bug where the file stays
61 # locked forever (under w32) if SyntaxError occurs.
62 # --- code based on code.py and PyShell.py.
33 try: 63 try:
34 try: execfile (file, __main__.__dict__) 64 try:
35 except: 65 source = open (file, "r").read()
36 (type, value, tb) = sys.exc_info () 66 code = compile (source, file, "exec")
37 # Lose the stack frame for this location. 67 # Other exceptions (shouldn't be any...) will (correctly) fall
38 tb = tb.tb_next 68 # through to "final".
39 if tb is None: # print_exception won't do it 69 except (OverflowError, SyntaxError, ValueError):
40 print "Traceback (most recent call last):" 70 # FIXME: When can compile() raise anything else than
41 traceback.print_exception (type, value, tb) 71 # SyntaxError ????
72 format_exception (file, False)
73 return
74 try:
75 exec code in __main__.__dict__
76 except:
77 format_exception (file, True)
42 finally: 78 finally:
43 os.remove (file) 79 os.remove (file)
44 80