.emacs, I distinguish between two scenarios:
- AUCTeX is not available. Then I load my customizations for the basic TeX mode — let's call that
- AUCTeX is available. Then I load my AUCTeX customizations — let's call that
I currently check this by testing whether
(require 'tex-site) succeeds. This worked fine in the good old days, and still works when AUCTeX is installed system-wide or manually with
tex-site somewhere in
load-path, but it fails when AUCTeX is installed through Emacs's package mechanism, because then
tex-site is loaded during package initialization which happens after the init file.
If AUCTeX is available as a package, I want to load my AUCTeX customizations. Furthermore, if AUCTeX is both available as a package and provided system-wide, then
tex-site is already loaded by the time my init file runs, but I'd like to unload it and load the one available through the package mechanism instead. More precisely, ideally, I'd like to use the most recent AUCTeX version in this situation.
So my code might look like this:
(defun auctex-is-available () (condition-case nil (progn (require 'tex-site) AUCTeX-version) nil)) (defun use-auctex-package-p () ;; Test if AUCTeX is available as a package. ;; Preferably, if AUCTeX is also available by loading `tex-site' ;; from elsewhere, only use the package if it's more recent. ???) (cond ((use-auctex-package-p) (if (featurep 'tex-site) (unload-feature 'tex-site)) (eval-after-load 'tex-site '(my-auctex-customizations))) ((auctex-is-available) (my-auctex-customizations) (t (my-tex-mode-customizations)))
.emacs, how do I test for available package versions? If I do that in a post-init hook, which one, keeping in mind that:
- if AUCTeX is both present as a package and installed system-wide then the package must be used (at least if it's more recent);
- if AUCTeX is not present as a package then an attempt must be made to load
- if there's no AUCTeX anywhere then
my-tex-mode-customizationsmust get executed;
- if AUCTeX is loaded from anywhere then
my-auctex-customizationsmust get executed after the final
tex-sitehas been loaded;
- all of this must happen before
desktoploads my saved session;
- this must work on all Emacs versions that have a package facility (I'll fill in the
(fboundp 'package-…)to cope with older versions).