Synch with Oort Gnus.
[elisp/gnus.git-] / lisp / dgnushack.el
index 5fab698..f7d7796 100644 (file)
 (defalias 'facep 'ignore)
 
 (require 'cl)
+(unless (dolist (var nil t))
+  ;; Override the macro `dolist' which may have been defined in egg.el.
+  (load "cl-macs" nil t))
 
 (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
 
 (require 'bytecomp)
 
+(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)))
+
 (unless (fboundp 'si:byte-optimize-form-code-walker)
   (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
   (setq max-specpdl-size 3000)
       (si:byte-optimize-form-code-walker form for-effect)))
   (byte-compile 'byte-optimize-form-code-walker))
 
-(load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
-
 (condition-case nil
     (char-after)
   (wrong-number-of-arguments
 
 ;; 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)
 (load (expand-file-name "lpath.el" srcdir) nil t t)
 
+(load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
+
 (require 'custom)
 
 ;; Bind functions defined by `defun-maybe'.
@@ -176,17 +241,124 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
 (condition-case nil
     :symbol-for-testing-whether-colon-keyword-is-available-or-not
   (void-variable
-   ;; Bind keywords.
-   (dolist (keyword '(:button-keymap :data :file :mime-handle
-                                    :key-type :value-type
-                                    :ascent :foreground :help))
-     (set keyword keyword))))
-
-;; If you are using Mule 2.3 based on Emacs 19.34, you may also put the
-;; following lines in your .emacs file, before gnus related modules are
-;; loaded.  It is not always necessary.  However if it is done, you will
-;; be able to load or evaluate gnus related *.el (not compiled) files.
-;; ------ cut here ------ cut here ------ cut here ------ cut here ------
+   (defun dgnushack-bind-colon-keywords ()
+     "Bind all the colon keywords for old Emacsen."
+     (let ((cache (expand-file-name "dgnuskwds.el" srcdir))
+          (makefile (expand-file-name "Makefile" srcdir))
+          (buffer (get-buffer-create " *colon keywords*"))
+          keywords ignores files file dirs dir form elem make-backup-files)
+       (save-excursion
+        (set-buffer buffer)
+        (let (buffer-file-format
+              format-alist
+              insert-file-contents-post-hook
+              insert-file-contents-pre-hook
+              jam-zcat-filename-list
+              jka-compr-compression-info-list)
+          (if (and (file-exists-p cache)
+                   (file-exists-p makefile)
+                   (file-newer-than-file-p cache makefile))
+              (progn
+                (insert-file-contents cache nil nil nil t)
+                (setq keywords (read buffer)))
+            (setq
+             ignores
+             '(:symbol-for-testing-whether-colon-keyword-is-available-or-not
+               ;; The following keywords will be bound by CUSTOM.
+               :get :group :initialize :link :load :options :prefix
+               :require :set :tag :type)
+             files (list (locate-library "semi-def")
+                         (locate-library "mailcap")
+                         (locate-library "mime-def")
+                         (locate-library "path-util")
+                         (locate-library "poem"))
+             dirs (list (file-name-as-directory (expand-file-name srcdir))))
+            (while files
+              (when (setq file (pop files))
+                (setq dir (file-name-directory file))
+                (unless (member dir dirs)
+                  (push dir dirs))))
+            (message "Searching for all the colon keywords in:")
+            (while dirs
+              (setq dir (pop dirs))
+              (message " %s..." dir)
+              (setq files (directory-files dir t
+                                           "\\.el\\(\\.gz\\|\\.bz2\\)?$"))
+              (while files
+                (setq file (pop files))
+                (if (string-match "\\(\\.gz$\\)\\|\\.bz2$" file)
+                    (let ((temp (expand-file-name "dgnustemp.el" srcdir)))
+                      (when
+                          (let* ((binary (if (boundp 'MULE)
+                                             '*noconv*
+                                           'binary))
+                                 (coding-system-for-read binary)
+                                 (coding-system-for-write binary)
+                                 (input-coding-system binary)
+                                 (output-coding-system binary)
+                                 (default-process-coding-system
+                                   (cons binary binary))
+                                 call-process-hook)
+                            (insert-file-contents file nil nil nil t)
+                            (when
+                                (condition-case code
+                                    (progn
+                                      (if (match-beginning 1)
+                                          (call-process-region
+                                           (point-min) (point-max)
+                                           "gzip" t buffer nil "-cd")
+                                        (call-process-region
+                                         (point-min) (point-max)
+                                         "bzip2" t buffer nil "-d"))
+                                      t)
+                                  (error
+                                   (erase-buffer)
+                                   (message "In file %s: %s" file code)
+                                   nil))
+                              (write-region (point-min) (point-max) temp
+                                            nil 'silent)
+                              t))
+                        (unwind-protect
+                            (insert-file-contents temp nil nil nil t)
+                          (delete-file temp))))
+                  (insert-file-contents file nil nil nil t))
+                (while (setq form (condition-case nil
+                                      (read buffer)
+                                    (error nil)))
+                  (while form
+                    (setq elem (pop form))
+                    (unless (memq (car-safe elem)
+                                  '(\` backquote
+                                    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)
+                                                 (symbol-name b)))))
+            (erase-buffer)
+            (insert (format "%s" keywords))
+            (write-region (point-min) (point) cache nil 'silent)
+            (message
+             "The following colon keywords will be bound at run-time:\n %s"
+             keywords))))
+       (kill-buffer buffer)
+       (defconst dgnushack-colon-keywords keywords)
+       (while keywords
+        (set (car keywords) (car keywords))
+        (setq keywords (cdr keywords)))))
+   (byte-compile 'dgnushack-bind-colon-keywords)
+   (dgnushack-bind-colon-keywords)))
+
 (if (boundp 'MULE)
     (progn
       (setq :version ':version
@@ -198,7 +370,6 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
        "Don't signal an error even if unsupported keyword is given."
        (if (not (memq (ad-get-arg 1) '(:version :set-after)))
            ad-do-it))))
-;; ------ cut here ------ cut here ------ cut here ------ cut here ------
 
 (when (boundp 'MULE)
   (put 'custom-declare-face 'byte-optimizer
@@ -260,7 +431,10 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
 (defalias 'define-mail-user-agent 'ignore)
 
 (defconst dgnushack-unexporting-files
-  (append '("dgnushack.el" "dgnuspath.el" "lpath.el")
+  (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)
                        (error
@@ -286,10 +460,22 @@ Try to re-configure with --with-addpath=FLIM_PATH and run make again.
                          nil)))
            '("nnweb.el" "nnlistserv.el" "nnultimate.el"
              "nnslashdot.el" "nnwarchive.el" "webmail.el"
-             "nnwfm.el"))
-         (condition-case nil
+             "nnwfm.el" "nnrss.el"))
+         (condition-case code
+             (progn (require 'mh-e) nil)
+           (error
+            (message "No mh-e: %s %s (ignored)" code (locate-library "mh-e"))
+            '("gnus-mh.el")))
+         (condition-case code
+             (progn (require 'xml) nil)
+           (error
+            (message "No xml: %s %s (ignored)" code (locate-library "xml"))
+            '("nnrss.el")))
+         (condition-case code
              (progn (require 'bbdb) nil)
-           (error '("gnus-bbdb.el")))
+           (error
+            (message "No bbdb: %s %s (ignored)" code (locate-library "bbdb"))
+            '("gnus-bbdb.el")))
          (unless (featurep 'xemacs)
            '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
              "nnheaderxm.el" "smiley.el"))
@@ -372,6 +558,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"))
@@ -409,6 +609,11 @@ Modify to suit your needs."))
          (search-forward ";;; Code:")
          (forward-line)
          (delete-region (point-min) (point))
+         (unless (re-search-forward "\
+^[\t ]*(autoload[\t\n ]+\\('\\|(quote[\t\n ]+\\)custom-add-loads[\t\n ]"
+                                    nil t)
+           (insert "\n(autoload 'custom-add-loads \"cus-load\")\n"))
+         (goto-char (point-min))
          (insert "\
 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
 ;;
@@ -456,6 +661,59 @@ Modify to suit your needs."))
   (byte-compile-file dgnushack-gnus-load-file))
 
 \f
+(defun dgnushack-compose-package ()
+  "Re-split the file gnus-load.el into custom-load.el and
+auto-autoloads.el.  It is silly, should be improved!"
+  (message "
+Re-splitting gnus-load.el into custom-load.el and auto-autoloads.el...")
+  (let ((customload (expand-file-name "custom-load.el" srcdir))
+       (autoloads (expand-file-name "auto-autoloads.el" srcdir))
+       start)
+    (with-temp-buffer
+      (insert-file-contents dgnushack-gnus-load-file)
+      (delete-file dgnushack-gnus-load-file)
+      (when (file-exists-p (concat dgnushack-gnus-load-file "c"))
+       (delete-file (concat dgnushack-gnus-load-file "c")))
+      (while (prog1
+                (looking-at "[\t ;]")
+              (forward-line 1)))
+      (setq start (point))
+      (insert "\
+;;; custom-load.el --- automatically extracted custom dependencies\n
+;;; Code:\n\n")
+      (goto-char (point-max))
+      (while (progn
+              (forward-line -1)
+              (not (looking-at "[\t ]*(custom-add-loads[\t\n ]"))))
+      (forward-list 1)
+      (forward-line 1)
+      (insert "\n;;; custom-load.el ends here\n")
+      (write-region start (point) customload)
+      (while (looking-at "[\t ]*$")
+       (forward-line 1))
+      (setq start (point))
+      (if (re-search-forward "^[\t\n ]*(if[\t\n ]+(featurep[\t\n ]" nil t)
+         (let ((from (goto-char (match-beginning 0))))
+           (delete-region from (progn
+                                 (forward-list 1)
+                                 (forward-line 1)
+                                 (point))))
+       (while (looking-at "[\t ;]")
+         (forward-line 1)))
+      (insert "(if (featurep 'gnus-autoloads) (error \"Already loaded\"))\n")
+      (goto-char (point-max))
+      (while (progn
+              (forward-line -1)
+              (not (looking-at "[\t ]*(provide[\t\n ]"))))
+      (insert "(provide 'gnus-autoloads)\n")
+      (write-region start (point) autoloads))
+    (byte-compile-file customload)
+    (byte-compile-file autoloads))
+  (message "\
+Re-splitting gnus-load.el into custom-load.el and auto-autoloads.el...done
+\n"))
+
+\f
 (defconst dgnushack-info-file-regexp-en
   (let ((names '("gnus" "message" "emacs-mime"))
        regexp name)