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