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