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.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news, path
9 ;; This file is part of GNU Emacs.
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)
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.
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.
30 (defalias 'facep 'ignore)
34 (defvar srcdir (or (getenv "srcdir") "."))
36 (defun my-getenv (str)
37 (let ((val (getenv str)))
38 (if (equal val "no") nil val)))
40 (if (my-getenv "lispdir")
41 (push (my-getenv "lispdir") load-path))
43 (push (or (my-getenv "URLDIR") (expand-file-name "../../url/lisp/" srcdir))
46 (push (or (my-getenv "W3DIR") (expand-file-name "../../w3/lisp/" srcdir))
49 ;(push "/usr/share/emacs/site-lisp" load-path)
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"))))
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)
79 (when (and (not (featurep 'xemacs))
80 (= emacs-major-version 21)
81 (= emacs-minor-version 3)
83 (let ((byte-compile-error-on-warn t))
84 (byte-optimize-form (quote (pop x)) t)
86 (error (string-match "called for effect"
87 (error-message-string code)))))
88 (defadvice byte-optimize-form-code-walker (around silence-warn-for-pop
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
95 (if (and (eq (car-safe form) 'car)
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))))
104 (null (nthcdr 3 (cadr form)))
105 (eq (car-safe last) 'setq)
107 (eq (car-safe (nth 2 last)) 'cdr)
108 (eq (cadr (nth 2 last)) var))))
110 (put 'car 'side-effect-free 'error-free)
113 (put 'car 'side-effect-free tmp)))
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))
132 " all subforms of %s called for effect; deleted" form))
135 (mapcar 'byte-optimize-form (cdr backwards))))
136 (setq ad-return-value (cons fn (nreverse backwards))))
139 (when (and (featurep 'xemacs)
140 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
141 (modify-syntax-entry ?= " " table)
143 (with-syntax-table table
145 (goto-char (point-min))
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)))
155 ;;(set-syntax-table (copy-syntax-table ,syntab))
156 (set-syntax-table ,syntab)
158 (set-syntax-table stab)))))
160 (push srcdir load-path)
161 (load (expand-file-name "lpath.el" srcdir) nil t)
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)
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)))
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")
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 'smtpmail-send-it "smtpmail")
210 (autoload 'sort-numeric-fields "sort" nil t)
211 (autoload 'sort-subr "sort")
212 (autoload 'trace-function-background "trace" nil t)
213 (autoload 'w3-do-setup "w3")
214 (autoload 'w3-prepare-buffer "w3-display")
215 (autoload 'w3-region "w3-display" nil t)
216 (defalias 'frame-char-height 'frame-height)
217 (defalias 'frame-char-width 'frame-width)
218 (defalias 'frame-parameter 'frame-property)
219 (defalias 'make-overlay 'ignore)
220 (defalias 'overlay-end 'ignore)
221 (defalias 'overlay-get 'ignore)
222 (defalias 'overlay-put 'ignore)
223 (defalias 'overlay-start 'ignore)
224 (defalias 'overlays-in 'ignore)
225 (defalias 'replace-dehighlight 'ignore)
226 (defalias 'replace-highlight 'ignore)
227 (defalias 'run-with-idle-timer 'ignore)
228 (defalias 'w3-coding-system-for-mime-charset 'ignore)))
230 (defun dgnushack-compile-verbosely ()
231 "Call dgnushack-compile with warnings ENABLED. If you are compiling
232 patches to gnus, you should consider modifying make.bat to call
233 dgnushack-compile-verbosely. All other users should continue to use
235 (dgnushack-compile t))
237 (defun dgnushack-compile (&optional warn)
238 ;;(setq byte-compile-dynamic t)
240 (setq byte-compile-warnings
241 '(free-vars unresolved callargs redefine)))
242 (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
243 ;;(byte-compile-generate-call-tree t)
245 ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
247 (when (featurep 'xemacs)
248 (setq gnus-xmas-glyph-directory "dummy"))
249 (dolist (file '("dgnushack.el" "lpath.el"))
250 (setq files (delete file files)))
251 (when (featurep 'base64)
252 (setq files (delete "base64.el" files)))
256 (message "No w3: %s %s" (cadr code) (or (locate-library "w3-parse") ""))
257 (dolist (file '("nnultimate.el" "webmail.el" "nnwfm.el"))
258 (setq files (delete file files)))))
262 (message "No mh-e: %s %s" (cadr code) (or (locate-library "mh-e") ""))
263 (setq files (delete "gnus-mh.el" files))))
267 (message "No xml: %s %s" (cadr code) (or (locate-library "xml") ""))
268 (setq files (delete "nnrss.el" files))))
270 (if (featurep 'xemacs)
272 '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el"
274 (setq files (delete file files)))
277 (setq file (expand-file-name file srcdir))
278 (when (and (file-exists-p
279 (setq elc (concat (file-name-nondirectory file) "c")))
280 (file-newer-than-file-p file elc))
283 (while (setq file (pop files))
284 (setq file (expand-file-name file srcdir))
285 (when (or (not (file-exists-p
286 (setq elc (concat (file-name-nondirectory file) "c"))))
287 (file-newer-than-file-p file elc))
289 (byte-compile-file file))))))
291 (defun dgnushack-recompile ()
293 (byte-recompile-directory "." 0))
295 (defvar dgnushack-gnus-load-file
296 (if (featurep 'xemacs)
297 (expand-file-name "auto-autoloads.el")
298 (expand-file-name "gnus-load.el")))
300 (defvar dgnushack-cus-load-file
301 (if (featurep 'xemacs)
302 (expand-file-name "custom-load.el")
303 (expand-file-name "cus-load.el")))
305 (defun dgnushack-make-cus-load ()
307 (let ((cusload-base-file dgnushack-cus-load-file))
308 (if (fboundp 'custom-make-dependencies)
309 (custom-make-dependencies)
310 (Custom-make-dependencies))
311 (when (featurep 'xemacs)
312 (message "Compiling %s..." dgnushack-cus-load-file)
313 (byte-compile-file dgnushack-cus-load-file))))
315 (defun dgnushack-make-auto-load ()
317 (unless (make-autoload '(define-derived-mode child parent name
320 (defadvice make-autoload (around handle-define-derived-mode activate)
321 "Handle `define-derived-mode'."
322 (if (eq (car-safe (ad-get-arg 0)) 'define-derived-mode)
323 (setq ad-return-value
325 (list 'quote (nth 1 (ad-get-arg 0)))
327 (nth 4 (ad-get-arg 0))
330 (put 'define-derived-mode 'doc-string-elt 3))
331 (let ((generated-autoload-file dgnushack-gnus-load-file)
332 (make-backup-files nil)
333 (autoload-package-name "gnus"))
334 (if (featurep 'xemacs)
335 (if (file-exists-p generated-autoload-file)
336 (delete-file generated-autoload-file))
337 (with-temp-file generated-autoload-file
339 (batch-update-autoloads)))
341 (defun dgnushack-make-load ()
342 (unless (featurep 'xemacs)
343 (message "Generating %s..." dgnushack-gnus-load-file)
344 (with-temp-file dgnushack-gnus-load-file
345 (insert-file-contents dgnushack-cus-load-file)
346 (delete-file dgnushack-cus-load-file)
347 (goto-char (point-min))
348 (search-forward ";;; Code:")
350 (delete-region (point-min) (point))
352 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
356 (goto-char (point-max))
357 (if (search-backward "custom-versions-load-alist" nil t)
360 (while (eq (char-after) ?\;)
363 (delete-region (point) (point-max))
365 ;; smiley-* are duplicated. Remove them all.
366 (let ((point (point)))
367 (insert-file-contents dgnushack-gnus-load-file)
369 (while (search-forward "smiley-" nil t)
371 (if (looking-at "(autoload ")
372 (delete-region (point) (progn (forward-sexp) (point)))
375 (goto-char (point-max))
376 (when (search-backward "\n(provide " nil t)
378 (delete-region (point) (point-max)))
381 \(provide 'gnus-load)
384 ;;; version-control: never
385 ;;; no-byte-compile: t
386 ;;; no-update-autoloads: t
388 ;;; gnus-load.el ends here
391 (message "Compiling %s..." dgnushack-gnus-load-file)
392 (byte-compile-file dgnushack-gnus-load-file)
393 (when (featurep 'xemacs)
394 (message "Creating dummy gnus-load.el...")
395 (with-temp-file (expand-file-name "gnus-load.el")
398 \(provide 'gnus-load)
401 ;;; version-control: never
402 ;;; no-byte-compile: t
403 ;;; no-update-autoloads: t
405 ;;; gnus-load.el ends here"))))
408 ;;; dgnushack.el ends here