Synch to No Gnus 200402270146.
[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, 2002, 2003
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       ((featurep 'mule)
41        (if (memq 'coding-category-sjis coding-category-list)
42            (set-coding-priority
43             (append (delq 'coding-category-sjis
44                           (copy-sequence coding-category-list))
45                     '(coding-category-sjis))))))
46
47 (defalias 'facep 'ignore)
48
49 (require 'cl)
50
51 (unless (and
52          ;; `dolist' might not be available because of ``-no-autoloads''.
53          (fboundp 'dolist)
54          ;; It may have been defined in egg.el.
55          (dolist (var nil t)))
56   (load "cl-macs" nil t))
57
58 (defvar srcdir (or (getenv "srcdir") "."))
59
60 (defvar dgnushack-w3-directory (let ((w3dir (getenv "W3DIR")))
61                                  (unless (zerop (length w3dir))
62                                    (file-name-as-directory w3dir))))
63
64 (let ((urldir (getenv "URLDIR")))
65   (unless (zerop (length urldir))
66     (setq urldir (file-name-as-directory urldir))
67     (push (file-name-as-directory urldir) load-path))
68   (when (and dgnushack-w3-directory
69              (not (string-equal urldir dgnushack-w3-directory)))
70     (push dgnushack-w3-directory load-path)))
71
72 ;; If we are building w3 in a different directory than the source
73 ;; directory, we must read *.el from source directory and write *.elc
74 ;; into the building directory.  For that, we define this function
75 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
76 (defun byte-compile-dest-file (filename)
77   "Convert an Emacs Lisp source file name to a compiled file name.
78  In addition, remove directory name part from FILENAME."
79   (setq filename (byte-compiler-base-file-name filename))
80   (setq filename (file-name-sans-versions filename))
81   (setq filename (file-name-nondirectory filename))
82   (if (memq system-type '(win32 w32 mswindows windows-nt))
83       (setq filename (downcase filename)))
84   (cond ((eq system-type 'vax-vms)
85          (concat (substring filename 0 (string-match ";" filename)) "c"))
86         ((string-match emacs-lisp-file-regexp filename)
87          (concat (substring filename 0 (match-beginning 0)) ".elc"))
88         (t (concat filename ".elc"))))
89
90 (require 'bytecomp)
91 ;; To avoid having defsubsts and inlines happen.
92 ;(if (featurep 'xemacs)
93 ;    (require 'byte-optimize)
94 ;  (require 'byte-opt))
95 ;(defun byte-optimize-inline-handler (form)
96 ;  "byte-optimize-handler for the `inline' special-form."
97 ;  (cons 'progn (cdr form)))
98 ;(defalias 'byte-compile-file-form-defsubst 'byte-compile-file-form-defun)
99
100 (when (and (not (featurep 'xemacs))
101            (= emacs-major-version 21)
102            (= emacs-minor-version 3)
103            (condition-case code
104                (let ((byte-compile-error-on-warn t))
105                  (byte-optimize-form (quote (pop x)) t)
106                  nil)
107              (error (string-match "called for effect"
108                                   (error-message-string code)))))
109   (defadvice byte-optimize-form-code-walker (around silence-warn-for-pop
110                                                     (form for-effect)
111                                                     activate)
112     "Silence the warning \"...called for effect\" for the `pop' form.
113 It is effective only when the `pop' macro is defined by cl.el rather
114 than subr.el."
115     (let (tmp)
116       (if (and (eq (car-safe form) 'car)
117                for-effect
118                (setq tmp (get 'car 'side-effect-free))
119                (not byte-compile-delete-errors)
120                (not (eq tmp 'error-free))
121                (eq (car-safe (cadr form)) 'prog1)
122                (let ((var (cadr (cadr form)))
123                      (last (nth 2 (cadr form))))
124                  (and (symbolp var)
125                       (null (nthcdr 3 (cadr form)))
126                       (eq (car-safe last) 'setq)
127                       (eq (cadr last) var)
128                       (eq (car-safe (nth 2 last)) 'cdr)
129                       (eq (cadr (nth 2 last)) var))))
130           (progn
131             (put 'car 'side-effect-free 'error-free)
132             (unwind-protect
133                 ad-do-it
134               (put 'car 'side-effect-free tmp)))
135         ad-do-it))))
136
137 (when (and (not (featurep 'xemacs))
138            (byte-optimize-form '(and (> 0 1) foo) t))
139   (defadvice byte-optimize-form-code-walker
140     (around fix-bug-in-and/or-forms (form for-effect) activate)
141     "Optimize the rest of the and/or forms.
142 It has been fixed in XEmacs before releasing 21.4 and also has been
143 fixed in Emacs after 21.3."
144     (if (and for-effect (memq (car-safe form) '(and or)))
145         (let ((fn (car form))
146               (backwards (reverse (cdr form))))
147           (while (and backwards
148                       (null (setcar backwards
149                                     (byte-optimize-form (car backwards) t))))
150             (setq backwards (cdr backwards)))
151           (if (and (cdr form) (null backwards))
152               (byte-compile-log
153                "  all subforms of %s called for effect; deleted" form))
154           (when backwards
155             (setcdr backwards
156                     (mapcar 'byte-optimize-form (cdr backwards))))
157           (setq ad-return-value (cons fn (nreverse backwards))))
158       ad-do-it)))
159
160 ;; Add `early-package-load-path' to `load-path' for XEmacs.  Those paths
161 ;; won't appear in `load-path' when XEmacs starts with the `-no-autoloads'
162 ;; option because of a bug. :<
163 (when (and (featurep 'xemacs)
164            (string-match "--package-path=\\([^ ]+\\)"
165                          system-configuration-options))
166   (let ((paths
167          (apply 'nconc
168                 (mapcar
169                  (lambda (path)
170                    (when (file-directory-p
171                           (setq path (expand-file-name "lisp" path)))
172                      (directory-files path t)))
173                  (split-string (match-string 1 system-configuration-options)
174                                "::"))))
175         path adds)
176     (while paths
177       (setq path (car paths)
178             paths (cdr paths))
179       (when (and path
180                  (not (or (string-match "/\\.\\.?\\'" path)
181                           (member (file-name-as-directory path) load-path)
182                           (member path load-path)))
183                  (file-directory-p path))
184         (push (file-name-as-directory path) adds)))
185     (setq load-path (nconc (nreverse adds) load-path))))
186
187 (if (file-exists-p (expand-file-name "dgnuspath.el" srcdir))
188     (load (expand-file-name "dgnuspath.el" srcdir) nil nil t)
189   (message "  ** There's no dgnuspath.el file"))
190
191 (condition-case err
192     (load "~/.lpath.el" t nil t)
193   (error (message "Error in \"~/.lpath.el\" file: %s" err)))
194
195 ;; Don't load path-util until `char-after' and `char-before' have been
196 ;; optimized because it requires `poe' and then modify the functions.
197
198 ;; If the APEL modules are installed under the non-standard directory,
199 ;; for example "/var/home/john/lisp/apel-VERSION/", you should add that
200 ;; name using the configure option "--with-addpath=".
201 ;; And also the directory where the EMU modules are installed, for
202 ;; example "/usr/local/share/mule/19.34/site-lisp/", it should be
203 ;; included in the standard `load-path' or added by the configure
204 ;; option "--with-addpath=".
205 (let ((path (or (locate-library "path-util")
206                 (locate-library "apel/path-util")));; backward compat.
207       parent lpath)
208   (if path
209       (progn
210         (when (string-match "/$" (setq path (file-name-directory path)))
211           (setq path (substring path 0 (match-beginning 0))))
212         ;; path == "/var/home/john/lisp/apel-VERSION"
213         (when (string-match "/$" (setq parent (file-name-directory path)))
214           (setq parent (substring path 0 (match-beginning 0))))
215         ;; parent == "/var/home/john/lisp"
216         (if (setq lpath (or (member path load-path)
217                             (member (file-name-as-directory path) load-path)))
218             (unless (or (member parent load-path)
219                         (member (file-name-as-directory parent) load-path))
220               (push parent (cdr lpath)))
221           (push path load-path)
222           (unless (or (member parent load-path)
223                       (member (file-name-as-directory parent) load-path))
224             (push parent (cdr load-path))))
225         (require 'advice)
226         (require 'path-util))
227     (error "
228 APEL modules are not found in %s.
229 Try to re-configure with --with-addpath=APEL_PATH and run make again.
230 "
231            load-path)))
232
233 (unless (locate-library "mel")
234   (add-path "flim"))
235 (unless (module-installed-p 'mel)
236   ;; FLIM 1.14 may have installed in two "flim" subdirectories.
237   (push (expand-file-name "flim"
238                           (file-name-directory (get-latest-path "^apel$" t)))
239         load-path)
240   (unless (module-installed-p 'mel)
241     (error "
242 FLIM modules does not found in %s.
243 Try to re-configure with --with-addpath=FLIM_PATH and run make again.
244 "
245            load-path)))
246 (add-path "semi")
247
248 (when (and (featurep 'xemacs)
249            (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
250              (modify-syntax-entry ?= " " table)
251              (with-temp-buffer
252                (with-syntax-table table
253                  (insert "foo=bar")
254                  (goto-char (point-min))
255                  (forward-sexp 1)
256                  (eolp)))))
257   ;; The original `with-syntax-table' uses `copy-syntax-table' which
258   ;; doesn't seem to copy modified syntax entries in XEmacs 21.5.
259   (defmacro with-syntax-table (syntab &rest body)
260     "Evaluate BODY with the SYNTAB as the current syntax table."
261     `(let ((stab (syntax-table)))
262        (unwind-protect
263            (progn
264              ;;(set-syntax-table (copy-syntax-table ,syntab))
265              (set-syntax-table ,syntab)
266              ,@body)
267          (set-syntax-table stab)))))
268
269 (push srcdir load-path)
270 (load (expand-file-name "lpath.el" srcdir) nil t t)
271
272 (require 'custom)
273
274 ;; Bind functions defined by `defun-maybe'.
275 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
276 (defun byte-compile-file-form-defun-maybe (form)
277   (if (and (not (fboundp (nth 1 form)))
278            (memq 'unresolved byte-compile-warnings))
279       (setq byte-compile-function-environment
280             (cons (cons (nth 1 form)
281                         (cons 'lambda (cdr (cdr form))))
282                   byte-compile-function-environment)))
283   form)
284
285 ;; Unknown variables and functions.
286 (unless (featurep 'xemacs)
287   (defalias 'Custom-make-dependencies 'ignore)
288   (defalias 'update-autoloads-from-directory 'ignore))
289
290 (defalias 'device-sound-enabled-p 'ignore)
291 (defalias 'play-sound-file 'ignore)
292 (defalias 'nndb-request-article 'ignore)
293 (defalias 'efs-re-read-dir 'ignore)
294 (defalias 'ange-ftp-re-read-dir 'ignore)
295 (defalias 'define-mail-user-agent 'ignore)
296
297 (eval-and-compile
298   (when (featurep 'xemacs)
299     (unless (fboundp 'defadvice)
300       (autoload 'defadvice "advice" nil nil 'macro))
301     (autoload 'Info-directory "info" nil t)
302     (autoload 'Info-menu "info" nil t)
303     (autoload 'annotations-at "annotations")
304     (autoload 'apropos "apropos" nil t)
305     (autoload 'apropos-command "apropos" nil t)
306     (autoload 'bbdb-complete-name "bbdb-com" nil t)
307     (autoload 'browse-url "browse-url" nil t)
308     (autoload 'customize-apropos "cus-edit" nil t)
309     (autoload 'customize-save-variable "cus-edit" nil t)
310     (autoload 'customize-variable "cus-edit" nil t)
311     (autoload 'delete-annotation "annotations")
312     (autoload 'dolist "cl-macs" nil nil 'macro)
313     (autoload 'enriched-decode "enriched")
314     (autoload 'executable-find "executable")
315     (autoload 'font-lock-fontify-buffer "font-lock" nil t)
316     (autoload 'info "info" nil t)
317     (autoload 'make-annotation "annotations")
318     (autoload 'make-display-table "disp-table")
319     (autoload 'pp "pp")
320     (autoload 'ps-despool "ps-print" nil t)
321     (autoload 'ps-spool-buffer "ps-print" nil t)
322     (autoload 'ps-spool-buffer-with-faces "ps-print" nil t)
323     (autoload 'read-passwd "passwd")
324     (autoload 'regexp-opt "regexp-opt")
325     (autoload 'reporter-submit-bug-report "reporter")
326     (if (emacs-version>= 21 5)
327         (autoload 'setenv "process" nil t)
328       (autoload 'setenv "env" nil t))
329     (autoload 'smtpmail-send-it "smtpmail")
330     (autoload 'sort-numeric-fields "sort" nil t)
331     (autoload 'sort-subr "sort")
332     (autoload 'trace-function-background "trace" nil t)
333     (autoload 'w3-do-setup "w3")
334     (autoload 'w3-prepare-buffer "w3-display")
335     (autoload 'w3-region "w3-display" nil t)
336     (defalias 'frame-char-height 'frame-height)
337     (defalias 'frame-char-width 'frame-width)
338     (defalias 'frame-parameter 'frame-property)
339     (defalias 'make-overlay 'ignore)
340     (defalias 'overlay-end 'ignore)
341     (defalias 'overlay-get 'ignore)
342     (defalias 'overlay-put 'ignore)
343     (defalias 'overlay-start 'ignore)
344     (defalias 'overlays-in 'ignore)
345     (defalias 'replace-dehighlight 'ignore)
346     (defalias 'replace-highlight 'ignore)
347     (defalias 'run-with-idle-timer 'ignore)
348     (defalias 'w3-coding-system-for-mime-charset 'ignore)))
349
350 ;; T-gnus stuff.
351 (eval-and-compile
352   (when (featurep 'xemacs)
353     (autoload 'c-mode "cc-mode" nil t)
354     (autoload 'font-lock-mode "font-lock" nil t)
355     (autoload 'read-kbd-macro "edmacro" nil t)
356     (autoload 'turn-on-font-lock "font-lock" nil t))
357   (autoload 'nnheader-detect-coding-region "nnheader")
358   (autoload 'std11-extract-addresses-components "nnheader")
359   (autoload 'std11-fold-region "nnheader")
360   (autoload 'std11-narrow-to-field "nnheader")
361   (autoload 'std11-unfold-region "nnheader"))
362
363 (defconst dgnushack-unexporting-files
364   (append '("dgnushack.el" "dgnuspath.el" "dgnuskwds.el" "lpath.el")
365           (unless (or (condition-case code
366                           (require 'w3-parse)
367                         (error
368                          (message "No w3: %s%s, retrying..."
369                                   (error-message-string code)
370                                   (if (setq code (locate-library "w3-parse"))
371                                       (concat " (" code ")")
372                                     ""))
373                          nil))
374                       ;; Maybe mis-configured Makefile is used (e.g.
375                       ;; configured for FSFmacs but XEmacs is running).
376                       (let ((lp (delete dgnushack-w3-directory
377                                         (copy-sequence load-path))))
378                         (if (let ((load-path lp))
379                               (condition-case nil
380                                   (require 'w3-parse)
381                                 (error nil)))
382                             ;; If success, fix `load-path' for compiling.
383                             (progn
384                               (setq load-path lp)
385                               (message " => fixed; W3DIR=%s"
386                                        (file-name-directory
387                                         (locate-library "w3-parse")))
388                               t)
389                           (message " => ignored")
390                           nil)))
391             '("nnultimate.el" "webmail.el" "nnwfm.el"))
392           (condition-case code
393               (progn (require 'mh-e) nil)
394             (error
395              (message "No mh-e: %s%s (ignored)"
396                       (error-message-string code)
397                       (if (setq code (locate-library "mh-e"))
398                           (concat " (" code ")")
399                         ""))
400              '("gnus-mh.el")))
401           (condition-case code
402               (progn (require 'xml) nil)
403             (error
404              (message "No xml: %s%s (ignored)"
405                       (error-message-string code)
406                       (if (setq code (locate-library "xml"))
407                           (concat " (" code ")")
408                         ""))
409              '("nnrss.el")))
410           (condition-case code
411               (progn (require 'bbdb) nil)
412             (error
413              (message "No bbdb: %s%s (ignored)"
414                       (error-message-string code)
415                       (if (setq code (locate-library "bbdb"))
416                           (concat " (" code ")")
417                         ""))
418              '("gnus-bbdb.el")))
419           (unless (featurep 'xemacs)
420             '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el"
421               "run-at-time.el"))
422           (when (and (fboundp 'base64-decode-string)
423                      (subrp (symbol-function 'base64-decode-string)))
424             '("base64.el"))
425           (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
426             '("md5.el"))
427           (when (featurep 'xemacs)
428             '("gnus-load.el")))
429   "Files which will not be installed.")
430
431 (defconst dgnushack-exporting-files
432   (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
433     (dolist (file dgnushack-unexporting-files)
434       (setq files (delete file files)))
435     (sort files 'string-lessp))
436   "Files which will be compiled and installed.")
437
438 (defun dgnushack-exporting-files ()
439   "Print name of files which will be installed."
440   (princ (mapconcat 'identity dgnushack-exporting-files " ")))
441
442 (defconst dgnushack-dont-compile-files
443   '("gnus-load.el"
444     "mm-bodies.el" "mm-decode.el" "mm-encode.el" "mm-extern.el"
445     "mm-partial.el" "mm-url.el" "mm-uu.el" "mm-view.el" "mml-sec.el"
446     "mml-smime.el" "mml.el" "mml1991.el" "mml2015.el")
447   "Files which should not be byte-compiled.")
448
449 (defun dgnushack-compile-verbosely ()
450   "Call dgnushack-compile with warnings ENABLED.  If you are compiling
451 patches to gnus, you should consider modifying make.bat to call
452 dgnushack-compile-verbosely.  All other users should continue to use
453 dgnushack-compile."
454   (dgnushack-compile t))
455
456 (defun dgnushack-compile (&optional warn)
457   ;;(setq byte-compile-dynamic t)
458   (unless warn
459     (setq byte-compile-warnings
460           '(free-vars unresolved callargs redefine)))
461
462   ;; Show `load-path'.
463   (message "load-path=(\"%s\")"
464            (mapconcat 'identity load-path "\"\n           \""))
465
466   (dolist (file dgnushack-exporting-files)
467     (setq file (expand-file-name file srcdir))
468     (when (and (file-exists-p
469                 (setq elc (concat (file-name-nondirectory file) "c")))
470                (file-newer-than-file-p file elc))
471       (delete-file elc)))
472
473   ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
474   ;; installed.
475   (when (featurep 'xemacs)
476     (setq gnus-xmas-glyph-directory "dummy"))
477
478   (let ((files dgnushack-exporting-files)
479         ;;(byte-compile-generate-call-tree t)
480         file elc)
481     (while (setq file (pop files))
482       (unless (member file dgnushack-dont-compile-files)
483         (setq file (expand-file-name file srcdir))
484         (when (or (not (file-exists-p
485                         (setq elc (concat (file-name-nondirectory file) "c"))))
486                   (file-newer-than-file-p file elc))
487           (ignore-errors
488             (byte-compile-file file)))))))
489
490 (defun dgnushack-recompile ()
491   (require 'gnus)
492   (byte-recompile-directory "." 0))
493
494 (defvar dgnushack-gnus-load-file
495   (if (featurep 'xemacs)
496       (expand-file-name "auto-autoloads.el" srcdir)
497     (expand-file-name "gnus-load.el" srcdir)))
498
499 (defvar dgnushack-cus-load-file
500   (if (featurep 'xemacs)
501       (expand-file-name "custom-load.el" srcdir)
502     (expand-file-name "cus-load.el" srcdir)))
503
504 (defun dgnushack-make-cus-load ()
505   (load "cus-dep")
506   (let ((cusload-base-file dgnushack-cus-load-file))
507     (if (fboundp 'custom-make-dependencies)
508         (custom-make-dependencies)
509       (Custom-make-dependencies))
510     (when (featurep 'xemacs)
511       (message "Compiling %s..." dgnushack-cus-load-file)
512       (byte-compile-file dgnushack-cus-load-file))))
513
514 (defun dgnushack-make-auto-load ()
515   (require 'autoload)
516   (unless (make-autoload '(define-derived-mode child parent name
517                             "docstring" body)
518                          "file")
519     (defadvice make-autoload (around handle-define-derived-mode activate)
520       "Handle `define-derived-mode'."
521       (if (eq (car-safe (ad-get-arg 0)) 'define-derived-mode)
522           (setq ad-return-value
523                 (list 'autoload
524                       (list 'quote (nth 1 (ad-get-arg 0)))
525                       (ad-get-arg 1)
526                       (nth 4 (ad-get-arg 0))
527                       t nil))
528         ad-do-it))
529     (put 'define-derived-mode 'doc-string-elt 3))
530   (let ((generated-autoload-file dgnushack-gnus-load-file)
531         (make-backup-files nil)
532         (autoload-package-name "gnus"))
533     (if (featurep 'xemacs)
534         (if (file-exists-p generated-autoload-file)
535             (delete-file generated-autoload-file))
536       (with-temp-file generated-autoload-file
537         (insert ?\014)))
538     (if (featurep 'xemacs)
539         (let ((si:message (symbol-function 'message)))
540           (defun message (fmt &rest args)
541             (cond ((and (string-equal "Generating autoloads for %s..." fmt)
542                         (file-exists-p (file-name-nondirectory (car args))))
543                    (funcall si:message
544                             fmt (file-name-nondirectory (car args))))
545                   ((string-equal "No autoloads found in %s" fmt))
546                   ((string-equal "Generating autoloads for %s...done" fmt))
547                   (t (apply si:message fmt args))))
548           (unwind-protect
549               (batch-update-autoloads)
550             (fset 'message si:message)))
551       (batch-update-autoloads))))
552
553 (defun dgnushack-make-load ()
554   (unless (featurep 'xemacs)
555     (message "Generating %s..." dgnushack-gnus-load-file)
556     (with-temp-file dgnushack-gnus-load-file
557       (insert-file-contents dgnushack-cus-load-file)
558       (delete-file dgnushack-cus-load-file)
559       (goto-char (point-min))
560       (search-forward ";;; Code:")
561       (forward-line)
562       (delete-region (point-min) (point))
563       (insert "\
564 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
565 ;;
566 ;;; Code:
567 ")
568       (goto-char (point-max))
569       (if (search-backward "custom-versions-load-alist" nil t)
570           (forward-line -1)
571         (forward-line -1)
572         (while (eq (char-after) ?\;)
573           (forward-line -1))
574         (forward-line))
575       (delete-region (point) (point-max))
576       (insert "\n")
577       ;; smiley-* are duplicated. Remove them all.
578       (let ((point (point)))
579         (insert-file-contents dgnushack-gnus-load-file)
580         (goto-char point)
581         (while (search-forward "smiley-" nil t)
582           (beginning-of-line)
583           (if (looking-at "(autoload ")
584               (delete-region (point) (progn (forward-sexp) (point)))
585             (forward-line))))
586       ;;
587       (goto-char (point-max))
588       (when (search-backward "\n(provide " nil t)
589         (forward-line -1)
590         (delete-region (point) (point-max)))
591       (insert "\
592
593 \(provide 'gnus-load)
594
595 ;;; Local Variables:
596 ;;; version-control: never
597 ;;; no-byte-compile: t
598 ;;; no-update-autoloads: t
599 ;;; End:
600 ;;; gnus-load.el ends here
601 ")
602       ))
603   (message "Compiling %s..." dgnushack-gnus-load-file)
604   (byte-compile-file dgnushack-gnus-load-file)
605   (when (featurep 'xemacs)
606     (message "Creating dummy gnus-load.el...")
607     (with-temp-file (expand-file-name "gnus-load.el")
608       (insert "\
609
610 \(provide 'gnus-load)
611
612 ;;; Local Variables:
613 ;;; version-control: never
614 ;;; no-byte-compile: t
615 ;;; no-update-autoloads: t
616 ;;; End:
617 ;;; gnus-load.el ends here"))))
618
619 \f
620 (defconst dgnushack-info-file-regexp-en
621   (let ((names '("gnus" "message" "emacs-mime"))
622         regexp name)
623     (while (setq name (pop names))
624       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
625                            (when names "\\|"))))
626     regexp)
627   "Regexp matching English info files.")
628
629 (defconst dgnushack-info-file-regexp-ja
630   (let ((names '("gnus-ja" "message-ja"))
631         regexp name)
632     (while (setq name (pop names))
633       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
634                            (when names "\\|"))))
635     regexp)
636   "Regexp matching Japanese info files.")
637
638 (defun dgnushack-remove-extra-files-in-package ()
639   "Remove extra files in the lisp directory of the XEmacs package."
640   (let ((lisp-dir (expand-file-name (concat "lisp/"
641                                             ;; GNUS_PRODUCT_NAME
642                                             (cadr command-line-args-left)
643                                             "/")
644                                     ;; PACKAGEDIR
645                                     (car command-line-args-left))))
646     (setq command-line-args-left nil)
647     (when (file-directory-p lisp-dir)
648       (let (files)
649         (dolist (file dgnushack-exporting-files)
650           (setq files (nconc files (list file (concat file "c")))))
651         (dolist (file (directory-files lisp-dir nil nil t t))
652           (unless (member file files)
653             (setq file (expand-file-name file lisp-dir))
654             (message "Removing %s..." file)
655             (condition-case nil
656                 (delete-file file)
657               (error nil))))))))
658
659 (defun dgnushack-install-package-manifest ()
660   "Install MANIFEST file as an XEmacs package."
661   (let* ((package-dir (pop command-line-args-left))
662          (product-name (pop command-line-args-left))
663          (pkginfo-dir (expand-file-name "pkginfo" package-dir))
664          (name (expand-file-name (concat "MANIFEST." product-name)
665                                  pkginfo-dir))
666          make-backup-files)
667     (unless (file-directory-p pkginfo-dir)
668       (message "Creating directory %s/..." pkginfo-dir)
669       (make-directory pkginfo-dir))
670     (message "Generating %s..." name)
671     (with-temp-file name
672       (insert "pkginfo/MANIFEST." product-name "\n")
673       (let ((lisp-dir (concat "lisp/" product-name "/"))
674             (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
675             file)
676         (while (setq file (pop files))
677           (unless (member file dgnushack-unexporting-files)
678             (insert lisp-dir file "\n")))
679         (setq files
680               (sort (directory-files "../texi/" nil
681                                      (concat dgnushack-info-file-regexp-en
682                                              "\\|"
683                                              dgnushack-info-file-regexp-ja)
684                                      t)
685                     'string-lessp))
686         (while (setq file (pop files))
687           (insert "info/" file "\n"))))))
688
689 \f
690 (define-compiler-macro describe-key-briefly (&whole form key &optional insert)
691   (if (condition-case nil
692           (progn
693             (describe-key-briefly '((())) nil)
694             t)
695         (wrong-number-of-arguments nil);; Old Emacsen.
696         (error t))
697       form
698     (if insert
699         `(if ,insert
700              (insert (funcall 'describe-key-briefly ,key))
701            (funcall 'describe-key-briefly ,key))
702       `(funcall 'describe-key-briefly ,key))))
703
704 ;;; dgnushack.el ends here