Autoload sgml-mode for XEmacs.
[gnus] / 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, 2003
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Version: 4.19
7 ;; Keywords: news, path
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (defalias 'facep 'ignore)
31
32 (require 'cl)
33
34 (defvar srcdir (or (getenv "srcdir") "."))
35
36 (defun my-getenv (str)
37   (let ((val (getenv str)))
38     (if (equal val "no") nil val)))
39
40 (if (my-getenv "lispdir")
41     (push (my-getenv "lispdir") load-path))
42
43 (push (or (my-getenv "URLDIR") (expand-file-name "../../url/lisp/" srcdir))
44       load-path)
45
46 (push (or (my-getenv "W3DIR") (expand-file-name "../../w3/lisp/" srcdir))
47       load-path)
48
49 ;(push "/usr/share/emacs/site-lisp" load-path)
50
51 ;; If we are building w3 in a different directory than the source
52 ;; directory, we must read *.el from source directory and write *.elc
53 ;; into the building directory.  For that, we define this function
54 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
55 (defun byte-compile-dest-file (filename)
56   "Convert an Emacs Lisp source file name to a compiled file name.
57  In addition, remove directory name part from FILENAME."
58   (setq filename (byte-compiler-base-file-name filename))
59   (setq filename (file-name-sans-versions filename))
60   (setq filename (file-name-nondirectory filename))
61   (if (memq system-type '(win32 w32 mswindows windows-nt))
62       (setq filename (downcase filename)))
63   (cond ((eq system-type 'vax-vms)
64          (concat (substring filename 0 (string-match ";" filename)) "c"))
65         ((string-match emacs-lisp-file-regexp filename)
66          (concat (substring filename 0 (match-beginning 0)) ".elc"))
67         (t (concat filename ".elc"))))
68
69 (require 'bytecomp)
70 ;; To avoid having defsubsts and inlines happen.
71 ;(if (featurep 'xemacs)
72 ;    (require 'byte-optimize)
73 ;  (require 'byte-opt))
74 ;(defun byte-optimize-inline-handler (form)
75 ;  "byte-optimize-handler for the `inline' special-form."
76 ;  (cons 'progn (cdr form)))
77 ;(defalias 'byte-compile-file-form-defsubst 'byte-compile-file-form-defun)
78
79 (when (and (not (featurep 'xemacs))
80            (= emacs-major-version 21)
81            (= emacs-minor-version 3)
82            (condition-case code
83                (let ((byte-compile-error-on-warn t))
84                  (byte-optimize-form (quote (pop x)) t)
85                  nil)
86              (error (string-match "called for effect"
87                                   (error-message-string code)))))
88   (defadvice byte-optimize-form-code-walker (around silence-warn-for-pop
89                                                     (form for-effect)
90                                                     activate)
91     "Silence the warning \"...called for effect\" for the `pop' form.
92 It is effective only when the `pop' macro is defined by cl.el rather
93 than subr.el."
94     (let (tmp)
95       (if (and (eq (car-safe form) 'car)
96                for-effect
97                (setq tmp (get 'car 'side-effect-free))
98                (not byte-compile-delete-errors)
99                (not (eq tmp 'error-free))
100                (eq (car-safe (cadr form)) 'prog1)
101                (let ((var (cadr (cadr form)))
102                      (last (nth 2 (cadr form))))
103                  (and (symbolp var)
104                       (null (nthcdr 3 (cadr form)))
105                       (eq (car-safe last) 'setq)
106                       (eq (cadr last) var)
107                       (eq (car-safe (nth 2 last)) 'cdr)
108                       (eq (cadr (nth 2 last)) var))))
109           (progn
110             (put 'car 'side-effect-free 'error-free)
111             (unwind-protect
112                 ad-do-it
113               (put 'car 'side-effect-free tmp)))
114         ad-do-it))))
115
116 (when (and (not (featurep 'xemacs))
117            (byte-optimize-form '(and (> 0 1) foo) t))
118   (defadvice byte-optimize-form-code-walker
119     (around fix-bug-in-and/or-forms (form for-effect) activate)
120     "Optimize the rest of the and/or forms.
121 It has been fixed in XEmacs before releasing 21.4 and also has been
122 fixed in Emacs after 21.3."
123     (if (and for-effect (memq (car-safe form) '(and or)))
124         (let ((fn (car form))
125               (backwards (reverse (cdr form))))
126           (while (and backwards
127                       (null (setcar backwards
128                                     (byte-optimize-form (car backwards) t))))
129             (setq backwards (cdr backwards)))
130           (if (and (cdr form) (null backwards))
131               (byte-compile-log
132                "  all subforms of %s called for effect; deleted" form))
133           (when backwards
134             (setcdr backwards
135                     (mapcar 'byte-optimize-form (cdr backwards))))
136           (setq ad-return-value (cons fn (nreverse backwards))))
137       ad-do-it)))
138
139 (when (and (featurep 'xemacs)
140            (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
141              (modify-syntax-entry ?= " " table)
142              (with-temp-buffer
143                (with-syntax-table table
144                  (insert "foo=bar")
145                  (goto-char (point-min))
146                  (forward-sexp 1)
147                  (eolp)))))
148   ;; The original `with-syntax-table' uses `copy-syntax-table' which
149   ;; doesn't seem to copy modified syntax entries in XEmacs 21.5.
150   (defmacro with-syntax-table (syntab &rest body)
151     "Evaluate BODY with the SYNTAB as the current syntax table."
152     `(let ((stab (syntax-table)))
153        (unwind-protect
154            (progn
155              ;;(set-syntax-table (copy-syntax-table ,syntab))
156              (set-syntax-table ,syntab)
157              ,@body)
158          (set-syntax-table stab)))))
159
160 (push srcdir load-path)
161 (load (expand-file-name "lpath.el" srcdir) nil t)
162
163 (defalias 'device-sound-enabled-p 'ignore)
164 (defalias 'play-sound-file 'ignore)
165 (defalias 'nndb-request-article 'ignore)
166 (defalias 'efs-re-read-dir 'ignore)
167 (defalias 'ange-ftp-re-read-dir 'ignore)
168 (defalias 'define-mail-user-agent 'ignore)
169
170 (eval-and-compile
171   (unless (featurep 'xemacs)
172     (defalias 'get-popup-menu-response 'ignore)
173     (defalias 'event-object 'ignore)
174     (defalias 'x-defined-colors 'ignore)
175     (defalias 'read-color 'ignore)))
176
177 (eval-and-compile
178   (when (featurep 'xemacs)
179     (unless (fboundp 'defadvice)
180       (autoload 'defadvice "advice" nil nil 'macro))
181     (autoload 'Info-directory "info" nil t)
182     (autoload 'Info-menu "info" nil t)
183     (autoload 'annotations-at "annotations")
184     (autoload 'apropos "apropos" nil t)
185     (autoload 'apropos-command "apropos" nil t)
186     (autoload 'bbdb-complete-name "bbdb-com" nil t)
187     (autoload 'browse-url "browse-url" nil t)
188     (autoload 'customize-apropos "cus-edit" nil t)
189     (autoload 'customize-save-variable "cus-edit" nil t)
190     (autoload 'customize-variable "cus-edit" nil t)
191     (autoload 'delete-annotation "annotations")
192     (autoload 'dolist "cl-macs" nil nil 'macro)
193     (autoload 'enriched-decode "enriched")
194     (autoload 'executable-find "executable")
195     (autoload 'font-lock-fontify-buffer "font-lock" nil t)
196     (autoload 'info "info" nil t)
197     (autoload 'make-annotation "annotations")
198     (autoload 'make-display-table "disp-table")
199     (autoload 'pp "pp")
200     (autoload 'ps-despool "ps-print" nil t)
201     (autoload 'ps-spool-buffer "ps-print" nil t)
202     (autoload 'ps-spool-buffer-with-faces "ps-print" nil t)
203     (autoload 'read-passwd "passwd")
204     (autoload 'regexp-opt "regexp-opt")
205     (autoload 'reporter-submit-bug-report "reporter")
206     (if (emacs-version>= 21 5)
207         (autoload 'setenv "process" nil t)
208       (autoload 'setenv "env" nil t))
209     (autoload 'sgml-mode "psgml" nil t)
210     (autoload 'smtpmail-send-it "smtpmail")
211     (autoload 'sort-numeric-fields "sort" nil t)
212     (autoload 'sort-subr "sort")
213     (autoload 'trace-function-background "trace" nil t)
214     (autoload 'w3-do-setup "w3")
215     (autoload 'w3-prepare-buffer "w3-display")
216     (autoload 'w3-region "w3-display" nil t)
217     (defalias 'frame-char-height 'frame-height)
218     (defalias 'frame-char-width 'frame-width)
219     (defalias 'frame-parameter 'frame-property)
220     (defalias 'make-overlay 'ignore)
221     (defalias 'overlay-end 'ignore)
222     (defalias 'overlay-get 'ignore)
223     (defalias 'overlay-put 'ignore)
224     (defalias 'overlay-start 'ignore)
225     (defalias 'overlays-in 'ignore)
226     (defalias 'replace-dehighlight 'ignore)
227     (defalias 'replace-highlight 'ignore)
228     (defalias 'run-with-idle-timer 'ignore)
229     (defalias 'w3-coding-system-for-mime-charset 'ignore)))
230
231 (defun dgnushack-compile-verbosely ()
232   "Call dgnushack-compile with warnings ENABLED.  If you are compiling
233 patches to gnus, you should consider modifying make.bat to call
234 dgnushack-compile-verbosely.  All other users should continue to use
235 dgnushack-compile."
236   (dgnushack-compile t))
237
238 (defun dgnushack-compile (&optional warn)
239   ;;(setq byte-compile-dynamic t)
240   (unless warn
241     (setq byte-compile-warnings
242           '(free-vars unresolved callargs redefine)))
243   (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
244         ;;(byte-compile-generate-call-tree t)
245         file elc)
246     ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
247     ;; installed.
248     (when (featurep 'xemacs)
249       (setq gnus-xmas-glyph-directory "dummy"))
250     (dolist (file '("dgnushack.el" "lpath.el"))
251       (setq files (delete file files)))
252     (when (featurep 'base64)
253       (setq files (delete "base64.el" files)))
254     (condition-case code
255         (require 'w3-parse)
256       (error
257        (message "No w3: %s %s" (cadr code) (or (locate-library "w3-parse") ""))
258        (dolist (file '("nnultimate.el" "webmail.el" "nnwfm.el"))
259          (setq files (delete file files)))))
260     (condition-case code
261         (require 'mh-e)
262       (error
263        (message "No mh-e: %s %s" (cadr code) (or (locate-library "mh-e") ""))
264        (setq files (delete "gnus-mh.el" files))))
265     (condition-case code
266         (require 'xml)
267       (error
268        (message "No xml: %s %s" (cadr code) (or (locate-library "xml") ""))
269        (setq files (delete "nnrss.el" files))))
270     (dolist (file
271              (if (featurep 'xemacs)
272                  '("md5.el")
273                '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el"
274                  "run-at-time.el")))
275       (setq files (delete file files)))
276
277     (dolist (file files)
278       (setq file (expand-file-name file srcdir))
279       (when (and (file-exists-p
280                   (setq elc (concat (file-name-nondirectory file) "c")))
281                  (file-newer-than-file-p file elc))
282         (delete-file elc)))
283
284     (while (setq file (pop files))
285       (setq file (expand-file-name file srcdir))
286       (when (or (not (file-exists-p
287                       (setq elc (concat (file-name-nondirectory file) "c"))))
288                 (file-newer-than-file-p file elc))
289         (ignore-errors
290           (byte-compile-file file))))))
291
292 (defun dgnushack-recompile ()
293   (require 'gnus)
294   (byte-recompile-directory "." 0))
295
296 (defvar dgnushack-gnus-load-file
297   (if (featurep 'xemacs)
298       (expand-file-name "auto-autoloads.el")
299     (expand-file-name "gnus-load.el")))
300
301 (defvar dgnushack-cus-load-file 
302   (if (featurep 'xemacs)
303       (expand-file-name "custom-load.el")
304     (expand-file-name "cus-load.el")))
305
306 (defun dgnushack-make-cus-load ()
307   (load "cus-dep")
308   (let ((cusload-base-file dgnushack-cus-load-file))
309     (if (fboundp 'custom-make-dependencies)
310         (custom-make-dependencies)
311       (Custom-make-dependencies))
312     (when (featurep 'xemacs)
313       (message "Compiling %s..." dgnushack-cus-load-file)
314       (byte-compile-file dgnushack-cus-load-file))))
315
316 (defun dgnushack-make-auto-load ()
317   (require 'autoload)
318   (unless (make-autoload '(define-derived-mode child parent name
319                             "docstring" body)
320                          "file")
321     (defadvice make-autoload (around handle-define-derived-mode activate)
322       "Handle `define-derived-mode'."
323       (if (eq (car-safe (ad-get-arg 0)) 'define-derived-mode)
324           (setq ad-return-value
325                 (list 'autoload
326                       (list 'quote (nth 1 (ad-get-arg 0)))
327                       (ad-get-arg 1)
328                       (nth 4 (ad-get-arg 0))
329                       t nil))
330         ad-do-it))
331     (put 'define-derived-mode 'doc-string-elt 3))
332   (let ((generated-autoload-file dgnushack-gnus-load-file)
333         (make-backup-files nil)
334         (autoload-package-name "gnus"))
335     (if (featurep 'xemacs)
336         (if (file-exists-p generated-autoload-file)
337             (delete-file generated-autoload-file))
338       (with-temp-file generated-autoload-file
339         (insert ?\014)))
340     (batch-update-autoloads)))
341
342 (defun dgnushack-make-load ()
343   (unless (featurep 'xemacs)
344     (message "Generating %s..." dgnushack-gnus-load-file)
345     (with-temp-file dgnushack-gnus-load-file
346       (insert-file-contents dgnushack-cus-load-file)
347       (delete-file dgnushack-cus-load-file)
348       (goto-char (point-min))
349       (search-forward ";;; Code:")
350       (forward-line)
351       (delete-region (point-min) (point))
352       (insert "\
353 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
354 ;;
355 ;;; Code:
356 ")
357       (goto-char (point-max))
358       (if (search-backward "custom-versions-load-alist" nil t)
359           (forward-line -1)
360         (forward-line -1)
361         (while (eq (char-after) ?\;)
362           (forward-line -1))
363         (forward-line))
364       (delete-region (point) (point-max))
365       (insert "\n")
366       ;; smiley-* are duplicated. Remove them all.
367       (let ((point (point)))
368         (insert-file-contents dgnushack-gnus-load-file)
369         (goto-char point)
370         (while (search-forward "smiley-" nil t)
371           (beginning-of-line)
372           (if (looking-at "(autoload ")
373               (delete-region (point) (progn (forward-sexp) (point)))
374             (forward-line))))
375       ;;
376       (goto-char (point-max))
377       (when (search-backward "\n(provide " nil t)
378         (forward-line -1)
379         (delete-region (point) (point-max)))
380       (insert "\
381
382 \(provide 'gnus-load)
383
384 ;;; Local Variables:
385 ;;; version-control: never
386 ;;; no-byte-compile: t
387 ;;; no-update-autoloads: t
388 ;;; End:
389 ;;; gnus-load.el ends here
390 ")
391       ))
392   (message "Compiling %s..." dgnushack-gnus-load-file)
393   (byte-compile-file dgnushack-gnus-load-file)
394   (when (featurep 'xemacs)
395     (message "Creating dummy gnus-load.el...")
396     (with-temp-file (expand-file-name "gnus-load.el")
397       (insert "\
398
399 \(provide 'gnus-load)
400
401 ;;; Local Variables:
402 ;;; version-control: never
403 ;;; no-byte-compile: t
404 ;;; no-update-autoloads: t
405 ;;; End:
406 ;;; gnus-load.el ends here"))))
407
408
409 ;;; dgnushack.el ends here