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