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