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