[Top][All Lists]

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

Finding a variable before it's loaded

From: Stefan Monnier
Subject: Finding a variable before it's loaded
Date: Thu, 23 Feb 2012 16:48:56 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

>> The docstring of comment-style refers the user to comment-styles for
>> details on what the values mean.  However, this is not available until
>> after newcomment.el is loaded.  So autoload comment-styles to avoid
>> this problem.
> Then this is an instance of a general problem. See eg
> http://debbugs.gnu.org/cgi/bugreport.cgi?bug=1768
> for the same thing.
> IMO there should be a general solution rather than papering over every
> instance that occurs with more pre/autoloading.

Yes, there is a general problem underneath, but it's difficult to
solve satisfactorily.  IIRC someone did submit a potential solution at
some point, but it required building a fairly large file listing where
each var is defined.

I have toyed with a slightly different approach which tries to reduce
the size of this file by keeping not the list of all vars, but only
a list of prefixes used by each file.
This way, if I want to find `comment-styles', I can simply load all the files
that define variables with the "comment-" prefix.

The table of prefixes is not very large, so I can simply have it
preloaded and put it in loaddefs.el (and it's automatically maintained
by autoload.el, which means it can also work for non-bundled packages if
their autoloads are generated by autoload.el).

E.g. for newcomment.el my code adds:

(register-definition-prefixes "newcomment"
  '("comment-" "uncomment-region-function" "uncomment-region-default"
    "block-comment-start" "block-comment-end"))

and for diff-mode.el it doesn't add anything at all, because I use
a default rule "for <foo>-<bar>, look for a file <foo>.el or
<foo>-mode.el" and that covers all the definitions in diff-mode.el.

It's also fun to look at all the register-definition-prefixes in
loaddefs.el as a way to flag "unclean namespace issues".


reply via email to

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