* lisp/gnus-vers.el (gnus-revision-number): Increment to 01.
[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 define-widget
299                                      quote widget-convert-button
300                                      widget-create widget-put))
301                        (while (consp elem)
302                          (push (car elem) form)
303                          (setq elem (cdr elem)))
304                        (when (and elem
305                                   (symbolp elem)
306                                   (not (eq ': elem))
307                                   (eq ?: (aref (symbol-name elem) 0))
308                                   (not (memq elem ignores))
309                                   (not (memq elem keywords)))
310                          (push elem keywords)))))))
311              (setq keywords (sort keywords
312                                   (lambda (a b)
313                                     (string-lessp (symbol-name a)
314                                                   (symbol-name b)))))
315              (erase-buffer)
316              (insert (format "%s" keywords))
317              (write-region (point-min) (point) cache nil 'silent)
318              (message
319               "The following colon keywords will be bound at run-time:\n %s"
320               keywords))))
321        (kill-buffer buffer)
322        (defconst dgnushack-colon-keywords keywords)
323        (while keywords
324          (set (car keywords) (car keywords))
325          (setq keywords (cdr keywords)))))
326    (byte-compile 'dgnushack-bind-colon-keywords)
327    (dgnushack-bind-colon-keywords)))
328
329 ;; If you are using Mule 2.3 based on Emacs 19.34, you may also put the
330 ;; following lines in your .emacs file, before gnus related modules are
331 ;; loaded.  It is not always necessary.  However if it is done, you will
332 ;; be able to load or evaluate gnus related *.el (not compiled) files.
333 ;; ------ cut here ------ cut here ------ cut here ------ cut here ------
334 (if (boundp 'MULE)
335     (progn
336       (setq :version ':version
337             :set-after ':set-after)
338       (require 'custom)
339       (defadvice custom-handle-keyword
340         (around dont-signal-an-error-even-if-unsupported-keyword-is-given
341                 activate)
342         "Don't signal an error even if unsupported keyword is given."
343         (if (not (memq (ad-get-arg 1) '(:version :set-after)))
344             ad-do-it))))
345 ;; ------ cut here ------ cut here ------ cut here ------ cut here ------
346
347 (when (boundp 'MULE)
348   (put 'custom-declare-face 'byte-optimizer
349        'byte-optimize-ignore-unsupported-custom-keywords)
350   (put 'custom-declare-group 'byte-optimizer
351        'byte-optimize-ignore-unsupported-custom-keywords)
352   (defun byte-optimize-ignore-unsupported-custom-keywords (form)
353     (if (or (memq ':version (nthcdr 4 form))
354             (memq ':set-after (nthcdr 4 form)))
355         (let ((newform (list (car form) (nth 1 form)
356                              (nth 2 form) (nth 3 form)))
357               (args (nthcdr 4 form)))
358           (while args
359             (or (memq (car args) '(:version :set-after))
360                 (setq newform (nconc newform (list (car args)
361                                                    (car (cdr args))))))
362             (setq args (cdr (cdr args))))
363           newform)
364       form))
365
366   (put 'custom-declare-variable 'byte-hunk-handler
367        'byte-compile-file-form-custom-declare-variable)
368   (defun byte-compile-file-form-custom-declare-variable (form)
369     ;; Bind defcustom'ed variables.
370     (if (memq 'free-vars byte-compile-warnings)
371         (setq byte-compile-bound-variables
372               (cons (nth 1 (nth 1 form)) byte-compile-bound-variables)))
373     (if (memq ':version (nthcdr 4 form))
374         ;; Make the variable uncustomizable.
375         `(defvar ,(nth 1 (nth 1 form)) ,(nth 1 (nth 2 form))
376            ,(substring (nth 3 form) (if (string-match "^[\t *]+" (nth 3 form))
377                                         (match-end 0)
378                                       0)))
379       ;; Ignore unsupported keyword(s).
380       (if (memq ':set-after (nthcdr 4 form))
381           (let ((newform (list (car form) (nth 1 form)
382                                (nth 2 form) (nth 3 form)))
383                 (args (nthcdr 4 form)))
384             (while args
385               (or (eq (car args) ':set-after)
386                   (setq newform (nconc newform (list (car args)
387                                                      (car (cdr args))))))
388               (setq args (cdr (cdr args))))
389             newform)
390         form))))
391
392 ;; Unknown variables and functions.
393 (unless (boundp 'buffer-file-coding-system)
394   (defvar buffer-file-coding-system (symbol-value 'file-coding-system)))
395 (unless (featurep 'xemacs)
396   (defalias 'Custom-make-dependencies 'ignore)
397   (defalias 'update-autoloads-from-directory 'ignore))
398
399 (defalias 'device-sound-enabled-p 'ignore)
400 (defalias 'play-sound-file 'ignore)
401 (defalias 'nndb-request-article 'ignore)
402 (defalias 'efs-re-read-dir 'ignore)
403 (defalias 'ange-ftp-re-read-dir 'ignore)
404 (defalias 'define-mail-user-agent 'ignore)
405
406 (defconst dgnushack-unexporting-files
407   (append '("dgnushack.el" "dgnuspath.el" "dgnuskwds.el" "lpath.el")
408           (unless (or (condition-case code
409                           (require 'w3-forms)
410                         (error
411                          (message "No w3: %s %s retrying..." code
412                                   (locate-library "w3-forms"))
413                          nil))
414                       ;; Maybe mis-configured Makefile is used (e.g.
415                       ;; configured for FSFmacs but XEmacs is running).
416                       (let ((lp (delete dgnushack-w3-directory
417                                         (copy-sequence load-path))))
418                         (if (let ((load-path lp))
419                               (condition-case nil
420                                   (require 'w3-forms)
421                                 (error nil)))
422                             ;; If success, fix `load-path' for compiling.
423                             (progn
424                               (setq load-path lp)
425                               (message " => fixed; W3DIR=%s"
426                                        (file-name-directory
427                                         (locate-library "w3-forms")))
428                               t)
429                           (message " => ignored")
430                           nil)))
431             '("nnweb.el" "nnlistserv.el" "nnultimate.el"
432               "nnslashdot.el" "nnwarchive.el" "webmail.el"
433               "nnwfm.el" "nnrss.el"))
434           (condition-case nil
435               (progn (require 'bbdb) nil)
436             (error '("gnus-bbdb.el")))
437           (unless (featurep 'xemacs)
438             '("gnus-xmas.el" "gnus-picon.el" "messagexmas.el"
439               "nnheaderxm.el" "smiley.el"))
440           (when (or (featurep 'xemacs) (<= emacs-major-version 20))
441             '("smiley-ems.el"))
442           (when (and (fboundp 'base64-decode-string)
443                      (subrp (symbol-function 'base64-decode-string)))
444             '("base64.el"))
445           (when (and (fboundp 'md5) (subrp (symbol-function 'md5)))
446             '("md5.el")))
447   "Files which will not be installed.")
448
449 (defconst dgnushack-exporting-files
450   (let ((files (directory-files srcdir nil "^[^=].*\\.el$" t)))
451     (dolist (file dgnushack-unexporting-files)
452       (setq files (delete file files)))
453     (sort files 'string-lessp))
454   "Files which will be compiled and installed.")
455
456 (defun dgnushack-exporting-files ()
457   "Print name of files which will be installed."
458   (princ (mapconcat 'identity dgnushack-exporting-files " ")))
459
460 (defun dgnushack-compile (&optional warn)
461   ;;(setq byte-compile-dynamic t)
462   (unless warn
463     (setq byte-compile-warnings
464           '(free-vars unresolved callargs redefine)))
465   (unless (locate-library "cus-edit")
466     (error "You do not seem to have Custom installed.
467 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
468 You also then need to add the following to the lisp/dgnushack.el file:
469
470      (push \"~/lisp/custom\" load-path)
471
472 Modify to suit your needs."))
473
474   ;; Show `load-path'.
475   (message "load-path=(\"%s\")"
476            (mapconcat 'identity load-path "\"\n           \""))
477
478   (dolist (file dgnushack-exporting-files)
479     (setq file (expand-file-name file srcdir))
480     (when (and (file-exists-p
481                 (setq elc (concat (file-name-nondirectory file) "c")))
482                (file-newer-than-file-p file elc))
483       (delete-file elc)))
484
485   (let ((files dgnushack-exporting-files)
486         ;;(byte-compile-generate-call-tree t)
487         file elc)
488     ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
489     ;; installed.
490     (when (featurep 'xemacs)
491       (setq gnus-xmas-glyph-directory "dummy"))
492     (while (setq file (pop files))
493       (setq file (expand-file-name file srcdir))
494       (when (or (not (file-exists-p
495                       (setq elc (concat (file-name-nondirectory file) "c"))))
496                 (file-newer-than-file-p file elc))
497         (ignore-errors
498           (byte-compile-file file))))))
499
500 (defun dgnushack-recompile ()
501   (require 'gnus)
502   (byte-recompile-directory "." 0))
503
504 (defvar dgnushack-gnus-load-file (expand-file-name "gnus-load.el" srcdir))
505 (defvar dgnushack-cus-load-file (expand-file-name "cus-load.el" srcdir))
506 (defvar dgnushack-auto-load-file (expand-file-name "auto-autoloads.el" srcdir))
507
508 (defun dgnushack-make-cus-load ()
509   (when (condition-case nil
510             (load "cus-dep")
511           (error nil))
512     (let ((cusload-base-file dgnushack-cus-load-file))
513       (if (fboundp 'custom-make-dependencies)
514           (custom-make-dependencies)
515         (Custom-make-dependencies)))))
516
517 (defun dgnushack-make-auto-load ()
518   (require 'autoload)
519   (let ((generated-autoload-file dgnushack-gnus-load-file)
520         (make-backup-files nil)
521         (autoload-package-name "gnus"))
522     (if (featurep 'xemacs)
523         (progn
524           (if (file-exists-p generated-autoload-file)
525               (delete-file generated-autoload-file))
526           (if (file-exists-p dgnushack-auto-load-file)
527               (delete-file dgnushack-auto-load-file)))
528       (with-temp-file generated-autoload-file
529         (insert ?\014)))
530     (if (featurep 'xemacs)
531         (let ((si:message (symbol-function 'message)))
532           (defun message (fmt &rest args)
533             (cond ((and (string-equal "Generating autoloads for %s..." fmt)
534                         (file-exists-p (file-name-nondirectory (car args))))
535                    (funcall si:message
536                             fmt (file-name-nondirectory (car args))))
537                   ((string-equal "No autoloads found in %s" fmt))
538                   ((string-equal "Generating autoloads for %s...done" fmt))
539                   (t (apply si:message fmt args))))
540           (unwind-protect
541               (batch-update-autoloads)
542             (fset 'message si:message)))
543       (batch-update-autoloads))))
544
545 (defun dgnushack-make-load ()
546   (message (format "Generating %s..." dgnushack-gnus-load-file))
547   (with-temp-file dgnushack-gnus-load-file
548     (if (file-exists-p dgnushack-cus-load-file)
549         (progn
550           (insert-file-contents dgnushack-cus-load-file)
551           (delete-file dgnushack-cus-load-file)
552           (goto-char (point-min))
553           (search-forward ";;; Code:")
554           (forward-line)
555           (delete-region (point-min) (point))
556           (unless (re-search-forward "\
557 ^[\t ]*(autoload[\t\n ]+\\('\\|(quote[\t\n ]+\\)custom-add-loads[\t\n ]"
558                                      nil t)
559             (insert "\n(autoload 'custom-add-loads \"cus-load\")\n"))
560           (goto-char (point-min))
561           (insert "\
562 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
563 ;;
564 ;;; Code:
565 ")
566           (goto-char (point-max))
567           (if (search-backward "custom-versions-load-alist" nil t)
568               (forward-line -1)
569             (forward-line -1)
570             (while (eq (char-after) ?\;)
571               (forward-line -1))
572             (forward-line))
573           (delete-region (point) (point-max))
574           (insert "\n"))
575       (insert "\
576 ;;; gnus-load.el --- automatically extracted autoload
577 ;;
578 ;;; Code:
579 "))
580     ;; smiley-* are duplicated. Remove them all.
581     (let ((point (point)))
582       (insert-file-contents dgnushack-gnus-load-file)
583       (goto-char point)
584       (while (search-forward "smiley-" nil t)
585         (beginning-of-line)
586         (if (looking-at "(autoload ")
587             (delete-region (point) (progn (forward-sexp) (point)))
588           (forward-line))))
589     ;;
590     (goto-char (point-max))
591     (when (search-backward "\n(provide " nil t)
592       (forward-line -1)
593       (delete-region (point) (point-max)))
594     (insert "\
595
596 \(provide 'gnus-load)
597
598 ;;; Local Variables:
599 ;;; version-control: never
600 ;;; no-byte-compile: t
601 ;;; no-update-autoloads: t
602 ;;; End:
603 ;;; gnus-load.el ends here\n"))
604   (message (format "Compiling %s..." dgnushack-gnus-load-file))
605   (byte-compile-file dgnushack-gnus-load-file))
606
607 \f
608 (defun dgnushack-compose-package ()
609   "Re-split the file gnus-load.el into custom-load.el and
610 auto-autoloads.el.  It is silly, should be improved!"
611   (message "
612 Re-splitting gnus-load.el into custom-load.el and auto-autoloads.el...")
613   (let ((customload (expand-file-name "custom-load.el" srcdir))
614         (autoloads (expand-file-name "auto-autoloads.el" srcdir))
615         start)
616     (with-temp-buffer
617       (insert-file-contents dgnushack-gnus-load-file)
618       (delete-file dgnushack-gnus-load-file)
619       (when (file-exists-p (concat dgnushack-gnus-load-file "c"))
620         (delete-file (concat dgnushack-gnus-load-file "c")))
621       (while (prog1
622                  (looking-at "[\t ;]")
623                (forward-line 1)))
624       (setq start (point))
625       (insert "\
626 ;;; custom-load.el --- automatically extracted custom dependencies\n
627 ;;; Code:\n\n")
628       (goto-char (point-max))
629       (while (progn
630                (forward-line -1)
631                (not (looking-at "[\t ]*(custom-add-loads[\t\n ]"))))
632       (forward-list 1)
633       (forward-line 1)
634       (insert "\n;;; custom-load.el ends here\n")
635       (write-region start (point) customload)
636       (while (looking-at "[\t ]*$")
637         (forward-line 1))
638       (setq start (point))
639       (if (re-search-forward "^[\t\n ]*(if[\t\n ]+(featurep[\t\n ]" nil t)
640           (let ((from (goto-char (match-beginning 0))))
641             (delete-region from (progn
642                                   (forward-list 1)
643                                   (forward-line 1)
644                                   (point))))
645         (while (looking-at "[\t ;]")
646           (forward-line 1)))
647       (insert "(if (featurep 'gnus-autoloads) (error \"Already loaded\"))\n")
648       (goto-char (point-max))
649       (while (progn
650                (forward-line -1)
651                (not (looking-at "[\t ]*(provide[\t\n ]"))))
652       (insert "(provide 'gnus-autoloads)\n")
653       (write-region start (point) autoloads))
654     (byte-compile-file customload)
655     (byte-compile-file autoloads))
656   (message "\
657 Re-splitting gnus-load.el into custom-load.el and auto-autoloads.el...done
658 \n"))
659
660 \f
661 (defconst dgnushack-info-file-regexp-en
662   (let ((names '("gnus" "message" "emacs-mime"))
663         regexp name)
664     (while (setq name (pop names))
665       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
666                            (when names "\\|"))))
667     regexp)
668   "Regexp matching English info files.")
669
670 (defconst dgnushack-info-file-regexp-ja
671   (let ((names '("gnus-ja" "message-ja"))
672         regexp name)
673     (while (setq name (pop names))
674       (setq regexp (concat regexp "^" name "\\.info\\(-[0-9]+\\)?$"
675                            (when names "\\|"))))
676     regexp)
677   "Regexp matching Japanese info files.")
678
679 (defun dgnushack-remove-extra-files-in-package ()
680   "Remove extra files in the lisp directory of the XEmacs package."
681   (let ((lisp-dir (expand-file-name (concat "lisp/"
682                                             ;; GNUS_PRODUCT_NAME
683                                             (cadr command-line-args-left)
684                                             "/")
685                                     ;; PACKAGEDIR
686                                     (car command-line-args-left))))
687     (when (file-directory-p lisp-dir)
688       (let (files)
689         (dolist (file dgnushack-exporting-files)
690           (setq files (nconc files (list file (concat file "c")))))
691         (dolist (file (directory-files lisp-dir nil nil t t))
692           (unless (member file files)
693             (setq file (expand-file-name file lisp-dir))
694             (message "Removing %s..." file)
695             (condition-case nil
696                 (delete-file file)
697               (error nil))))))))
698
699 (defun dgnushack-install-package-manifest ()
700   "Install MANIFEST file as an XEmacs package."
701   (let* ((package-dir (car command-line-args-left))
702          (product-name (cadr command-line-args-left))
703          (name (expand-file-name (concat "pkginfo/MANIFEST." product-name)
704                                  package-dir))
705          make-backup-files)
706     (message "Generating %s..." name)
707     (with-temp-file name
708       (insert "pkginfo/MANIFEST." product-name "\n")
709       (let ((lisp-dir (concat "lisp/" product-name "/"))
710             (files (sort (directory-files "." nil "\\.elc?$" t) 'string-lessp))
711             file)
712         (while (setq file (pop files))
713           (unless (member file dgnushack-unexporting-files)
714             (insert lisp-dir file "\n")))
715         (setq files
716               (sort (directory-files "../texi/" nil
717                                      (concat dgnushack-info-file-regexp-en
718                                              "\\|"
719                                              dgnushack-info-file-regexp-ja)
720                                      t)
721                     'string-lessp))
722         (while (setq file (pop files))
723           (insert "info/" file "\n"))))))
724
725 \f
726 (define-compiler-macro describe-key-briefly (&whole form key &optional insert)
727   (if (condition-case nil
728           (progn
729             (describe-key-briefly '((())) nil)
730             t)
731         (wrong-number-of-arguments nil);; Old Emacsen.
732         (error t))
733       form
734     (if insert
735         `(if ,insert
736              (insert (funcall 'describe-key-briefly ,key))
737            (funcall 'describe-key-briefly ,key))
738       `(funcall 'describe-key-briefly ,key))))
739
740 ;;; dgnushack.el ends here