Browse files

Move pymacs-load's error handling to python code

This is to provide more helpful message when, for example,
pymacs-loading a python module and one of its dependencies is missing.
  • Loading branch information...
1 parent 8363300 commit 1683219c60e2f24a1d1ce376e264de64359728b3 @leoliu leoliu committed with Jun 14, 2012
Showing with 7 additions and 5 deletions.
  1. +5 −2
  2. +2 −3
@@ -403,7 +403,7 @@ class Protocol:
-def pymacs_load_helper(file_without_extension, prefix):
+def pymacs_load_helper(file_without_extension, prefix, noerror=None):
# This function imports a Python module, then returns a Lisp expression
# which, when later evaluated, will install trampoline definitions
# in Emacs for accessing the Python module facilities. Module, given
@@ -435,7 +435,10 @@ def pymacs_load_helper(file_without_extension, prefix):
for component in module_components[1:]:
module = getattr(module, component)
except ImportError:
- return None
+ if noerror:
+ return None
+ else:
+ raise
load_hook = module.__dict__.get('pymacs_load_hook')
if load_hook:
@@ -155,16 +155,15 @@ If NOERROR is not nil, do not raise error when the module is not found."
nil nil default)))
(list module prefix)))
(message "Pymacs loading %s..." module)
- (let ((lisp-code (pymacs-call "pymacs_load_helper" module prefix)))
+ (let ((lisp-code (pymacs-call "pymacs_load_helper" module prefix noerror)))
(cond (lisp-code (let ((result (eval lisp-code)))
(add-to-list 'pymacs-load-history
(list module prefix noerror)
;; append so that order is kept
(message "Pymacs loading %s...done" module)
- (noerror (message "Pymacs loading %s...failed" module) nil)
- (t (pymacs-report-error "Pymacs loading %s...failed" module)))))
+ (noerror (message "Pymacs loading %s...failed" module) nil))))
(defun pymacs-autoload (function module &optional prefix docstring interactive)

0 comments on commit 1683219

Please sign in to comment.