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