1

After profiling my Emacs init file, I saw that many of my modes are taking a long time to load, explaining why I've been having slow start times.

I am trying to use after-load or autoload to decrease the load time but have been unsuccessful in many modes.

For example, I have a mode called multiple-cursors.el that I downloaded manually and placed in my .emacs.d directory. Here is the code I have now:

;; Multiple Cursors                                                               
(add-to-list 'load-path "~/.emacs.d/multiple-cursors.el/")
(require 'multiple-cursors)  
(global-set-key (kbd "C-c c") 'mc/edit-lines)                                     
(global-set-key (kbd "C-c .") 'mc/mark-next-like-this)
(global-set-key (kbd "C-c ,") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c /") 'mc/mark-all-like-this)

I tried to replace the require line with (autoload 'multiple-cursors-mode "multiple-cursors.el" "Multiple cursors mode") but that did not work.

This format of the autoload seems to work well only with Melpa-installed packages. How can I do the equivalent for manually installed packages, such as the example above?

darksky
  • 20,411
  • 61
  • 165
  • 254
  • 1
    There is no such thing as `multiple-cursors-mode`, that you should autoload. You need to add autoloads for all `mc/…` functions you'd like to use. You should probably just use package.el instead. –  Jul 29 '14 at 15:29

1 Answers1

4

You need to write autoloads for the functions that you are actually calling through the key bindings (i.e. mc/edit-lines, mc/mark-next-like-this, mc/mark-previous-like-this and mc/mark-all-like-this), since that's how the loading of the file is triggered. The autoloads need to refer to the files where the respective functions are defined, which is mc-edit-lines for mc/edit-lines, and mc-mark-more for the others.

So after setting the load path and binding the keys, add something like this:

(autoload 'mc/edit-lines "mc-edit-lines" "" t)
(autoload 'mc/mark-next-like-this "mc-mark-more" "" t)
(autoload 'mc/mark-previous-like-this "mc-mark-more" "" t)
(autoload 'mc/mark-all-like-this "mc-mark-more" "" t)
legoscia
  • 39,593
  • 22
  • 116
  • 167