help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Autoload plus extra configurations


From: Giorgos Keramidas
Subject: Re: Autoload plus extra configurations
Date: Tue, 19 May 2009 09:24:37 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.93 (berkeley-unix)

On Mon, 18 May 2009 21:54:27 -0700 (PDT), Eric <girzel@gmail.com> wrote:
> I'm shifting a bunch of libraries to autoload in order to reduce load
> times, and running into an issue with extra configuration for those
> autoloaded libraries. Tramp, for instance, is enormous and slow and I
> don't use it often. I want to autoload it, but I've also got some
> extra configuration that accesses tramp-default-methods and tramp-set-
> completion-fuction, which are unavailable until tramp is actually
> loaded.
>
> Is there a way that I can tuck these configurations inside a hook that
> runs only when tramp is actually loaded, or otherwise delay the
> evaluation of these configurations until the proper variables and
> functions are available?

I think tramp *is* autoloaded only at the last possible moment in recent
Emacs versions.  At least it is autoloaded only when I try to open a
file URI that requires tramp here in Emacs 23.X.

Having said that, please have a look at `eval-after-load'.

For example, I load a separate lisp source file to configure emacs-w3m
in my `~/.emacs' file, but only after the "w3m" module is itself loaded:

  (eval-after-load "w3m"
    '(require 'keramida-w3m))

A similar Lisp form loads "keramida-erc.el" from my load-path, but only
when I explicitly load "erc" by invoking it:

  (eval-after-load "erc"
    '(require 'keramida-erc))

Yet another form loads my cc-mode customizations and hooks, but only
the first time I edit a file that triggers cc-mode to load:

  (eval-after-load "cc-mode"
    '(require 'keramida-cc-extra))

Note that the Lisp form passed to eval-after-load must be quoted!  If
you don't quote it, Emacs will try to evaluate it at the same time
before the `eval-after-load' form, which is very unlikely to be the
intended result.

By lazy loading as many libraries and extensions as possible, the
startup time of Emacs on my laptop is almost a second:

  $ time emacs-23.0.93 --batch \
    --eval '(princ (format "%s\n" (replace-regexp-in-string "\n" "" 
(version))))'
  GNU Emacs 23.0.93.1 (i386-unknown-freebsd8.0, GTK+ Version 2.16.1) of 
2009-05-18 on kobe
          0.974 real      0.412 user      0.562 sys



reply via email to

[Prev in Thread] Current Thread [Next in Thread]