I use Pymacs to load ropemacs and rope with the following lines in my .emacs file as described here.
(autoload 'pymacs-load "pymacs" nil t)
(pymacs-load "ropemacs" "rope-")
It however slows down the start-up of Emacs significantly as it takes a while to load Ropemacs.
I tried the following line instead but that loads Ropemacs every time a Python file is opened:
(add-hook 'python-mode-hook (lambda () (pymacs-load "ropemacs" "rope-")))
Is there a way to perform the pymacs-load
operation when opening a Python file but only if ropemacs and rope aren't loaded yet?
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 be loaded only once. This happens when the first .py file is opened.
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. This is because occasionally ropemacs crashes for me, and when it does I just call that function to reload it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With