emacs-devel
[Top][All Lists]
Advanced

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

Re: unload-feature questions and thoughts


From: David Kastrup
Subject: Re: unload-feature questions and thoughts
Date: Thu, 25 Oct 2007 23:24:07 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

Richard Stallman <address@hidden> writes:

>     Have you checked AUCTeX's loadup/startup sequence?  It uses the
>     unload hooks in order to offer a way of selectively disabling
>     autoloaded parts.
>
> Could you tell us how AUCTeX's hooks would be affected by the
> various proposed changes?

Actually, I don't really have time in the next few days to do the
proper research.

One somewhat surprising thing I remembered is that it was necessary to
call an autoloaded (dummy in this case) function instead of
straightforwardly using require.  The latter did not register the
necessary information for unloading the feature again (unloading the
feature needs to restore autoloads for the default TeX modes).

To wit, we have
;;; auctex.el
;;
;; This can be used for starting up AUCTeX.  The following somewhat
;; strange trick causes tex-site.el to be loaded in a way that can be
;; safely undone using (unload-feature 'tex-site).
;;
(autoload 'TeX-load-hack
  @lisptexsite@)
(TeX-load-hack)

Where @lisptexsite@ resolves to the full path of the actual startup
file tex-site.el.

This file contains the following relevant stuff:

(defalias 'TeX-load-hack 'ignore)

(add-hook 'tex-site-unload-hook
          (lambda ()
            (let ((list after-load-alist))
              (while list
                ;; Adapted copy of the definition of `assq-delete-all'
                ;; from Emacs 21 as substitute for
                ;; `(assq-delete-all'TeX-modes-set (car list))' which
                ;; fails on non-list elements in Emacs 21.
                (let* ((alist (car list))
                       (tail alist)
                       (key 'TeX-modes-set))
                  (while tail
                    (if (and (consp (car tail))
                             (eq (car (car tail)) key))
                        (setq alist (delq (car tail) alist)))
                    (setq tail (cdr tail))))
                (setq list (cdr list))))
            (setq load-path (delq TeX-lisp-directory load-path))))

(defun TeX-modes-set (var value &optional update)
  "Set VAR (which should be `TeX-modes') to VALUE.

This places either the standard or the AUCTeX versions of
functions into the respective function cell of the mode.
If UPDATE is set, a previously saved value for
the non-AUCTeX function gets overwritten with the current
definition."
  (custom-set-default var value)
  (let ((list TeX-mode-alist) elt)
    (while list
      (setq elt (car (pop list)))
      (when (or update (null (get elt 'tex-saved)))
        (when (fboundp elt)
          (put elt 'tex-saved (symbol-function elt))))
      (defalias elt
        (if (memq elt value)
            (intern (concat "TeX-" (symbol-name elt)))
          (get elt 'tex-saved))))))

(defcustom TeX-modes
  (mapcar 'car TeX-mode-alist)
  "List of modes provided by AUCTeX.

This variable can't be set normally; use customize for that, or
set it with `TeX-modes-set'."
  :type (cons 'set
              (mapcar (lambda(x) (list 'const (car x))) TeX-mode-alist))
  :set 'TeX-modes-set
  :group 'AUCTeX
  :initialize (lambda (var value)
                (custom-initialize-reset var value)
                (let ((list TeX-mode-alist))
                  (while list
                    (eval-after-load (cdar list)
                      `(TeX-modes-set ',var ,var t))
                    (setq list (cdr list))))))


This is all rather messy and I don't remember all too well what all of
this does for which exact reason, but the key point is that the
variable TeX-modes can be set to overwrite a selected subset of mode
definition autoloads with autoloads for the respective AUCTeX version
of the mode, and (unload-feature 'tex-site) will pretty much undo
(load-file "auctex.el") as long as none of the autoloads overwritten
in tex-site.el have yet been triggered.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum




reply via email to

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