Synch with Oort Gnus.
[elisp/gnus.git-] / lisp / dgnushack.el
1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;      Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Version: 4.19
8 ;; Keywords: news, path
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 ;; Set coding priority of Shift-JIS to the bottom.
32 (if (featurep 'xemacs)
33     (defalias 'set-coding-priority 'ignore)
34   (defalias 'coding-priority-list 'ignore)
35   (defalias 'set-coding-priority-list 'ignore))
36 (cond ((and (featurep 'xemacs) (featurep 'mule))
37        (if (memq 'shift-jis (coding-priority-list))
38            (set-coding-priority-list
39             (append (delq 'shift-jis (coding-priority-list)) '(shift-jis)))))
40       ((boundp 'MULE)
41        (put '*coding-category-sjis* 'priority (length *predefined-category*)))
42       ((featurep 'mule)
43        (if (memq 'coding-category-sjis coding-category-list)
44            (set-coding-priority
45             (append (delq 'coding-category-sjis
46                           (copy-sequence coding-category-list))
47                     '(coding-category-sjis))))))
48
49 (defalias 'facep 'ignore)
50
51 (require 'cl)
52 (unless (dolist (var nil t))
53   ;; Override the macro `dolist' which may have been defined in egg.el.
54   (load "cl-macs" nil t))
55
56 (defvar srcdir (or (getenv "srcdir") "."))
57
58 (defvar dgnushack-w3-directory (let ((w3dir (getenv "W3DIR")))
59                                  (unless (zerop (length w3dir))
60                                    (file-name-as-directory w3dir))))
61
62 (let ((urldir (getenv "URLDIR")))
63   (unless (zerop (length urldir))
64     (setq urldir (file-name-as-directory urldir))
65     (push (file-name-as-directory urldir) load-path))
66   (when (and dgnushack-w3-directory
67              (not (string-equal urldir dgnushack-w3-directory)))
68     (push dgnushack-w3-directory load-path)))
69
70 ;; If we are building w3 in a different directory than the source
71 ;; directory, we must read *.el from source directory and write *.elc
72 ;; into the building directory.  For that, we define this function
73 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
74 (defun byte-compile-dest-file (filename)
75   "Convert an Emacs Lisp source file name to a compiled file name.
76  In addition, remove directory name part from FILENAME."
77   (setq filename (byte-compiler-base-file-name filename))
78   (setq filename (file-name-sans-versions filename))
79   (setq filename (file-name-nondirectory filename))
80   (if (memq system-type '(win32 w32 mswindows windows-nt))
81       (setq filename (downcase filename)))
82   (cond ((eq system-type 'vax-vms)
83          (concat (substring filename 0 (string-match ";" filename)) "c"))
84         ((string-match emacs-lisp-file-regexp filename)
85          (concat (substring filename 0 (match-beginning 0)) ".elc"))
86         (t (concat filename ".elc"))))
87
88 (require 'bytecomp)
89
90 (when (boundp 'MULE)
91   (let (current-load-list)
92     ;; Make the function to be silent at compile-time.
93     (defun locate-library (library &optional nosuffix)
94       "Show the full path name of Emacs library LIBRARY.
95 This command searches the directories in `load-path' like `M-x load-library'
96 to find the file that `M-x load-library RET LIBRARY RET' would load.
97 Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
98 to the specified name LIBRARY (a la calling `load' instead of `load-library')."
99       (interactive "sLocate library: ")
100       (catch 'answer
101         (mapcar
102          '(lambda (dir)
103             (mapcar
104              '(lambda (suf)
105                 (let ((try (expand-file-name (concat library suf) dir)))
106                   (and (file-readable-p try)
107                        (null (file-directory-p try))
108                        (progn
109                          (or noninteractive
110                              (message "Library is file %s" try))
111                          (throw 'answer try)))))
112              (if nosuffix '("") '(".elc" ".el" ""))))
113          load-path)
114         (or noninteractive
115             (message "No library %s in search path" library))
116         nil))
117     (byte-compile 'locate-library)))
118
119 (unless (fboundp 'si:byte-optimize-form-code-walker)
120   (byte-optimize-form nil);; Load `byte-opt' or `byte-optimize'.
121   (setq max-specpdl-size 3000)
122   (defalias 'si:byte-optimize-form-code-walker
123     (symbol-function 'byte-optimize-form-code-walker))
124   (defun byte-optimize-form-code-walker (form for-effect)
125     (if (and for-effect (memq (car-safe form) '(and or)))
126         ;; Fix bug in and/or forms.
127         (let ((fn (car form))
128               (backwards (reverse (cdr form))))
129           (while (and backwards
130                       (null (setcar backwards
131                                     (byte-optimize-form (car backwards) t))))
132             (setq backwards (cdr backwards)))
133           (if (and (cdr form) (null backwards))
134               (byte-compile-log
135                "  all subforms of %s called for effect; deleted" form))
136           (if backwards
137               (let ((head backwards))
138                 (while (setq backwards (cdr backwards))
139                   (setcar backwards (byte-optimize-form (car backwards)
140                                                         nil)))
141                 (cons fn (nreverse head)))))
142       (si:byte-optimize-form-code-walker form for-effect)))
143   (byte-compile 'byte-optimize-form-code-walker))
144
145 (condition-case nil
146     (char-after)
147   (wrong-number-of-arguments
148    ;; Optimize byte code for `char-after'.
149    (put 'char-after 'byte-optimizer 'byte-optimize-char-after)
150    (defun byte-optimize-char-after (form)
151      (if (null (cdr form))
152          '(char-after (point))
153        form))))
154
155 (condition-case nil
156     (char-before)
157   (wrong-number-of-arguments
158    ;; Optimize byte code for `char-before'.
159    (put 'char-before 'byte-optimizer 'byte-optimize-char-before)
160    (defun byte-optimize-char-before (form)
161      (if (null (cdr form))
162          '(char-before (point))
163        form))))
164
165 (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
166
167 (condition-case err
168     (load "~/.lpath.el" t nil t)
169   (error (message "Error in \"~/.lpath.el\" file: %s" err)))
170
171 ;; Don't load path-util until `char-after' and `char-before' have been
172 ;; optimized because it requires `poe' and then modify the functions.
173
174 ;; If the APEL modules are installed under the non-standard directory,
175 ;; for example "/var/home/john/lisp/apel-VERSION/", you should add that
176 ;; name using the configure option "--with-addpath=".
177 ;; And also the directory where the EMU modules are installed, for
178 ;; example "/usr/local/share/mule/19.34/site-lisp/", it should be
179 ;; included in the standard `load-path' or added by the configure
180 ;; option "--with-addpath=".
181 (let ((path (or (locate-library "path-util")
182                 (locate-library "apel/path-util")));; backward compat.
183       parent lpath)
184   (if path
185       (progn
186         (when (string-match "/$" (setq path (file-name-directory path)))
187           (setq path (substring path 0 (match-beginning 0))))
188         ;; path == "/var/home/john/lisp/apel-VERSION"
189         (when (string-match "/$" (setq parent (file-name-directory path)))
190           (setq parent (substring path 0 (match-beginning 0))))
191         ;; parent == "/var/home/john/lisp"
192         (if (setq lpath (or (member path load-path)
193                             (member (file-name-as-directory path) load-path)))
194             (unless (or (member parent load-path)
195                         (member (file-name-as-directory parent) load-path))
196               (push parent (cdr lpath)))
197           (push path load-path)
198           (unless (or (member parent load-path)
199                       (member (file-name-as-directory parent) load-path))
200             (push parent (cdr load-path))))
201         (require 'path-util))
202     (error "
203 APEL modules are not found in %s.
204 Try to re-configure with --with-addpath=APEL_PATH and run make again.
205 "
206            load-path)))
207
208 (unless (locate-library "mel")
209   (add-path "flim"))
210 (unless (module-installed-p 'mel)
211   ;; FLIM 1.14 may have installed in two "flim" subdirectories.
212   (push (expand-file-name "flim"
213                           (file-name-directory (get-latest-path "^apel$" t)))
214         load-path)
215   (unless (module-installed-p 'mel)
216     (error "
217 FLIM modules does not found in %s.
218 Try to re-configure with --with-addpath=FLIM_PATH and run make again.
219 "
220            load-path)))
221 (add-path "semi")
222
223 (push srcdir load-path)
224 (load (expand-file-name "lpath.el" srcdir) nil t t)
225
226 (load (expand-file-name "gnus-clfns.el" srcdir) nil t t)
227
228 (require 'custom)
229
230 ;; Bind functions defined by `defun-maybe'.
231 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
232 (defun byte-compile-file-form-defun-maybe (form)
233   (if (and (not (fboundp (nth 1 form)))
234            (memq 'unresolved byte-compile-warnings))
235       (setq byte-compile-function-environment
236             (cons (cons (nth 1 form)
237                         (cons 'lambda (cdr (cdr form))))
238                   byte-compile-function-environment)))
239   form)
240
241 (condition-case nil
242     :symbol-for-testing-whether-colon-keyword-is-available-or-not
243   (void-variable
244    (defun dgnushack-bind-colon-keywords ()
245      "Bind all the colon keywords for old Emacsen."
246      (let ((cache (expand-file-name "dgnuskwds.el" srcdir))
247            (makefile (expand-file-name "Makefile" srcdir))
248            (buffer (get-buffer-create " *colon keywords*"))
249            keywords ignores files file dirs dir form elem make-backup-files)
250        (save-excursion
251          (set-buffer buffer)
252          (let (buffer-file-format
253                format-alist
254                insert-file-contents-post-hook
255                insert-file-contents-pre-hook
256                jam-zcat-filename-list
257                jka-compr-compression-info-list)
258            (if (and (file-exists-p cache)
259                     (file-exists-p makefile)
260                     (file-newer-than-file-p cache makefile))
261                (progn
262                  (insert-file-contents cache nil nil nil t)
263                  (setq keywords (read buffer)))
264              (setq
265               ignores
266               '(:symbol-for-testing-whether-colon-keyword-is-available-or-not
267                 ;; The following keywords will be bound by CUSTOM.
268                 :get :group :initialize :link :load :options :prefix
269                 :require :set :tag :type)
270               files (list (locate-library "semi-def")
271                           (locate-library "mailcap")
272                           (locate-library "mime-def")
273                           (locate-library "path-util")
274                           (locate-library "poem"))
275               dirs (list (file-name-as-directory (expand-file-name srcdir))))
276              (while files
277                (when (setq file (pop files))
278                  (setq dir (file-name-directory file))
279                  (unless (member dir dirs)
280                    (push dir dirs))))
281              (message "Searching for all the colon keywords in:")
282              (while dirs
283                (setq dir (pop dirs))
284                (message " %s..." dir)
285                (setq files (directory-files dir t
286                                             "\\.el\\(\\.gz\\|\\.bz2\\)?$"))
287                (while files
288                  (setq file (pop files))
289                  (if (string-match "\\(\\.gz$\\)\\|\\.bz2$" file)
290                      (let ((temp (expand-file-name "dgnustemp.el" srcdir)))
291                        (when
292                            (let* ((binary (if (boundp 'MULE)
293                                               '*noconv*
294                                             'binary))
295                                   (coding-system-for-read binary)
296                                   (coding-system-for-write binary)
297                                   (input-coding-system binary)
298                                   (output-coding-system binary)
299                                   (default-process-coding-system
300                                     (cons binary binary))
301                                   call-process-hook)
302                              (insert-file-contents file nil nil nil t)
303                              (when
304                                  (condition-case code
305                                      (progn
306                                        (if (match-beginning 1)
307                                            (call-process-region
308                                             (point-min) (point-max)
309                                             "gzip" t buffer nil "-cd")
310                                          (call-process-region
311                                           (point-min) (point-max)
312                                           "bzip2" t buffer nil "-d"))
313                                        t)
314                                    (error
315                                     (erase-buffer)
316                                     (message "In file %s: %s" file code)
317                                     nil))
318                                (write-region (point-min) (point-max) temp
319                                              nil 'silent)
320                                t))
321                          (unwind-protect
322                              (insert-file-contents temp nil nil nil t)
323                            (delete-file temp))))
324                    (insert-file-contents file nil nil nil t))
325                  (while (setq form (condition-case nil
326                                        (read buffer)
327                                      (error nil)))
328                    (while form
329                      (setq elem (pop form))
330                      (unless (memq (car-safe elem)
331                                    '(\` backquote
332                                      defcustom defface defgroup
333                                      define-widget quote))
334                        (while (consp elem)
335                          (push (car elem) form)
336                          (setq elem (cdr elem)))
337                        (when (and elem
338                                   (symbolp elem)
339                                   (not (eq ': elem))
340                                   (eq ?: (aref (symbol-name elem) 0))
341                                   (not (memq elem ignores))
342                                   (not (memq elem keywords)))
343                          (push elem keywords)))))))
344              (setq keywords (sort keywords
345                                   (lambda (a b)
346                                     (string-lessp (symbol-name a)
347                                                   (symbol-name b)))))
348              (erase-buffer)
349              (insert (format "%s" keywords))
350              (write-region (point-min) (point) cache nil 'silent)
351              (message
352               "The following colon keywords will be bound at run-time:\n %s"
353               keywords))))
354        (kill-buffer buffer)
355        (defconst dgnushack-colon-keywords keywords)
356        (while keywords
357          (set (car keywords) (car keywords))
358          (setq keywords (cdr keywords)))))
359    (byte-compile 'dgnushack-bind-colon-keywords)
360    (dgnushack-bind-colon-keywords)))
361
362 (if (boundp 'MULE)
363     (progn
364       (setq :version ':version
365             :set-after ':set-after)
366       (require 'custom)
367       (defadvice custom-handle-keyword
368         (around dont-signal-an-error-even-if-unsupported-keyword-is-given
369                 activate)
370         "Don't signal an error even if unsupported keyword is given."
371         (if (not (memq (ad-get-arg 1) '(:version :set-after)))
372             ad-do-it))))
373
374 (when (boundp 'MULE)
375   (put 'custom-declare-face 'byte-optimizer
376        'byte-optimize-ignore-unsupported-custom-keywords)
377   (put 'custom-declare-group 'byte-optimizer
378        'byte-optimize-ignore-unsupported-custom-keywords)
379   (defun byte-optimize-ignore-unsupported-custom-keywords (form)
380     (if (or (memq ':version (nthcdr 4 form))
381             (memq ':set-after (nthcdr 4 form)))
382         (let ((newform (list (car form) (nth 1 form)
383                              (nth 2 form) (nth 3 form)))
384               (args (nthcdr 4 form)))
385           (while args
386             (or (memq (car args) '(:version :set-after))
387                 (setq newform (nconc newform (list (car args)
388                                                    (car (cdr args))))))
389             (setq args (cdr (cdr args))))
390           newform)
391       form))
392
393   (put 'custom-declare-variable 'byte-hunk-handler
394        'byte-compile-file-form-custom-declare-variable)
395   (defun byte-compile-file-form-custom-declare-variable (form)
396     ;; Bind defcustom'ed variables.
397     (if (memq 'free-vars byte-compile-warnings)
398         (setq byte-compile-bound-variables
399               (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
400     (if (memq ':version (nthcdr 4 form))
401         ;; Make the variable uncustomizable.
402         `(defvar ,(nth 1 (nth 1 form)) ,(nth 1 (nth 2 form))
403            ,(substring (nth 3 form) (if (string-match "^[\t *]+" (nth 3 form))
404                                         (match-end 0)
405                                       0)))
406       ;; Ignore unsupported keyword(s).
407       (if (memq ':set-after (nthcdr 4 form))
408           (let ((newform (list (car form) (nth 1 form)
409                                (nth 2 form) (nth 3 form)))
410                 (args (nthcdr 4 form)))
411             (while args
412               (or (eq (car args) ':set-after)
413                   (setq newform (nconc newform (list (car args)
414                                                      (car (cdr args))))))
415               (setq args (cdr (cdr args))))
416             newform)
417         form))))
418
419 ;; Unknown variables and functions.
420 (unless (boundp 'buffer-file-coding-system)
421   (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
422 (unless (featurep 'xemacs)
423   (defalias 'Custom-make-dependencies 'ignore)
424   (defalias 'update-autoloads-from-directory 'ignore))
425
426 (defalias 'device-sound-enabled-p 'ignore)
427 (defalias 'play-sound-file 'ignore)
428 (defalias 'nndb-request-article 'ignore)
429 (defalias 'efs-re-read-dir 'ignore)
430 (defalias 'ange-ftp-re-read-dir 'ignore)
431 (defalias 'define-mail-user-agent 'ignore)
432
433 (defconst dgnushack-unexporting-files
434   (append '("dgnushack.el" "dgnuspath.el" "dgnuskwds.el" "lpath.el")
435           (condition-case nil
436               (progn (require 'shimbun) nil)
437             (error '("nnshimbun.el")))
438           (unless (or (condition-case code
439                           (require 'w3-forms)
440                         (error
441                          (message "No w3: %s %s retrying..." code
442                                   (locate-library "w3-forms"))
443                          nil))
444                       ;; Maybe mis-configured Makefile is used (e.g.
445                       ;; configured for FSFmacs but XEmacs is running).
446                       (let ((lp (delete dgnushack-w3-directory
447                                         (copy-sequence load-path))))
448                         (if (let ((load-path lp))
449                               (condition-case nil
450                                   (require 'w3-forms)
451                                 (error nil)))
452                             ;; If success, fix `load-path' for compiling.
453                             (progn
454                               (setq load-path lp)
455                               (message " => fixed; W3DIR=%s"
456                                        (file-name-directory
457                                         (locate-library "w3-forms")))
458                               t)
459                           (message " => ignored")
460                           nil)))
461             '("nnweb.el" "nnlistserv.el" "nnultimate.el"
462               "nnslashdot.el" "nnwarchive.el" "webmail.el"
463               "nnwfm.el" "nnrss.el"))
464           (condition-case code
465               (progn (require 'mh-e) nil)
466             (error
467              (message "No mh-e: %s %s (ignored)" code (locate-library "mh-e"))
468              '("gnus-mh.el")))
469           (condition-case code
470               (progn (require 'xml) nil)
471             (error
472              (message "No xml: %s %s (ignored)" code (locate-library "xml"))
473              '("nnrss.el")))
474           (condition-case code
475               (progn (require 'bbdb) nil)
476             (error
477              (message "No bbdb: %s %s (ignored)" code (locate-library "bbdb"))
478              '("gnus-bbdb.el")))
479           (unless (featurep 'xemacs)
480             '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
481               "nnheaderxm.el" "smiley.el"))
482           (when (or (featurep 'xemacs) (<= emacs-major-version 20))
483             '("smiley-ems.el"))
484           (when (and (fboundp 'base64-decode-string)
485                      (subrp (symbol-function 'base64-decode-string)))
486             '("base64.el"))
487           (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
488             '("md5.el")))
489   "Files which will not be installed.")
490
491 (defconst dgnushack-exporting-files
492   (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
493     (dolist (file dgnushack-unexporting-files)
494       (setq files (delete file files)))
495     (sort files 'string-lessp))
496   "Files which will be compiled and installed.")
497
498 (defun dgnushack-exporting-files ()
499   "Print name of files which will be installed."
500   (princ (mapconcat 'identity dgnushack-exporting-files " ")))
501
502 (defun dgnushack-compile (&optional warn)
503   ;;(setq byte-compile-dynamic t)
504   (unless warn
505     (setq byte-compile-warnings
506           '(free-vars unresolved callargs redefine)))
507   (unless (locate-library "cus-edit")
508     (error "You do not seem to have Custom installed.
509 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
510 You also then need to add the following to the lisp/dgnushack.el file:
511
512      (push \"~/lisp/custom\" load-path)
513
514 Modify to suit your needs."))
515
516   ;; Show `load-path'.
517   (message "load-path=(\"%s\")"
518            (mapconcat 'identity load-path "\"\n           \""))
519
520   (dolist (file dgnushack-exporting-files)
521     (setq file (expand-file-name file srcdir))
522     (when (and (file-exists-p
523                 (setq elc (concat (file-name-nondirectory file) "c")))
524                (file-newer-than-file-p file elc))
525       (delete-file elc)))
526
527   (let ((files dgnushack-exporting-files)
528         ;;(byte-compile-generate-call-tree t)
529         file elc)
530     ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
531     ;; installed.
532     (when (featurep 'xemacs)
533       (setq gnus-xmas-glyph-directory "dummy"))
534     (while (setq file (pop files))
535       (setq file (expand-file-name file srcdir))
536       (when (or (not (file-exists-p
537                       (setq elc (concat (file-name-nondirectory file) "c"))))
538                 (file-newer-than-file-p file elc))
539         (ignore-errors
540           (byte-compile-file file))))))
541
542 (defun dgnushack-recompile ()
543   (require 'gnus)
544   (byte-recompile-directory "." 0))
545
546 (defvar dgnushack-gnus-load-file (expand-file-name "gnus-load.el" srcdir))
547 (defvar dgnushack-cus-load-file (expand-file-name "cus-load.el" srcdir))
548 (defvar dgnushack-auto-load-file (expand-file-name "auto-autoloads.el" srcdir))
549
550 (defun dgnushack-make-cus-load ()
551   (when (condition-case nil
552             (load "cus-dep")
553           (error nil))
554     (let ((cusload-base-file dgnushack-cus-load-file))
555       (if (fboundp 'custom-make-dependencies)
556           (custom-make-dependencies)
557         (Custom-make-dependencies)))))
558
559 (defun dgnushack-make-auto-load ()
560   (require 'autoload)
561   (unless (make-autoload '(define-derived-mode child parent name
562                             "docstring" body)
563                          "file")
564     (defadvice make-autoload (around handle-define-derived-mode activate)
565       "Handle `define-derived-mode'."
566       (if (eq (car-safe (ad-get-arg 0)) 'define-derived-mode)
567           (setq ad-return-value
568                 (list 'autoload
569                       (list 'quote (nth 1 (ad-get-arg 0)))
570                       (ad-get-arg 1)
571                       (nth 4 (ad-get-arg 0))
572                       t nil))
573         ad-do-it))
574     (put 'define-derived-mode 'doc-string-elt 3))
575   (let ((generated-autoload-file dgnushack-gnus-load-file)
576         (make-backup-files nil)
577         (autoload-package-name "gnus"))
578     (if (featurep 'xemacs)
579         (progn
580           (if (file-exists-p generated-autoload-file)
581               (delete-file generated-autoload-file))
582           (if (file-exists-p dgnushack-auto-load-file)
583               (delete-file dgnushack-auto-load-file)))
584       (with-temp-file generated-autoload-file
585         (insert ?\014)))
586     (if (featurep 'xemacs)
587         (let ((si:message (symbol-function 'message)))
588           (defun message (fmt &rest args)
589             (cond ((and (string-equal "Generating autoloads for %s..." fmt)
590                         (file-exists-p (file-name-nondirectory (car args))))
591                    (funcall si:message
592                             fmt (file-name-nondirectory (car args))))
593                   ((string-equal "No autoloads found in %s" fmt))
594                   ((string-equal "Generating autoloads for %s...done" fmt))
595                   (t (apply si:message fmt args))))
596           (unwind-protect
597               (batch-update-autoloads)
598             (fset 'message si:message)))
599       (batch-update-autoloads))))
600
601 (defun dgnushack-make-load ()
602   (message (format "Generating %s..." dgnushack-gnus-load-file))
603   (with-temp-file dgnushack-gnus-load-file
604     (if (file-exists-p dgnushack-cus-load-file)
605         (progn
606           (insert-file-contents dgnushack-cus-load-file)
607           (delete-file dgnushack-cus-load-file)
608           (goto-char (point-min))
609           (search-forward ";;; Code:")
610           (forward-line)
611           (delete-region (point-min) (point))
612           (unless (re-search-forward "\
613 ^[\t ]*(autoload[\t\n ]+\\('\\|(quote[\t\n ]+\\)custom-add-loads[\t\n ]"
614                                      nil t)
615             (insert "\n(autoload 'custom-add-loads \"cus-load\")\n"))
616           (goto-char (point-min))
617           (insert "\
618 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
619 ;;
620 ;;; Code:
621 ")
622           (goto-char (point-max))
623           (if (search-backward "custom-versions-load-alist" nil t)
624               (forward-line -1)
625             (forward-line -1)
626             (while (eq (char-after) ?\;)
627               (forward-line -1))
628             (forward-line))
629           (delete-region (point) (point-max))
630           (insert "\n"))
631       (insert "\
632 ;;; gnus-load.el --- automatically extracted autoload
633 ;;
634 ;;; Code:
635 "))
636     ;; smiley-* are duplicated. Remove them all.
637     (let ((point (point)))
638       (insert-file-contents dgnushack-gnus-load-file)
639       (goto-char point)
640       (while (search-forward "smiley-" nil t)
641         (beginning-of-line)
642         (if (looking-at "(autoload ")
643             (delete-region (point) (progn (forward-sexp) (point)))
644           (forward-line))))
645     ;;
646     (goto-char (point-max))
647     (when (search-backward "\n(provide " nil t)
648       (forward-line -1)
649       (delete-region (point) (point-max)))
650     (insert "\
651
652 \(provide 'gnus-load)
653
654 ;;; Local Variables:
655 ;;; version-control: never
656 ;;; no-byte-compile: t
657 ;;; no-update-autoloads: t
658 ;;; End:
659 ;;; gnus-load.el ends here\n"))
660   (message (format "Compiling %s..." dgnushack-gnus-load-file))
661   (byte-compile-file dgnushack-gnus-load-file))
662
663 \f
664 (defun dgnushack-compose-package ()
665   "Re-split the file gnus-load.el into custom-load.el and
666 auto-autoloads.el.  It is silly, should be improved!"
667   (message "
668 Re-splitting gnus-load.el into custom-load.el and auto-autoloads.el...")
669   (let ((customload (expand-file-name "custom-load.el" srcdir))
670         (autoloads (expand-file-name "auto-autoloads.el" srcdir))
671         start)
672     (with-temp-buffer
673       (insert-file-contents dgnushack-gnus-load-file)
674       (delete-file dgnushack-gnus-load-file)
675       (when (file-exists-p (concat dgnushack-gnus-load-file "c"))
676         (delete-file (concat dgnushack-gnus-load-file "c")))
677       (while (prog1
678                  (looking-at "[\t ;]")
679                (forward-line 1)))
680       (setq start (point))
681       (insert "\
682 ;;; custom-load.el --- automatically extracted custom dependencies\n
683 ;;; Code:\n\n")
684       (goto-char (point-max))
685       (while (progn
686                (forward-line -1)
687                (not (looking-at "[\t ]*(custom-add-loads[\t\n ]"))))
688       (forward-list 1)
689       (forward-line 1)
690       (insert "\n;;; custom-load.el ends here\n")
691       (write-region start (point) customload)
692       (while (looking-at "[\t ]*$")
693         (forward-line 1))
694       (setq start (point))
695       (if (re-search-forward "^[\t\n ]*(if[\t\n ]+(featurep[\t\n ]" nil t)
696           (let ((from (goto-char (match-beginning 0))))
697             (delete-region from (progn
698                                   (forward-list 1)
699                                   (forward-line 1)
700                                   (point))))
701         (while (looking-at "[\t ;]")
702           (forward-line 1)))
703       (insert "(if (featurep 'gnus-autoloads) (error \"Already loaded\"))\n")
704       (goto-char (point-max))
705       (while (progn
706                (forward-line -1)
707                (not (looking-at "[\t ]*(provide[\t\n ]"))))
708       (insert "(provide 'gnus-autoloads)\n")
709       (write-region start (point) autoloads))
710     (byte-compile-file customload)
711     (byte-compile-file autoloads))
712   (message "\
713 Re-splitting gnus-load.el into custom-load.el and auto-autoloads.el...done
714 \n"))
715
716 \f
717 (defconst dgnushack-info-file-regexp-en
718   (let ((names '("gnus" "message" "emacs-mime"))
719         regexp name)
720     (while (setq name (pop names))
721       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
722                            (when names "\\|"))))
723     regexp)
724   "Regexp matching English info files.")
725
726 (defconst dgnushack-info-file-regexp-ja
727   (let ((names '("gnus-ja" "message-ja"))
728         regexp name)
729     (while (setq name (pop names))
730       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
731                            (when names "\\|"))))
732     regexp)
733   "Regexp matching Japanese info files.")
734
735 (defun dgnushack-remove-extra-files-in-package ()
736   "Remove extra files in the lisp directory of the XEmacs package."
737   (let ((lisp-dir (expand-file-name (concat "lisp/"
738                                             ;; GNUS_PRODUCT_NAME
739                                             (cadr command-line-args-left)
740                                             "/")
741                                     ;; PACKAGEDIR
742                                     (car command-line-args-left))))
743     (when (file-directory-p lisp-dir)
744       (let (files)
745         (dolist (file dgnushack-exporting-files)
746           (setq files (nconc files (list file (concat file "c")))))
747         (dolist (file (directory-files lisp-dir nil nil t t))
748           (unless (member file files)
749             (setq file (expand-file-name file lisp-dir))
750             (message "Removing %s..." file)
751             (condition-case nil
752                 (delete-file file)
753               (error nil))))))))
754
755 (defun dgnushack-install-package-manifest ()
756   "Install MANIFEST file as an XEmacs package."
757   (let* ((package-dir (car command-line-args-left))
758          (product-name (cadr command-line-args-left))
759          (name (expand-file-name (concat "pkginfo/MANIFEST." product-name)
760                                  package-dir))
761          make-backup-files)
762     (message "Generating %s..." name)
763     (with-temp-file name
764       (insert "pkginfo/MANIFEST." product-name "\n")
765       (let ((lisp-dir (concat "lisp/" product-name "/"))
766             (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
767             file)
768         (while (setq file (pop files))
769           (unless (member file dgnushack-unexporting-files)
770             (insert lisp-dir file "\n")))
771         (setq files
772               (sort (directory-files "../texi/" nil
773                                      (concat dgnushack-info-file-regexp-en
774                                              "\\|"
775                                              dgnushack-info-file-regexp-ja)
776                                      t)
777                     'string-lessp))
778         (while (setq file (pop files))
779           (insert "info/" file "\n"))))))
780
781 \f
782 (define-compiler-macro describe-key-briefly (&whole form key &optional insert)
783   (if (condition-case nil
784           (progn
785             (describe-key-briefly '((())) nil)
786             t)
787         (wrong-number-of-arguments nil);; Old Emacsen.
788         (error t))
789       form
790     (if insert
791         `(if ,insert
792              (insert (funcall 'describe-key-briefly ,key))
793            (funcall 'describe-key-briefly ,key))
794       `(funcall 'describe-key-briefly ,key))))
795
796 ;;; dgnushack.el ends here