Subject: bug#23329: 11.89; Unloading tex-site doesn't restore original functionality

From: Ikumi Keita <[email-masked]>
Date: Fri, 22 Apr 2016 15:49:57 +0900

Hi all,

> tex-site.el defines `tex-site-unload-hook' which looks into
> `after-load-alist' to remove AUCTeX settings (it looks for
> `TeX-modes-set' function), but in Emacs 24 `after-load-alist' seems to
> have changed and there is no reference to `TeX-modes-set' anymore.  Do
> you have any idea how to unload AUCTeX in Emacs 24?

I think I have figured out why `unload-feature' doesn't work well.  The
story is as follows.

If `advice-add' is available, tex-site.el uses `advice-add' on the
original tex modes and doesn't touch `after-load-alist'.

The advices are added through the defcustom of `TeX-modes' when
tex-site.el is loaded, because it has the line
  :set 'TeX-modes-set
.  Thus `tex-site-unload-hook' should remove these advices when
`advice-add' is available.

I confirmed that the attached crude workaround makes unloading tex-site
to work as expected.

Regards,
Ikumi Keita

diff -r 26f0a318aedb -r 125674651465 tex-site.el.in
--- a/tex-site.el.in	Tue Jun 03 14:10:34 2014 +0900
+++ b/tex-site.el.in	Fri Apr 22 15:22:33 2016 +0900
@@ -87,6 +87,8 @@
 
 (add-hook 'tex-site-unload-hook
 	  (lambda ()
+	    (if (fboundp 'advice-add)
+		(TeX-modes-set 'TeX-modes nil)
 	    (let ((list after-load-alist))
 	      (while list
 		;; Adapted copy of the definition of `assq-delete-all'
@@ -101,7 +103,7 @@
 			     (eq (car (car tail)) key))
 			(setq alist (delq (car tail) alist)))
 		    (setq tail (cdr tail))))
-		(setq list (cdr list))))
+		(setq list (cdr list)))))
 	    (setq load-path (delq TeX-lisp-directory load-path))))
 
 (defun TeX-modes-set (var value &optional update)