Synch to No Gnus 200510042243.
[elisp/gnus.git-] / lisp / dgnushack.el
index 0debd8a..476b612 100644 (file)
@@ -1,5 +1,6 @@
 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
-;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
+;; 2004, 2005
 ;;        Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
@@ -21,8 +22,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -44,6 +45,8 @@
                          (copy-sequence coding-category-list))
                    '(coding-category-sjis))))))
 
+(defvar dgnushack-default-load-path (copy-sequence load-path))
+
 (defalias 'facep 'ignore)
 
 (require 'cl)
 
 (when (and (not (featurep 'xemacs))
           (= emacs-major-version 21)
-          (= emacs-minor-version 3)
+          (>= emacs-minor-version 3)
           (condition-case code
               (let ((byte-compile-error-on-warn t))
                 (byte-optimize-form (quote (pop x)) t)
@@ -158,21 +161,22 @@ fixed in Emacs after 21.3."
          (setq ad-return-value (cons fn (nreverse backwards))))
       ad-do-it)))
 
-;; Add `early-package-load-path' to `load-path' for XEmacs.  Those paths
+;; Add `configure-package-path' to `load-path' for XEmacs.  Those paths
 ;; won't appear in `load-path' when XEmacs starts with the `-no-autoloads'
-;; option because of a bug. :<
+;; option or the `-vanilla' option because of a bug. :<
 (when (and (featurep 'xemacs)
-          (string-match "--package-path=\\([^ ]+\\)"
-                        system-configuration-options))
+          (boundp 'configure-package-path)
+          (listp configure-package-path))
   (let ((paths
         (apply 'nconc
                (mapcar
                 (lambda (path)
-                  (when (file-directory-p
-                         (setq path (expand-file-name "lisp" path)))
+                  (when (and (stringp path)
+                             (not (string-equal path ""))
+                             (file-directory-p
+                              (setq path (expand-file-name "lisp" path))))
                     (directory-files path t)))
-                (split-string (match-string 1 system-configuration-options)
-                              "::"))))
+                configure-package-path)))
        path adds)
     (while paths
       (setq path (car paths)
@@ -186,50 +190,33 @@ fixed in Emacs after 21.3."
     (setq load-path (nconc (nreverse adds) load-path))))
 
 (if (file-exists-p (expand-file-name "dgnuspath.el" srcdir))
-    (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
-  (message "  ** There's no dgnuspath.el file"))
+    (load (expand-file-name "dgnuspath.el" srcdir) nil nil t))
 
 (condition-case err
     (load "~/.lpath.el" t nil t)
   (error (message "Error in \"~/.lpath.el\" file: %s" err)))
 
+(when (featurep 'xemacs)
+  (condition-case nil
+      (require 'timer-funcs)
+    (error "
+You should upgrade your XEmacs packages, especially xemacs-base.\n"))
+
+  ;; The reason that to load `advice' is necessary is:
+  ;; 1. `path-util' loads poe.elc.
+  ;; 2. poe.elc requires the `ad-add-advice' function which is expanded
+  ;;    from `defadvice'.
+  ;; 3. XEmacs is running with the -no-autoloads option.
+  (require 'advice))
+
 ;; Don't load path-util until `char-after' and `char-before' have been
 ;; optimized because it requires `poe' and then modify the functions.
-
-;; If the APEL modules are installed under the non-standard directory,
-;; for example "/var/home/john/lisp/apel-VERSION/", you should add that
-;; name using the configure option "--with-addpath=".
-;; And also the directory where the EMU modules are installed, for
-;; example "/usr/local/share/mule/19.34/site-lisp/", it should be
-;; included in the standard `load-path' or added by the configure
-;; option "--with-addpath=".
-(let ((path (or (locate-library "path-util")
-               (locate-library "apel/path-util")));; backward compat.
-      parent lpath)
-  (if path
-      (progn
-       (when (string-match "/$" (setq path (file-name-directory path)))
-         (setq path (substring path 0 (match-beginning 0))))
-       ;; path == "/var/home/john/lisp/apel-VERSION"
-       (when (string-match "/$" (setq parent (file-name-directory path)))
-         (setq parent (substring path 0 (match-beginning 0))))
-       ;; parent == "/var/home/john/lisp"
-       (if (setq lpath (or (member path load-path)
-                           (member (file-name-as-directory path) load-path)))
-           (unless (or (member parent load-path)
-                       (member (file-name-as-directory parent) load-path))
-             (push parent (cdr lpath)))
-         (push path load-path)
-         (unless (or (member parent load-path)
-                     (member (file-name-as-directory parent) load-path))
-           (push parent (cdr load-path))))
-       (require 'advice)
-       (require 'path-util))
-    (error "
-APEL modules are not found in %s.
-Try to re-configure with --with-addpath=APEL_PATH and run make again.
-"
-          load-path)))
+(condition-case nil
+    (require 'path-util)
+  (error "\nIn %s,
+APEL was not found or an error occurred.  You will need to run the
+configure script again adding the --with-addpath=APEL_PATH option.\n"
+        load-path))
 
 (unless (locate-library "mel")
   (add-path "flim"))
@@ -239,10 +226,9 @@ Try to re-configure with --with-addpath=APEL_PATH and run make again.
                          (file-name-directory (get-latest-path "^apel$" t)))
        load-path)
   (unless (module-installed-p 'mel)
-    (error "
-FLIM modules does not found in %s.
-Try to re-configure with --with-addpath=FLIM_PATH and run make again.
-"
+    (error "In %s,
+FLIM was not found.  You will need to run the configure script again
+adding the --with-addpath=FLIM_PATH option.\n"
           load-path)))
 (add-path "semi")
 
@@ -310,6 +296,7 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
     (autoload 'c-mode "cc-mode" nil t)
     (autoload 'customize-apropos "cus-edit" nil t)
     (autoload 'customize-save-variable "cus-edit" nil t)
+    (autoload 'customize-set-variable "cus-edit" nil t)
     (autoload 'customize-variable "cus-edit" nil t)
     (autoload 'delete-annotation "annotations")
     (autoload 'dolist "cl-macs" nil nil 'macro)
@@ -317,6 +304,8 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
     (autoload 'executable-find "executable")
     (autoload 'font-lock-fontify-buffer "font-lock" nil t)
     (autoload 'info "info" nil t)
+    (autoload 'mail-extract-address-components "mail-extr")
+    (autoload 'mail-fetch-field "mail-utils")
     (autoload 'make-annotation "annotations")
     (autoload 'make-display-table "disp-table")
     (autoload 'pp "pp")
@@ -326,10 +315,13 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
     (autoload 'read-passwd "passwd")
     (autoload 'regexp-opt "regexp-opt")
     (autoload 'reporter-submit-bug-report "reporter")
-    (if (emacs-version>= 21 5)
+    (if (and (emacs-version>= 21 5)
+            (not (featurep 'sxemacs)))
        (autoload 'setenv "process" nil t)
       (autoload 'setenv "env" nil t))
     (autoload 'sgml-mode "psgml" nil t)
+    (autoload 'sha1 "sha1")
+    (autoload 'sha1-binary "sha1")
     (autoload 'smtpmail-send-it "smtpmail")
     (autoload 'sort-numeric-fields "sort" nil t)
     (autoload 'sort-subr "sort")
@@ -348,7 +340,6 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
     (defalias 'overlays-in 'ignore)
     (defalias 'replace-dehighlight 'ignore)
     (defalias 'replace-highlight 'ignore)
-    (defalias 'run-with-idle-timer 'ignore)
     (defalias 'w3-coding-system-for-mime-charset 'ignore)))
 
 ;; T-gnus stuff.
@@ -422,8 +413,7 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
                        ""))
             '("gnus-bbdb.el")))
          (unless (featurep 'xemacs)
-           '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el"
-             "run-at-time.el"))
+           '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el"))
          (when (and (fboundp 'base64-decode-string)
                     (subrp (symbol-function 'base64-decode-string)))
            '("base64.el"))
@@ -447,8 +437,8 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
 (defconst dgnushack-dont-compile-files
   '("gnus-load.el"
     "mm-bodies.el" "mm-decode.el" "mm-encode.el" "mm-extern.el"
-    "mm-partial.el" "mm-url.el" "mm-uu.el" "mm-view.el" "mml-sec.el"
-    "mml-smime.el" "mml.el" "mml1991.el" "mml2015.el")
+    "mm-partial.el" "mm-uu.el" "mm-view.el" "mml-sec.el" "mml-smime.el"
+    "mml.el" "mml1991.el" "mml2015.el")
   "Files which should not be byte-compiled.")
 
 (defun dgnushack-compile-verbosely ()
@@ -689,21 +679,99 @@ dgnushack-compile."
                                     t)
                    'string-lessp))
        (while (setq file (pop files))
-         (insert "info/" file "\n"))))))
-
-\f
-(define-compiler-macro describe-key-briefly (&whole form key &optional insert)
-  (if (condition-case nil
-         (progn
-           (describe-key-briefly '((())) nil)
-           t)
-       (wrong-number-of-arguments nil);; Old Emacsen.
-       (error t))
-      form
-    (if insert
-       `(if ,insert
-            (insert (funcall 'describe-key-briefly ,key))
-          (funcall 'describe-key-briefly ,key))
-      `(funcall 'describe-key-briefly ,key))))
+         (insert "info/" file "\n"))
+       (insert "etc/gnus-tut.txt\n")
+       (setq files
+             (sort (directory-files "../etc/images/gnus/" nil
+                                    "\\.\\(pbm\\|xbm\\|xpm\\)\\'"
+                                    t)
+                   'string-lessp))
+       (while (setq file (pop files))
+         (insert "etc/images/gnus/" file "\n"))
+       (insert "etc/images/gnus/x-splash\n")
+       (setq files
+             (sort (directory-files "../etc/images/smilies/" nil
+                                    "\\.\\(pbm\\|xpm\\)\\'"
+                                    t)
+                   'string-lessp))
+       (while (setq file (pop files))
+         (insert "etc/images/smilies/" file "\n"))))))
+
+(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