* Makefile.in (list-installed-shadows): New entry.
authorKatsumi Yamaoka <yamaoka@jpl.org>
Tue, 4 Oct 2005 09:38:33 +0000 (09:38 +0000)
committerKatsumi Yamaoka <yamaoka@jpl.org>
Tue, 4 Oct 2005 09:38:33 +0000 (09:38 +0000)
(install): Use it.
(remove-installed-shadows): New entry.

* dgnushack.el (dgnushack-default-load-path): New variable.
(dgnushack-find-lisp-shadows): New function.
(dgnushack-remove-lisp-shadows): New function.

lisp/ChangeLog
lisp/Makefile.in
lisp/dgnushack.el

index b839497..09c3f38 100644 (file)
@@ -1,3 +1,13 @@
+2005-10-04  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+       * Makefile.in (list-installed-shadows): New entry.
+       (install): Use it.
+       (remove-installed-shadows): New entry.
+
+       * dgnushack.el (dgnushack-default-load-path): New variable.
+       (dgnushack-find-lisp-shadows): New function.
+       (dgnushack-remove-lisp-shadows): New function.
+
 2005-10-02  Katsumi Yamaoka  <yamaoka@jpl.org>
 
        * Makefile.in (install-el-elc): New entry.
index 866b389..15e7340 100644 (file)
@@ -29,7 +29,7 @@ warn: clean-some gnus-load.el
 clever some l: gnus-load.el
        $(EMACS_COMP) -f dgnushack-compile
 
-install: install-el-elc
+install: install-el-elc list-installed-shadows
 
 # This entry will never install .el files if there are no .elc files.
 install-el: gnus-load.el
@@ -67,6 +67,12 @@ install-el-elc: clever
          $(INSTALL_DATA) $$p $(lispdir)/$$p; \
        done
 
+list-installed-shadows:
+       $(EMACS_COMP) -f dgnushack-find-lisp-shadows
+
+remove-installed-shadows:
+       $(EMACS_COMP) -f dgnushack-remove-lisp-shadows
+
 uninstall:
        for p in *.elc; do \
          rm -f "$(lispdir)/$$p"; \
index 8ef0ee6..5e769ec 100644 (file)
@@ -28,6 +28,8 @@
 
 ;;; Code:
 
+(defvar dgnushack-default-load-path (copy-sequence load-path))
+
 (defalias 'facep 'ignore)
 
 (require 'cl)
@@ -411,6 +413,83 @@ dgnushack-compile."
 ;;; End:
 ;;; gnus-load.el ends here"))))
 
+(defun dgnushack-find-lisp-shadows (&optional lispdir)
+  "Return a list of directories in which other Gnus installations exist.
+This function looks for the other Gnus installations which will shadow
+the new Gnus Lisp modules which have been installed in LISPDIR, using
+the default `load-path'.  The return value will make sense only when
+LISPDIR is existent and is listed in the default `load-path'.  Assume
+LISPDIR will be prepended to `load-path' by a user if the default
+`load-path' does not contain it."
+  (unless lispdir
+    (setq lispdir (getenv "lispdir")))
+  (when (and lispdir (file-directory-p lispdir))
+    (setq lispdir (file-truename (directory-file-name lispdir)))
+    (let ((indices '("gnus.elc" "gnus.el" "gnus.el.bz2" "gnus.el.gz"
+                    "message.elc" "message.el" "message.el.bz2"
+                    "message.el.gz"))
+         (path (delq nil (mapcar
+                          (lambda (p)
+                            (condition-case nil
+                                (when (and p (file-directory-p p))
+                                  (file-truename (directory-file-name p)))
+                              (error nil)))
+                          dgnushack-default-load-path)))
+         rest elcs)
+      (while path
+       (setq rest (cons (car path) rest)
+             path (delete (car rest) (cdr path))))
+      (setq path (nreverse (cdr (member lispdir rest)))
+           rest nil)
+      (while path
+       (setq elcs indices)
+       (while elcs
+         (when (file-exists-p (expand-file-name (pop elcs) (car path)))
+           (setq rest (cons (car path) rest)
+                 elcs nil)))
+       (setq path (cdr path)))
+      (prog1
+         (setq path (nreverse rest))
+       (when path
+         (let (print-level print-length)
+           (princ (concat "\n\
+WARNING: The other Gnus installation" (if (cdr path) "s have" " has") "\
+ been detected in:\n\n  " (mapconcat 'identity path "\n  ") "\n\n\
+You will need to modify the run-time `load-path', remove them manually,
+or remove them using `make remove-installed-shadows'.\n\n"))))))))
+
+(defun dgnushack-remove-lisp-shadows (&optional lispdir)
+  "Remove the other Gnus installations which shadow the recent one."
+  (let ((path (with-temp-buffer
+               (let ((standard-output (current-buffer)))
+                 (dgnushack-find-lisp-shadows lispdir))))
+       elcs files shadows file)
+    (when path
+      (unless (setq elcs (directory-files srcdir nil "\\.elc\\'"))
+       (error "You should build .elc files first."))
+      (setq files
+           (apply
+            'append
+            (mapcar
+             (lambda (el)
+               (list (concat el "c") el (concat el ".bz2") (concat el ".gz")))
+             (append
+              (list (file-name-nondirectory dgnushack-gnus-load-file)
+                    (file-name-nondirectory dgnushack-cus-load-file))
+              (mapcar (lambda (elc) (substring elc 0 -1)) elcs)))))
+      (while path
+       (setq shadows files)
+       (while shadows
+         (setq file (expand-file-name (pop shadows) (car path)))
+         (when (file-exists-p file)
+           (princ (concat "  Removing " file "..."))
+           (condition-case nil
+               (progn
+                 (delete-file file)
+                 (princ "done\n"))
+             (error (princ "failed\n")))))
+       (setq path (cdr path))))))
+
 ;;; dgnushack.el ends here
 
 ;;; arch-tag: 579f585a-24eb-4e1c-8d34-4808e11b68f2