T-gnus 6.15.10 revision 00.
[elisp/gnus.git-] / lisp / dgnushack.el
index b7c55fa..67f7510 100644 (file)
@@ -1,5 +1,5 @@
 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
-;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
 ;;        Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 
 (defvar srcdir (or (getenv "srcdir") "."))
 
-(let ((urldir (getenv "URLDIR")))
-  (unless (zerop (length urldir))
-    (push (file-name-as-directory urldir) load-path)))
-
 (defvar dgnushack-w3-directory (let ((w3dir (getenv "W3DIR")))
                                 (unless (zerop (length w3dir))
                                   (file-name-as-directory w3dir))))
-(when dgnushack-w3-directory
-  (push dgnushack-w3-directory load-path))
+
+(let ((urldir (getenv "URLDIR")))
+  (unless (zerop (length urldir))
+    (setq urldir (file-name-as-directory urldir))
+    (push (file-name-as-directory urldir) load-path))
+  (when (and dgnushack-w3-directory
+            (not (string-equal urldir dgnushack-w3-directory)))
+    (push dgnushack-w3-directory load-path)))
 
 ;; If we are building w3 in a different directory than the source
 ;; directory, we must read *.el from source directory and write *.elc
        (t (concat filename ".elc"))))
 
 (require 'bytecomp)
+;; To avoid having defsubsts and inlines happen.
+;(if (featurep 'xemacs)
+;    (require 'byte-optimize)
+;  (require 'byte-opt))
+;(defun byte-optimize-inline-handler (form)
+;  "byte-optimize-handler for the `inline' special-form."
+;  (cons 'progn (cdr form)))
+;(defalias 'byte-compile-file-form-defsubst 'byte-compile-file-form-defun)
 
-(unless (fboundp 'si:byte-optimize-form-code-walker)
-  (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
-  (setq max-specpdl-size 3000)
-  (defalias 'si:byte-optimize-form-code-walker
-    (symbol-function 'byte-optimize-form-code-walker))
-  (defun byte-optimize-form-code-walker (form for-effect)
+(when (boundp 'MULE)
+  (let (current-load-list)
+    ;; Make the function to be silent at compile-time.
+    (defun locate-library (library &optional nosuffix)
+      "Show the full path name of Emacs library LIBRARY.
+This command searches the directories in `load-path' like `M-x load-library'
+to find the file that `M-x load-library RET LIBRARY RET' would load.
+Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
+to the specified name LIBRARY (a la calling `load' instead of `load-library')."
+      (interactive "sLocate library: ")
+      (catch 'answer
+       (mapcar
+        '(lambda (dir)
+           (mapcar
+            '(lambda (suf)
+               (let ((try (expand-file-name (concat library suf) dir)))
+                 (and (file-readable-p try)
+                      (null (file-directory-p try))
+                      (progn
+                        (or noninteractive
+                            (message "Library is file %s" try))
+                        (throw 'answer try)))))
+            (if nosuffix '("") '(".elc" ".el" ""))))
+        load-path)
+       (or noninteractive
+           (message "No library %s in search path" library))
+       nil))
+    (byte-compile 'locate-library)))
+
+(setq max-specpdl-size 3000)
+
+(when (equal
+       (cadr
+       (byte-optimize-form
+        '(and
+          (< 0 1)
+          (message "The subform `(< 0 1)' should be optimized to `t'"))
+        'for-effect))
+       '(< 0 1))
+  (defadvice byte-optimize-form-code-walker
+    (around fix-bug-in-and/or-forms (form for-effect) activate)
+    "Fix a bug in the optimizing and/or forms.
+It has already been fixed in XEmacs since 1999-12-06."
     (if (and for-effect (memq (car-safe form) '(and or)))
-       ;; Fix bug in and/or forms.
        (let ((fn (car form))
              (backwards (reverse (cdr form))))
          (while (and backwards
          (if (and (cdr form) (null backwards))
              (byte-compile-log
               "  all subforms of %s called for effect; deleted" form))
-         (if backwards
-             (let ((head backwards))
-               (while (setq backwards (cdr backwards))
-                 (setcar backwards (byte-optimize-form (car backwards)
-                                                       nil)))
-               (cons fn (nreverse head)))))
-      (si:byte-optimize-form-code-walker form for-effect)))
-  (byte-compile 'byte-optimize-form-code-walker))
+         (when backwards
+           (setcdr backwards
+                   (mapcar 'byte-optimize-form (cdr backwards))))
+         (setq ad-return-value (cons fn (nreverse backwards))))
+      ad-do-it)))
 
 (condition-case nil
     (char-after)
 
 ;; Don't load path-util until `char-after' and `char-before' have been
 ;; optimized because it requires `poe' and then modify the functions.
-(or (featurep 'path-util)
-    (load "apel/path-util"))
-(add-path "apel")
-(add-path "flim")
+
+;; 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 '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)))
+
+(unless (locate-library "mel")
+  (add-path "flim"))
 (unless (module-installed-p 'mel)
   ;; FLIM 1.14 may have installed in two "flim" subdirectories.
   (push (expand-file-name "flim"
        load-path)
   (unless (module-installed-p 'mel)
     (error "
-FLIM package does not found in %s.
+FLIM modules does not found in %s.
 Try to re-configure with --with-addpath=FLIM_PATH and run make again.
 "
-          (progn
-            (add-path "semi")
-            load-path))))
+          load-path)))
 (add-path "semi")
 
 (push srcdir load-path)
@@ -163,6 +237,14 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
 
 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
 
+(when (boundp 'MULE)
+  ;; Bind the function `base64-encode-string' before loading canlock.
+  ;; Since canlock will bind it as an autoloaded function, it causes
+  ;; damage to define the function by MEL.
+  (load (expand-file-name "base64.el" srcdir) nil t t)
+  ;; Load special macros for compiling canlock.el.
+  (load (expand-file-name "canlock-om.el" srcdir) nil t t))
+
 (require 'custom)
 
 ;; Bind functions defined by `defun-maybe'.
@@ -176,35 +258,6 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
                  byte-compile-function-environment)))
   form)
 
-(when (boundp 'MULE)
-  (let (current-load-list)
-    ;; Make the function to be silent at compile-time.
-    (defun locate-library (library &optional nosuffix)
-      "Show the full path name of Emacs library LIBRARY.
-This command searches the directories in `load-path' like `M-x load-library'
-to find the file that `M-x load-library RET LIBRARY RET' would load.
-Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
-to the specified name LIBRARY (a la calling `load' instead of `load-library')."
-      (interactive "sLocate library: ")
-      (catch 'answer
-       (mapcar
-        '(lambda (dir)
-           (mapcar
-            '(lambda (suf)
-               (let ((try (expand-file-name (concat library suf) dir)))
-                 (and (file-readable-p try)
-                      (null (file-directory-p try))
-                      (progn
-                        (or noninteractive
-                            (message "Library is file %s" try))
-                        (throw 'answer try)))))
-            (if nosuffix '("") '(".elc" ".el" ""))))
-        load-path)
-       (or noninteractive
-           (message "No library %s in search path" library))
-       nil))
-    (byte-compile 'locate-library)))
-
 (condition-case nil
     :symbol-for-testing-whether-colon-keyword-is-available-or-not
   (void-variable
@@ -292,23 +345,23 @@ to the specified name LIBRARY (a la calling `load' instead of `load-library')."
                 (while (setq form (condition-case nil
                                       (read buffer)
                                     (error nil)))
-                  (while form
-                    (setq elem (pop form))
-                    (unless (memq (car-safe elem)
-                                  '(\` backquote defcustom defgroup
-                                    define-widget quote
-                                    widget-convert-button
-                                    widget-create widget-put))
-                      (while (consp elem)
-                        (push (car elem) form)
-                        (setq elem (cdr elem)))
-                      (when (and elem
-                                 (symbolp elem)
-                                 (not (eq ': elem))
-                                 (eq ?: (aref (symbol-name elem) 0))
-                                 (not (memq elem ignores))
-                                 (not (memq elem keywords)))
-                        (push elem keywords)))))))
+                  (when (listp form)
+                    (while form
+                      (setq elem (car-safe form)
+                            form (cdr-safe form))
+                      (unless (memq (car-safe elem)
+                                    '(defcustom defface defgroup
+                                      define-widget quote))
+                        (while (consp elem)
+                          (push (car elem) form)
+                          (setq elem (cdr elem)))
+                        (when (and elem
+                                   (symbolp elem)
+                                   (not (eq ': elem))
+                                   (eq ?: (aref (symbol-name elem) 0))
+                                   (not (memq elem ignores))
+                                   (not (memq elem keywords)))
+                          (push elem keywords))))))))
             (setq keywords (sort keywords
                                  (lambda (a b)
                                    (string-lessp (symbol-name a)
@@ -327,17 +380,16 @@ to the specified name LIBRARY (a la calling `load' instead of `load-library')."
    (byte-compile 'dgnushack-bind-colon-keywords)
    (dgnushack-bind-colon-keywords)))
 
-(if (boundp 'MULE)
-    (progn
-      (setq :version ':version
-           :set-after ':set-after)
-      (require 'custom)
-      (defadvice custom-handle-keyword
-       (around dont-signal-an-error-even-if-unsupported-keyword-is-given
-               activate)
-       "Don't signal an error even if unsupported keyword is given."
-       (if (not (memq (ad-get-arg 1) '(:version :set-after)))
-           ad-do-it))))
+(when (boundp 'MULE)
+  (setq :version ':version
+       :set-after ':set-after)
+  (require 'custom)
+  (defadvice custom-handle-keyword
+    (around dont-signal-an-error-even-if-unsupported-keyword-is-given
+           activate)
+    "Don't signal an error even if unsupported keyword is given."
+    (if (not (memq (ad-get-arg 1) '(:version :set-after)))
+       ad-do-it)))
 
 (when (boundp 'MULE)
   (put 'custom-declare-face 'byte-optimizer
@@ -382,7 +434,18 @@ to the specified name LIBRARY (a la calling `load' instead of `load-library')."
                                                     (car (cdr args))))))
              (setq args (cdr (cdr args))))
            newform)
-       form))))
+       form)))
+
+  (defadvice byte-compile-inline-expand (around ignore-built-in-functions
+                                               (form) activate)
+    "Ignore built-in functions."
+    (let* ((name (car form))
+          (fn (and (fboundp name)
+                   (symbol-function name))))
+      (if (subrp fn)
+         ;; Give up on inlining.
+         (setq ad-return-value form)
+       ad-do-it))))
 
 ;; Unknown variables and functions.
 (unless (boundp 'buffer-file-coding-system)
@@ -400,11 +463,17 @@ to the specified name LIBRARY (a la calling `load' instead of `load-library')."
 
 (defconst dgnushack-unexporting-files
   (append '("dgnushack.el" "dgnuspath.el" "dgnuskwds.el" "lpath.el")
+         (condition-case nil
+             (progn (require 'shimbun) nil)
+           (error '("nnshimbun.el")))
          (unless (or (condition-case code
-                         (require 'w3-forms)
+                         (require 'w3-parse)
                        (error
-                        (message "No w3: %s %s retrying..." code
-                                 (locate-library "w3-forms"))
+                        (message "No w3: %s%s, retrying..."
+                                 (error-message-string code)
+                                 (if (setq code (locate-library "w3-parse"))
+                                     (concat " (" code ")")
+                                   ""))
                         nil))
                      ;; Maybe mis-configured Makefile is used (e.g.
                      ;; configured for FSFmacs but XEmacs is running).
@@ -412,33 +481,57 @@ to the specified name LIBRARY (a la calling `load' instead of `load-library')."
                                        (copy-sequence load-path))))
                        (if (let ((load-path lp))
                              (condition-case nil
-                                 (require 'w3-forms)
+                                 (require 'w3-parse)
                                (error nil)))
                            ;; If success, fix `load-path' for compiling.
                            (progn
                              (setq load-path lp)
                              (message " => fixed; W3DIR=%s"
                                       (file-name-directory
-                                       (locate-library "w3-forms")))
+                                       (locate-library "w3-parse")))
                              t)
                          (message " => ignored")
                          nil)))
-           '("nnweb.el" "nnlistserv.el" "nnultimate.el"
-             "nnslashdot.el" "nnwarchive.el" "webmail.el"
-             "nnwfm.el" "nnrss.el"))
-         (condition-case nil
+           '("nnultimate.el" "webmail.el" "nnwfm.el"))
+         (condition-case code
+             (progn (require 'mh-e) nil)
+           (error
+            (message "No mh-e: %s%s (ignored)"
+                     (error-message-string code)
+                     (if (setq code (locate-library "mh-e"))
+                         (concat " (" code ")")
+                       ""))
+            '("gnus-mh.el")))
+         (condition-case code
+             (progn (require 'xml) nil)
+           (error
+            (message "No xml: %s%s (ignored)"
+                     (error-message-string code)
+                     (if (setq code (locate-library "xml"))
+                         (concat " (" code ")")
+                       ""))
+            '("nnrss.el")))
+         (condition-case code
              (progn (require 'bbdb) nil)
-           (error '("gnus-bbdb.el")))
+           (error
+            (message "No bbdb: %s%s (ignored)"
+                     (error-message-string code)
+                     (if (setq code (locate-library "bbdb"))
+                         (concat " (" code ")")
+                       ""))
+            '("gnus-bbdb.el")))
          (unless (featurep 'xemacs)
-           '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
-             "nnheaderxm.el" "smiley.el"))
-         (when (or (featurep 'xemacs) (<= emacs-major-version 20))
-           '("smiley-ems.el"))
+           '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el"))
+         (when (and (not (featurep 'xemacs))
+                    (<= emacs-major-version 20))
+           '("smiley.el"))
          (when (and (fboundp 'base64-decode-string)
                     (subrp (symbol-function 'base64-decode-string)))
            '("base64.el"))
          (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
-           '("md5.el")))
+           '("md5.el"))
+         (unless (boundp 'MULE)
+           '("canlock-om.el")))
   "Files which will not be installed.")
 
 (defconst dgnushack-exporting-files
@@ -452,6 +545,12 @@ to the specified name LIBRARY (a la calling `load' instead of `load-library')."
   "Print name of files which will be installed."
   (princ (mapconcat 'identity dgnushack-exporting-files " ")))
 
+(defconst dgnushack-dont-compile-files
+  '("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")
+  "Files which should not be byte-compiled.")
+
 (defun dgnushack-compile (&optional warn)
   ;;(setq byte-compile-dynamic t)
   (unless warn
@@ -477,20 +576,22 @@ Modify to suit your needs."))
               (file-newer-than-file-p file elc))
       (delete-file elc)))
 
+  ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
+  ;; installed.
+  (when (featurep 'xemacs)
+    (setq gnus-xmas-glyph-directory "dummy"))
+
   (let ((files dgnushack-exporting-files)
        ;;(byte-compile-generate-call-tree t)
        file elc)
-    ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
-    ;; installed.
-    (when (featurep 'xemacs)
-      (setq gnus-xmas-glyph-directory "dummy"))
     (while (setq file (pop files))
-      (setq file (expand-file-name file srcdir))
-      (when (or (not (file-exists-p
-                     (setq elc (concat (file-name-nondirectory file) "c"))))
-               (file-newer-than-file-p file elc))
-       (ignore-errors
-         (byte-compile-file file))))))
+      (unless (member file dgnushack-dont-compile-files)
+       (setq file (expand-file-name file srcdir))
+       (when (or (not (file-exists-p
+                       (setq elc (concat (file-name-nondirectory file) "c"))))
+                 (file-newer-than-file-p file elc))
+         (ignore-errors
+           (byte-compile-file file)))))))
 
 (defun dgnushack-recompile ()
   (require 'gnus)
@@ -511,6 +612,20 @@ Modify to suit your needs."))
 
 (defun dgnushack-make-auto-load ()
   (require 'autoload)
+  (unless (make-autoload '(define-derived-mode child parent name
+                           "docstring" body)
+                        "file")
+    (defadvice make-autoload (around handle-define-derived-mode activate)
+      "Handle `define-derived-mode'."
+      (if (eq (car-safe (ad-get-arg 0)) 'define-derived-mode)
+         (setq ad-return-value
+               (list 'autoload
+                     (list 'quote (nth 1 (ad-get-arg 0)))
+                     (ad-get-arg 1)
+                     (nth 4 (ad-get-arg 0))
+                     t nil))
+       ad-do-it))
+    (put 'define-derived-mode 'doc-string-elt 3))
   (let ((generated-autoload-file dgnushack-gnus-load-file)
        (make-backup-files nil)
        (autoload-package-name "gnus"))
@@ -595,7 +710,19 @@ Modify to suit your needs."))
 ;;; no-byte-compile: t
 ;;; no-update-autoloads: t
 ;;; End:
-;;; gnus-load.el ends here\n"))
+;;; gnus-load.el ends here
+")
+    ;; Workaround the bug in some version of XEmacs.
+    (when (featurep 'xemacs)
+      (condition-case nil
+         (require 'cus-load)
+       (error nil))
+      (goto-char (point-min))
+      (when (and (fboundp 'custom-add-loads)
+                (not (search-forward "\n(autoload 'custom-add-loads " nil t)))
+       (search-forward "\n;;; Code:" nil t)
+       (forward-line 1)
+       (insert "\n(autoload 'custom-add-loads \"cus-load\")\n"))))
   (message (format "Compiling %s..." dgnushack-gnus-load-file))
   (byte-compile-file dgnushack-gnus-load-file))