* (merge, copy-list): Remove compiler macros.
[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
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 ;; Define compiler macros for the functions provided by cl in old Emacsen.
52 (unless (featurep 'xemacs)
53   (define-compiler-macro butlast (&whole form x &optional n)
54     (if (>= emacs-major-version 21)
55         form
56       (if n
57           `(let ((x ,x)
58                  (n ,n))
59              (if (and n (<= n 0))
60                  x
61                (let ((m (length x)))
62                  (or n (setq n 1))
63                  (and (< n m)
64                       (progn
65                         (if (> n 0)
66                             (progn
67                               (setq x (copy-sequence x))
68                               (setcdr (nthcdr (- (1- m) n) x) nil)))
69                         x)))))
70         `(let* ((x ,x)
71                 (m (length x)))
72            (and (< 1 m)
73                 (progn
74                   (setq x (copy-sequence x))
75                   (setcdr (nthcdr (- m 2) x) nil)
76                   x))))))
77
78   (define-compiler-macro remove (&whole form item seq)
79     (if (>= emacs-major-version 21)
80         form
81       `(delete ,item (copy-sequence ,seq)))))
82
83 ;; If we are building w3 in a different directory than the source
84 ;; directory, we must read *.el from source directory and write *.elc
85 ;; into the building directory.  For that, we define this function
86 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
87 (defun byte-compile-dest-file (filename)
88   "Convert an Emacs Lisp source file name to a compiled file name.
89  In addition, remove directory name part from FILENAME."
90   (setq filename (byte-compiler-base-file-name filename))
91   (setq filename (file-name-sans-versions filename))
92   (setq filename (file-name-nondirectory filename))
93   (if (memq system-type '(win32 w32 mswindows windows-nt))
94       (setq filename (downcase filename)))
95   (cond ((eq system-type 'vax-vms)
96          (concat (substring filename 0 (string-match ";" filename)) "c"))
97         ((string-match emacs-lisp-file-regexp filename)
98          (concat (substring filename 0 (match-beginning 0)) ".elc"))
99         (t (concat filename ".elc"))))
100
101 (require 'bytecomp)
102 ;; To avoid having defsubsts and inlines happen.
103 ;(if (featurep 'xemacs)
104 ;    (require 'byte-optimize)
105 ;  (require 'byte-opt))
106 ;(defun byte-optimize-inline-handler (form)
107 ;  "byte-optimize-handler for the `inline' special-form."
108 ;  (cons 'progn (cdr form)))
109 ;(defalias 'byte-compile-file-form-defsubst 'byte-compile-file-form-defun)
110
111 (push srcdir load-path)
112 (load (expand-file-name "lpath.el" srcdir) nil t)
113
114 (defalias 'device-sound-enabled-p 'ignore)
115 (defalias 'play-sound-file 'ignore)
116 (defalias 'nndb-request-article 'ignore)
117 (defalias 'efs-re-read-dir 'ignore)
118 (defalias 'ange-ftp-re-read-dir 'ignore)
119 (defalias 'define-mail-user-agent 'ignore)
120
121 (eval-and-compile
122   (unless (featurep 'xemacs)
123     (defalias 'get-popup-menu-response 'ignore)
124     (defalias 'event-object 'ignore)
125     (defalias 'x-defined-colors 'ignore)
126     (defalias 'read-color 'ignore)))
127
128 (eval-and-compile
129   (when (featurep 'xemacs)
130     (autoload 'Info-directory "info" nil t)
131     (autoload 'Info-menu "info" nil t)
132     (autoload 'annotations-at "annotations")
133     (autoload 'apropos "apropos" nil t)
134     (autoload 'apropos-command "apropos" nil t)
135     (autoload 'bbdb-complete-name "bbdb-com" nil t)
136     (autoload 'browse-url "browse-url" nil t)
137     (autoload 'customize-apropos "cus-edit" nil t)
138     (autoload 'customize-save-variable "cus-edit" nil t)
139     (autoload 'customize-variable "cus-edit" nil t)
140     (autoload 'delete-annotation "annotations")
141     (autoload 'dolist "cl-macs" nil nil 'macro)
142     (autoload 'enriched-decode "enriched")
143     (autoload 'info "info" nil t)
144     (autoload 'make-annotation "annotations")
145     (autoload 'make-display-table "disp-table")
146     (autoload 'pp "pp")
147     (autoload 'ps-despool "ps-print" nil t)
148     (autoload 'ps-spool-buffer "ps-print" nil t)
149     (autoload 'ps-spool-buffer-with-faces "ps-print" nil t)
150     (autoload 'read-passwd "passwd")
151     (autoload 'regexp-opt "regexp-opt")
152     (autoload 'reporter-submit-bug-report "reporter")
153     (if (emacs-version>= 21 5)
154         (autoload 'setenv "process" nil t)
155       (autoload 'setenv "env" nil t))
156     (autoload 'smtpmail-send-it "smtpmail")
157     (autoload 'sort-numeric-fields "sort" nil t)
158     (autoload 'sort-subr "sort")
159     (autoload 'trace-function-background "trace" nil t)
160     (autoload 'w3-do-setup "w3")
161     (autoload 'w3-prepare-buffer "w3-display")
162     (autoload 'w3-region "w3-display" nil t)
163     (defalias 'frame-char-height 'frame-height)
164     (defalias 'frame-char-width 'frame-width)
165     (defalias 'frame-parameter 'frame-property)
166     (defalias 'make-overlay 'ignore)
167     (defalias 'overlay-end 'ignore)
168     (defalias 'overlay-get 'ignore)
169     (defalias 'overlay-put 'ignore)
170     (defalias 'overlay-start 'ignore)
171     (defalias 'overlays-in 'ignore)
172     (defalias 'replace-dehighlight 'ignore)
173     (defalias 'replace-highlight 'ignore)
174     (defalias 'run-with-idle-timer 'ignore)
175     (defalias 'w3-coding-system-for-mime-charset 'ignore)))
176
177 (defun dgnushack-compile (&optional warn)
178   ;;(setq byte-compile-dynamic t)
179   (unless warn
180     (setq byte-compile-warnings
181           '(free-vars unresolved callargs redefine)))
182   (unless (locate-library "cus-edit")
183     (error "You do not seem to have Custom installed.
184 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
185 You also then need to add the following to the lisp/dgnushack.el file:
186
187      (push \"~/lisp/custom\" load-path)
188
189 Modify to suit your needs."))
190   (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
191         ;;(byte-compile-generate-call-tree t)
192         file elc)
193     ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
194     ;; installed.
195     (when (featurep 'xemacs)
196       (setq gnus-xmas-glyph-directory "dummy"))
197     (dolist (file '("dgnushack.el" "lpath.el"))
198       (setq files (delete file files)))
199     (when (featurep 'base64)
200       (setq files (delete "base64.el" files)))
201     (condition-case code
202         (require 'w3-parse)
203       (error
204        (message "No w3: %s %s" (cadr code) (or (locate-library "w3-parse") ""))
205        (dolist (file '("nnultimate.el" "webmail.el" "nnwfm.el"))
206          (setq files (delete file files)))))
207     (condition-case code
208         (require 'mh-e)
209       (error
210        (message "No mh-e: %s %s" (cadr code) (or (locate-library "mh-e") ""))
211        (setq files (delete "gnus-mh.el" files))))
212     (condition-case code
213         (require 'xml)
214       (error
215        (message "No xml: %s %s" (cadr code) (or (locate-library "xml") ""))
216        (setq files (delete "nnrss.el" files))))
217     (dolist (file
218              (if (featurep 'xemacs)
219                  '("md5.el")
220                '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el")))
221       (setq files (delete file files)))
222
223     (dolist (file files)
224       (setq file (expand-file-name file srcdir))
225       (when (and (file-exists-p
226                   (setq elc (concat (file-name-nondirectory file) "c")))
227                  (file-newer-than-file-p file elc))
228         (delete-file elc)))
229
230     (while (setq file (pop files))
231       (setq file (expand-file-name file srcdir))
232       (when (or (not (file-exists-p
233                       (setq elc (concat (file-name-nondirectory file) "c"))))
234                 (file-newer-than-file-p file elc))
235         (ignore-errors
236           (byte-compile-file file))))))
237
238 (defun dgnushack-recompile ()
239   (require 'gnus)
240   (byte-recompile-directory "." 0))
241
242 (defvar dgnushack-gnus-load-file (expand-file-name "gnus-load.el"))
243 (defvar dgnushack-cus-load-file (expand-file-name "cus-load.el"))
244
245 (defun dgnushack-make-cus-load ()
246   (load "cus-dep")
247   (let ((cusload-base-file dgnushack-cus-load-file))
248     (if (fboundp 'custom-make-dependencies)
249         (custom-make-dependencies)
250       (Custom-make-dependencies))))
251
252 (defun dgnushack-make-auto-load ()
253   (require 'autoload)
254   (unless (make-autoload '(define-derived-mode child parent name
255                             "docstring" body)
256                          "file")
257     (defadvice make-autoload (around handle-define-derived-mode activate)
258       "Handle `define-derived-mode'."
259       (if (eq (car-safe (ad-get-arg 0)) 'define-derived-mode)
260           (setq ad-return-value
261                 (list 'autoload
262                       (list 'quote (nth 1 (ad-get-arg 0)))
263                       (ad-get-arg 1)
264                       (nth 4 (ad-get-arg 0))
265                       t nil))
266         ad-do-it))
267     (put 'define-derived-mode 'doc-string-elt 3))
268   (let ((generated-autoload-file dgnushack-gnus-load-file)
269         (make-backup-files nil)
270         (autoload-package-name "gnus"))
271     (if (featurep 'xemacs)
272         (if (file-exists-p generated-autoload-file)
273             (delete-file generated-autoload-file))
274       (with-temp-file generated-autoload-file
275         (insert ?\014)))
276     (batch-update-autoloads)))
277
278 (defun dgnushack-make-load ()
279   (message (format "Generating %s..." dgnushack-gnus-load-file))
280   (with-temp-file dgnushack-gnus-load-file
281     (insert-file-contents dgnushack-cus-load-file)
282     (delete-file dgnushack-cus-load-file)
283     (goto-char (point-min))
284     (search-forward ";;; Code:")
285     (forward-line)
286     (delete-region (point-min) (point))
287     (insert "\
288 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
289 ;;
290 ;;; Code:
291 ")
292     (goto-char (point-max))
293     (if (search-backward "custom-versions-load-alist" nil t)
294         (forward-line -1)
295       (forward-line -1)
296       (while (eq (char-after) ?\;)
297         (forward-line -1))
298       (forward-line))
299     (delete-region (point) (point-max))
300     (insert "\n")
301     ;; smiley-* are duplicated. Remove them all.
302     (let ((point (point)))
303       (insert-file-contents dgnushack-gnus-load-file)
304       (goto-char point)
305       (while (search-forward "smiley-" nil t)
306         (beginning-of-line)
307         (if (looking-at "(autoload ")
308             (delete-region (point) (progn (forward-sexp) (point)))
309           (forward-line))))
310     ;;
311     (goto-char (point-max))
312     (when (search-backward "\n(provide " nil t)
313       (forward-line -1)
314       (delete-region (point) (point-max)))
315     (insert "\
316
317 \(provide 'gnus-load)
318
319 ;;; Local Variables:
320 ;;; version-control: never
321 ;;; no-byte-compile: t
322 ;;; no-update-autoloads: t
323 ;;; End:
324 ;;; gnus-load.el ends here
325 ")
326     ;; Workaround the bug in some version of XEmacs.
327     (when (featurep 'xemacs)
328       (condition-case nil
329           (require 'cus-load)
330         (error nil))
331       (goto-char (point-min))
332       (when (and (fboundp 'custom-add-loads)
333                  (not (search-forward "\n(autoload 'custom-add-loads " nil t)))
334         (search-forward "\n;;; Code:" nil t)
335         (forward-line 1)
336         (insert "\n(autoload 'custom-add-loads \"cus-load\")\n"))))
337   (message (format "Compiling %s..." dgnushack-gnus-load-file))
338   (byte-compile-file dgnushack-gnus-load-file))
339
340 ;;; dgnushack.el ends here