In my .emacs
, I distinguish between two scenarios:
- AUCTeX is not available. Then I load my customizations for the basic TeX mode — let's call that
(my-tex-mode-customizations)
. - AUCTeX is available. Then I load my AUCTeX customizations — let's call that
(my-auctex-customizations)
.
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)))
But in .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
tex-site
; - if there's no AUCTeX anywhere then
my-tex-mode-customizations
must get executed; - if AUCTeX is loaded from anywhere then
my-auctex-customizations
must get executed after the finaltex-site
has been loaded; - all of this must happen before
desktop
loads 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).
package-alist
.package-alist
isn't available from.emacs
, any more thanpackage-installed-p
which looks like the right function to use.(directory-files (concat user-emacs-directory "elpa") t "auctex-[.0-9]+")