Ville Skyttä <scop(a)xemacs.org> wrote:
> A fix for this would be to append the new entries to the end of
> auto-mode-alist instead, e.g:
>
> ;;;###autoload
> (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode) t)
>
> This will work with Emacs 21 and XEmacs in the cvs since add-to-list
> has gotten the third APPEND argument there. To make it work with older
> (X)Emacsen, the package maintainer can add something like this:
/.../
Yep, you're right, the APPEND argument would be better,
unfortunately it
cannot be used in XEmacs packages at the moment because of the backwards
compatibility stuff you already mentioned. And I wouldn't like to see
too big workarounds for this in every package.
That is the workaround I intended to have in CC Mode. Why can't it be
used? Is there some situation where loaddefs.el in older XEmacsen are
updated with newer packages? (The size and ugliness of the kludge
itself doesn't become me very much; CC Mode already has plenty more of
similar cruft to work around bugs and limitations in various
versions. This one hardly makes a dent.)
/.../ Or we could try to make sure these *-mode-alist associations
are only used for generating package autoloads, and not evaluated
when loading the file. I don't know how to do that, though. Ideas?
From the elisp manual:
/.../ You can also use a magic comment to execute a form at build
time *without* executing it when the file itself is loaded. To do
this, write the form *on the same line* as the magic comment.
Since it is in a comment, it does nothing when you load the source
file; but `update-file-autoloads' copies it to `loaddefs.el',
where it is executed while building Emacs. /.../
Thus an alternative could be something like this:
(defun c-append-to-auto-mode-alist (element)
(unless (member element auto-mode-alist)
(setq auto-mode-alist (nconc auto-mode-alist (list element)))))
/.../
;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" .
objc-mode))
(c-append-to-auto-mode-alist '("\\.m\\'" . objc-mode))
But that would duplicate all the entries in the source, which I'd
rather avoid. One might of course skip the second step; it'd work
equally well as in earlier versions, when the package relied on the
central auto-mode-alist value. But I rather liked the idea to update
auto-mode-alist on package load, to install bindings for new modes
that doesn't exist in older (X)Emacsen.