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