Synch to No Gnus 200402240748.
[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 (push srcdir load-path)
249 (load (expand-file-name "lpath.el" srcdir) nil t t)
250
251 (require 'custom)
252
253 ;; Bind functions defined by `defun-maybe'.
254 (put 'defun-maybe 'byte-hunk-handler 'byte-compile-file-form-defun-maybe)
255 (defun byte-compile-file-form-defun-maybe (form)
256   (if (and (not (fboundp (nth 1 form)))
257            (memq 'unresolved byte-compile-warnings))
258       (setq byte-compile-function-environment
259             (cons (cons (nth 1 form)
260                         (cons 'lambda (cdr (cdr form))))
261                   byte-compile-function-environment)))
262   form)
263
264 ;; Unknown variables and functions.
265 (unless (featurep 'xemacs)
266   (defalias 'Custom-make-dependencies 'ignore)
267   (defalias 'update-autoloads-from-directory 'ignore))
268
269 (defalias 'device-sound-enabled-p 'ignore)
270 (defalias 'play-sound-file 'ignore)
271 (defalias 'nndb-request-article 'ignore)
272 (defalias 'efs-re-read-dir 'ignore)
273 (defalias 'ange-ftp-re-read-dir 'ignore)
274 (defalias 'define-mail-user-agent 'ignore)
275
276 (eval-and-compile
277   (when (featurep 'xemacs)
278     (unless (fboundp 'defadvice)
279       (autoload 'defadvice "advice" nil nil 'macro))
280     (autoload 'Info-directory "info" nil t)
281     (autoload 'Info-menu "info" nil t)
282     (autoload 'annotations-at "annotations")
283     (autoload 'apropos "apropos" nil t)
284     (autoload 'apropos-command "apropos" nil t)
285     (autoload 'bbdb-complete-name "bbdb-com" nil t)
286     (autoload 'browse-url "browse-url" nil t)
287     (autoload 'customize-apropos "cus-edit" nil t)
288     (autoload 'customize-save-variable "cus-edit" nil t)
289     (autoload 'customize-variable "cus-edit" nil t)
290     (autoload 'delete-annotation "annotations")
291     (autoload 'dolist "cl-macs" nil nil 'macro)
292     (autoload 'enriched-decode "enriched")
293     (autoload 'executable-find "executable")
294     (autoload 'font-lock-fontify-buffer "font-lock" nil t)
295     (autoload 'info "info" nil t)
296     (autoload 'make-annotation "annotations")
297     (autoload 'make-display-table "disp-table")
298     (autoload 'pp "pp")
299     (autoload 'ps-despool "ps-print" nil t)
300     (autoload 'ps-spool-buffer "ps-print" nil t)
301     (autoload 'ps-spool-buffer-with-faces "ps-print" nil t)
302     (autoload 'read-passwd "passwd")
303     (autoload 'regexp-opt "regexp-opt")
304     (autoload 'reporter-submit-bug-report "reporter")
305     (if (emacs-version>= 21 5)
306         (autoload 'setenv "process" nil t)
307       (autoload 'setenv "env" nil t))
308     (autoload 'smtpmail-send-it "smtpmail")
309     (autoload 'sort-numeric-fields "sort" nil t)
310     (autoload 'sort-subr "sort")
311     (autoload 'trace-function-background "trace" nil t)
312     (autoload 'w3-do-setup "w3")
313     (autoload 'w3-prepare-buffer "w3-display")
314     (autoload 'w3-region "w3-display" nil t)
315     (defalias 'frame-char-height 'frame-height)
316     (defalias 'frame-char-width 'frame-width)
317     (defalias 'frame-parameter 'frame-property)
318     (defalias 'make-overlay 'ignore)
319     (defalias 'overlay-end 'ignore)
320     (defalias 'overlay-get 'ignore)
321     (defalias 'overlay-put 'ignore)
322     (defalias 'overlay-start 'ignore)
323     (defalias 'overlays-in 'ignore)
324     (defalias 'replace-dehighlight 'ignore)
325     (defalias 'replace-highlight 'ignore)
326     (defalias 'run-with-idle-timer 'ignore)
327     (defalias 'w3-coding-system-for-mime-charset 'ignore)))
328
329 ;; T-gnus stuff.
330 (eval-and-compile
331   (when (featurep 'xemacs)
332     (autoload 'c-mode "cc-mode" nil t)
333     (autoload 'font-lock-mode "font-lock" nil t)
334     (autoload 'read-kbd-macro "edmacro" nil t)
335     (autoload 'turn-on-font-lock "font-lock" nil t))
336   (autoload 'nnheader-detect-coding-region "nnheader")
337   (autoload 'std11-extract-addresses-components "nnheader")
338   (autoload 'std11-fold-region "nnheader")
339   (autoload 'std11-narrow-to-field "nnheader")
340   (autoload 'std11-unfold-region "nnheader"))
341
342 (defconst dgnushack-unexporting-files
343   (append '("dgnushack.el" "dgnuspath.el" "dgnuskwds.el" "lpath.el")
344           (unless (or (condition-case code
345                           (require 'w3-parse)
346                         (error
347                          (message "No w3: %s%s, retrying..."
348                                   (error-message-string code)
349                                   (if (setq code (locate-library "w3-parse"))
350                                       (concat " (" code ")")
351                                     ""))
352                          nil))
353                       ;; Maybe mis-configured Makefile is used (e.g.
354                       ;; configured for FSFmacs but XEmacs is running).
355                       (let ((lp (delete dgnushack-w3-directory
356                                         (copy-sequence load-path))))
357                         (if (let ((load-path lp))
358                               (condition-case nil
359                                   (require 'w3-parse)
360                                 (error nil)))
361                             ;; If success, fix `load-path' for compiling.
362                             (progn
363                               (setq load-path lp)
364                               (message " => fixed; W3DIR=%s"
365                                        (file-name-directory
366                                         (locate-library "w3-parse")))
367                               t)
368                           (message " => ignored")
369                           nil)))
370             '("nnultimate.el" "webmail.el" "nnwfm.el"))
371           (condition-case code
372               (progn (require 'mh-e) nil)
373             (error
374              (message "No mh-e: %s%s (ignored)"
375                       (error-message-string code)
376                       (if (setq code (locate-library "mh-e"))
377                           (concat " (" code ")")
378                         ""))
379              '("gnus-mh.el")))
380           (condition-case code
381               (progn (require 'xml) nil)
382             (error
383              (message "No xml: %s%s (ignored)"
384                       (error-message-string code)
385                       (if (setq code (locate-library "xml"))
386                           (concat " (" code ")")
387                         ""))
388              '("nnrss.el")))
389           (condition-case code
390               (progn (require 'bbdb) nil)
391             (error
392              (message "No bbdb: %s%s (ignored)"
393                       (error-message-string code)
394                       (if (setq code (locate-library "bbdb"))
395                           (concat " (" code ")")
396                         ""))
397              '("gnus-bbdb.el")))
398           (unless (featurep 'xemacs)
399             '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el"
400               "run-at-time.el"))
401           (when (and (fboundp 'base64-decode-string)
402                      (subrp (symbol-function 'base64-decode-string)))
403             '("base64.el"))
404           (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
405             '("md5.el"))
406           (when (featurep 'xemacs)
407             '("gnus-load.el")))
408   "Files which will not be installed.")
409
410 (defconst dgnushack-exporting-files
411   (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
412     (dolist (file dgnushack-unexporting-files)
413       (setq files (delete file files)))
414     (sort files 'string-lessp))
415   "Files which will be compiled and installed.")
416
417 (defun dgnushack-exporting-files ()
418   "Print name of files which will be installed."
419   (princ (mapconcat 'identity dgnushack-exporting-files " ")))
420
421 (defconst dgnushack-dont-compile-files
422   '("gnus-load.el"
423     "mm-bodies.el" "mm-decode.el" "mm-encode.el" "mm-extern.el"
424     "mm-partial.el" "mm-url.el" "mm-uu.el" "mm-view.el" "mml-sec.el"
425     "mml-smime.el" "mml.el" "mml1991.el" "mml2015.el")
426   "Files which should not be byte-compiled.")
427
428 (defun dgnushack-compile-verbosely ()
429   "Call dgnushack-compile with warnings ENABLED.  If you are compiling
430 patches to gnus, you should consider modifying make.bat to call
431 dgnushack-compile-verbosely.  All other users should continue to use
432 dgnushack-compile."
433   (dgnushack-compile t))
434
435 (defun dgnushack-compile (&optional warn)
436   ;;(setq byte-compile-dynamic t)
437   (unless warn
438     (setq byte-compile-warnings
439           '(free-vars unresolved callargs redefine)))
440
441   ;; Show `load-path'.
442   (message "load-path=(\"%s\")"
443            (mapconcat 'identity load-path "\"\n           \""))
444
445   (dolist (file dgnushack-exporting-files)
446     (setq file (expand-file-name file srcdir))
447     (when (and (file-exists-p
448                 (setq elc (concat (file-name-nondirectory file) "c")))
449                (file-newer-than-file-p file elc))
450       (delete-file elc)))
451
452   ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
453   ;; installed.
454   (when (featurep 'xemacs)
455     (setq gnus-xmas-glyph-directory "dummy"))
456
457   (let ((files dgnushack-exporting-files)
458         ;;(byte-compile-generate-call-tree t)
459         file elc)
460     (while (setq file (pop files))
461       (unless (member file dgnushack-dont-compile-files)
462         (setq file (expand-file-name file srcdir))
463         (when (or (not (file-exists-p
464                         (setq elc (concat (file-name-nondirectory file) "c"))))
465                   (file-newer-than-file-p file elc))
466           (ignore-errors
467             (byte-compile-file file)))))))
468
469 (defun dgnushack-recompile ()
470   (require 'gnus)
471   (byte-recompile-directory "." 0))
472
473 (defvar dgnushack-gnus-load-file
474   (if (featurep 'xemacs)
475       (expand-file-name "auto-autoloads.el" srcdir)
476     (expand-file-name "gnus-load.el" srcdir)))
477
478 (defvar dgnushack-cus-load-file
479   (if (featurep 'xemacs)
480       (expand-file-name "custom-load.el" srcdir)
481     (expand-file-name "cus-load.el" srcdir)))
482
483 (defun dgnushack-make-cus-load ()
484   (load "cus-dep")
485   (let ((cusload-base-file dgnushack-cus-load-file))
486     (if (fboundp 'custom-make-dependencies)
487         (custom-make-dependencies)
488       (Custom-make-dependencies))
489     (when (featurep 'xemacs)
490       (message "Compiling %s..." dgnushack-cus-load-file)
491       (byte-compile-file dgnushack-cus-load-file))))
492
493 (defun dgnushack-make-auto-load ()
494   (require 'autoload)
495   (unless (make-autoload '(define-derived-mode child parent name
496                             "docstring" body)
497                          "file")
498     (defadvice make-autoload (around handle-define-derived-mode activate)
499       "Handle `define-derived-mode'."
500       (if (eq (car-safe (ad-get-arg 0)) 'define-derived-mode)
501           (setq ad-return-value
502                 (list 'autoload
503                       (list 'quote (nth 1 (ad-get-arg 0)))
504                       (ad-get-arg 1)
505                       (nth 4 (ad-get-arg 0))
506                       t nil))
507         ad-do-it))
508     (put 'define-derived-mode 'doc-string-elt 3))
509   (let ((generated-autoload-file dgnushack-gnus-load-file)
510         (make-backup-files nil)
511         (autoload-package-name "gnus"))
512     (if (featurep 'xemacs)
513         (if (file-exists-p generated-autoload-file)
514             (delete-file generated-autoload-file))
515       (with-temp-file generated-autoload-file
516         (insert ?\014)))
517     (if (featurep 'xemacs)
518         (let ((si:message (symbol-function 'message)))
519           (defun message (fmt &rest args)
520             (cond ((and (string-equal "Generating autoloads for %s..." fmt)
521                         (file-exists-p (file-name-nondirectory (car args))))
522                    (funcall si:message
523                             fmt (file-name-nondirectory (car args))))
524                   ((string-equal "No autoloads found in %s" fmt))
525                   ((string-equal "Generating autoloads for %s...done" fmt))
526                   (t (apply si:message fmt args))))
527           (unwind-protect
528               (batch-update-autoloads)
529             (fset 'message si:message)))
530       (batch-update-autoloads))))
531
532 (defun dgnushack-make-load ()
533   (unless (featurep 'xemacs)
534     (message "Generating %s..." dgnushack-gnus-load-file)
535     (with-temp-file dgnushack-gnus-load-file
536       (insert-file-contents dgnushack-cus-load-file)
537       (delete-file dgnushack-cus-load-file)
538       (goto-char (point-min))
539       (search-forward ";;; Code:")
540       (forward-line)
541       (delete-region (point-min) (point))
542       (insert "\
543 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
544 ;;
545 ;;; Code:
546 ")
547       (goto-char (point-max))
548       (if (search-backward "custom-versions-load-alist" nil t)
549           (forward-line -1)
550         (forward-line -1)
551         (while (eq (char-after) ?\;)
552           (forward-line -1))
553         (forward-line))
554       (delete-region (point) (point-max))
555       (insert "\n")
556       ;; smiley-* are duplicated. Remove them all.
557       (let ((point (point)))
558         (insert-file-contents dgnushack-gnus-load-file)
559         (goto-char point)
560         (while (search-forward "smiley-" nil t)
561           (beginning-of-line)
562           (if (looking-at "(autoload ")
563               (delete-region (point) (progn (forward-sexp) (point)))
564             (forward-line))))
565       ;;
566       (goto-char (point-max))
567       (when (search-backward "\n(provide " nil t)
568         (forward-line -1)
569         (delete-region (point) (point-max)))
570       (insert "\
571
572 \(provide 'gnus-load)
573
574 ;;; Local Variables:
575 ;;; version-control: never
576 ;;; no-byte-compile: t
577 ;;; no-update-autoloads: t
578 ;;; End:
579 ;;; gnus-load.el ends here
580 ")
581       ))
582   (message "Compiling %s..." dgnushack-gnus-load-file)
583   (byte-compile-file dgnushack-gnus-load-file)
584   (when (featurep 'xemacs)
585     (message "Creating dummy gnus-load.el...")
586     (with-temp-file (expand-file-name "gnus-load.el")
587       (insert "\
588
589 \(provide 'gnus-load)
590
591 ;;; Local Variables:
592 ;;; version-control: never
593 ;;; no-byte-compile: t
594 ;;; no-update-autoloads: t
595 ;;; End:
596 ;;; gnus-load.el ends here"))))
597
598 \f
599 (defconst dgnushack-info-file-regexp-en
600   (let ((names '("gnus" "message" "emacs-mime"))
601         regexp name)
602     (while (setq name (pop names))
603       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
604                            (when names "\\|"))))
605     regexp)
606   "Regexp matching English info files.")
607
608 (defconst dgnushack-info-file-regexp-ja
609   (let ((names '("gnus-ja" "message-ja"))
610         regexp name)
611     (while (setq name (pop names))
612       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
613                            (when names "\\|"))))
614     regexp)
615   "Regexp matching Japanese info files.")
616
617 (defun dgnushack-remove-extra-files-in-package ()
618   "Remove extra files in the lisp directory of the XEmacs package."
619   (let ((lisp-dir (expand-file-name (concat "lisp/"
620                                             ;; GNUS_PRODUCT_NAME
621                                             (cadr command-line-args-left)
622                                             "/")
623                                     ;; PACKAGEDIR
624                                     (car command-line-args-left))))
625     (setq command-line-args-left nil)
626     (when (file-directory-p lisp-dir)
627       (let (files)
628         (dolist (file dgnushack-exporting-files)
629           (setq files (nconc files (list file (concat file "c")))))
630         (dolist (file (directory-files lisp-dir nil nil t t))
631           (unless (member file files)
632             (setq file (expand-file-name file lisp-dir))
633             (message "Removing %s..." file)
634             (condition-case nil
635                 (delete-file file)
636               (error nil))))))))
637
638 (defun dgnushack-install-package-manifest ()
639   "Install MANIFEST file as an XEmacs package."
640   (let* ((package-dir (pop command-line-args-left))
641          (product-name (pop command-line-args-left))
642          (pkginfo-dir (expand-file-name "pkginfo" package-dir))
643          (name (expand-file-name (concat "MANIFEST." product-name)
644                                  pkginfo-dir))
645          make-backup-files)
646     (unless (file-directory-p pkginfo-dir)
647       (message "Creating directory %s/..." pkginfo-dir)
648       (make-directory pkginfo-dir))
649     (message "Generating %s..." name)
650     (with-temp-file name
651       (insert "pkginfo/MANIFEST." product-name "\n")
652       (let ((lisp-dir (concat "lisp/" product-name "/"))
653             (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
654             file)
655         (while (setq file (pop files))
656           (unless (member file dgnushack-unexporting-files)
657             (insert lisp-dir file "\n")))
658         (setq files
659               (sort (directory-files "../texi/" nil
660                                      (concat dgnushack-info-file-regexp-en
661                                              "\\|"
662                                              dgnushack-info-file-regexp-ja)
663                                      t)
664                     'string-lessp))
665         (while (setq file (pop files))
666           (insert "info/" file "\n"))))))
667
668 \f
669 (define-compiler-macro describe-key-briefly (&whole form key &optional insert)
670   (if (condition-case nil
671           (progn
672             (describe-key-briefly '((())) nil)
673             t)
674         (wrong-number-of-arguments nil);; Old Emacsen.
675         (error t))
676       form
677     (if insert
678         `(if ,insert
679              (insert (funcall 'describe-key-briefly ,key))
680            (funcall 'describe-key-briefly ,key))
681       `(funcall 'describe-key-briefly ,key))))
682
683 ;;; dgnushack.el ends here