Browse files

Support reloading modules by recording loading history

in pymacs-load-history.
  • Loading branch information...
1 parent 5989046 commit 8a9684cd097d6766a4867265e4473ddb8cbb08be @leoliu leoliu committed May 2, 2012
Showing with 17 additions and 1 deletion.
  1. +17 −1
@@ -138,6 +138,8 @@ Possible values are nil, t or ask.")
"If zombies should trigger hard errors, whenever they get called.
If `nil', calling a zombie will merely produce a diagnostic message.")
+(defvar pymacs-load-history nil "Pymacs loading history.")
(defun pymacs-load (module &optional prefix noerror)
"Import the Python module named MODULE into Emacs.
@@ -155,6 +157,10 @@ If NOERROR is not nil, do not raise error when the module is not found."
(message "Pymacs loading %s..." module)
(let ((lisp-code (pymacs-call "pymacs_load_helper" module prefix)))
(cond (lisp-code (let ((result (eval lisp-code)))
+ (add-to-list 'pymacs-load-history
+ (list module prefix noerror)
+ ;; append so that order is kept
+ 'append)
(message "Pymacs loading %s...done" module)
(noerror (message "Pymacs loading %s...failed" module) nil)
@@ -650,7 +656,17 @@ The timer is used only if `post-gc-hook' is not available.")
(add-hook 'post-gc-hook 'pymacs-schedule-gc)
(setq pymacs-gc-timer (run-at-time 20 20 'pymacs-schedule-gc))))
;; If nothing failed, only then declare that Pymacs has started!
- (setq pymacs-transit-buffer buffer)))
+ (setq pymacs-transit-buffer buffer)
+ (let ((modules pymacs-load-history))
+ (setq pymacs-load-history nil)
+ (when (and modules (yes-or-no-p "Reload modules in previous session? "))
+ (mapc (lambda (args)
+ ;; Be defensive in case sys.path differs
+ (condition-case err
+ (apply 'pymacs-load args)
+ (error
+ (message "%s: %s" (car err) (error-message-string err)))))
+ modules)))))
(defun pymacs-terminate-services ()
;; This function is mainly provided for documentation purposes.

0 comments on commit 8a9684c

Please sign in to comment.