views:

235

answers:

2

I use Pymacs to load Ropemacs and Rope with the following lines in my .emacs as described here.

(autoload 'pymacs-load "pymacs" nil t)
(pymacs-load "ropemacs" "rope-")

It however slows down the startup of Emacs significantly as it takes a while to load Ropemacs.

I tried the following line instead but that loads Ropemacs everytime Python file is opened...

(add-hook 'python-mode-hook (lambda () (pymacs-load "ropemacs" "rope-")))

Is there a way to perform the pymacs-load when opening a Python file but only if ropemacs and rope aren't loaded yet?

+1  A: 

In my .emacs I have

(autoload 'python-mode "my-python-setup" "" t)

And in a separate file my-python-setup.el I keep

(require 'python)
(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
;; Initialize Pymacs
(autoload 'pymacs-apply "pymacs")
(autoload 'pymacs-call "pymacs")
(autoload 'pymacs-eval "pymacs" nil t)
(autoload 'pymacs-exec "pymacs" nil t)
(autoload 'pymacs-load "pymacs" nil t)
;; Initialize Rope
(pymacs-load "ropemacs" "rope-")
(setq ropemacs-enable-autoimport t)

This way, Pymacs and ropemacs will only be loaded on opening a .py file.

mmmasterluke
Oh, very clever! Thanks! :)
monotux
A: 

This is what eval-after-load is for.

(eval-after-load "python-mode"
  '(progn
     ;; Do whatever you need to do here, it will only get executed after python-mode.el has loaded
     (require 'pymacs)
     (pymacs-load "ropemacs" "rope-")))

You'll need to write "python" instead of "python-mode" if you use python.el instead of python-mode.el.

I actually have my ropemacs loading code in a separate function that can be called interactively, occasionally ropemacs crashes for me and when it does I just call that function to reload it.

Thomas Parslow