Use macro from w3. For details see ChangeLog.
[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
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 (fset 'facep 'ignore)
31
32 (require 'cl)
33
34 (push (or (getenv "lispdir") 
35           "/usr/share/emacs/site-lisp")
36       load-path)
37 (push (or (getenv "W3DIR") (expand-file-name "../../w3/lisp/" srcdir)) 
38       load-path)
39
40 (unless (featurep 'xemacs)
41   (define-compiler-macro last (&whole form x &optional n)
42     (if (and (fboundp 'last)
43              (subrp (symbol-function 'last)))
44         form
45       (if n
46           `(let* ((x ,x)
47                   (n ,n)
48                   (m 0)
49                   (p x))
50              (while (consp p)
51                (incf m)
52                (pop p))
53              (if (<= n 0)
54                  p
55                (if (< n m)
56                    (nthcdr (- m n) x)
57                  x)))
58         `(let ((x ,x))
59            (while (consp (cdr x))
60              (pop x))
61            x))))
62
63   (define-compiler-macro mapcon (&whole form fn seq &rest rest)
64     (if (and (fboundp 'mapcon)
65              (subrp (symbol-function 'mapcon)))
66         form
67       (if rest
68           `(let (res
69                  (args (list ,seq ,@rest))
70                  p)
71              (while (not (memq nil args))
72                (push (apply ,fn args) res)
73                (setq p args)
74                (while p
75                  (setcar p (cdr (pop p)))
76                  ))
77              (apply (function nconc) (nreverse res)))
78         `(let (res
79                (arg ,seq))
80            (while arg
81              (push (funcall ,fn arg) res)
82              (setq arg (cdr arg)))
83            (apply (function nconc) (nreverse res))))))
84
85   (define-compiler-macro member-if (&whole form pred list)
86     (if (and (fboundp 'member-if)
87              (subrp (symbol-function 'member-if)))
88         form
89       `(let ((fn ,pred)
90              (seq ,list))
91          (while (and seq
92                      (not (funcall fn (car seq))))
93            (pop seq))
94          seq)))
95
96   (define-compiler-macro union (&whole form list1 list2)
97     (if (and (fboundp 'union)
98              (subrp (symbol-function 'union)))
99         form
100       `(let ((a ,list1)
101              (b ,list2))
102          (cond ((null a) b)
103                ((null b) a)
104                ((equal a b) a)
105                (t
106                 (or (>= (length a) (length b))
107                     (setq a (prog1 b (setq b a))))
108                 (while b
109                   (or (memq (car b) a)
110                       (push (car b) a))
111                   (pop b))
112                 a)))))
113   )
114
115 ;; If we are building w3 in a different directory than the source
116 ;; directory, we must read *.el from source directory and write *.elc
117 ;; into the building directory.  For that, we define this function
118 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
119 (defun byte-compile-dest-file (filename)
120   "Convert an Emacs Lisp source file name to a compiled file name.
121  In addition, remove directory name part from FILENAME."
122   (setq filename (byte-compiler-base-file-name filename))
123   (setq filename (file-name-sans-versions filename))
124   (setq filename (file-name-nondirectory filename))
125   (if (memq system-type '(win32 w32 mswindows windows-nt))
126       (setq filename (downcase filename)))
127   (cond ((eq system-type 'vax-vms)
128          (concat (substring filename 0 (string-match ";" filename)) "c"))
129         ((string-match emacs-lisp-file-regexp filename)
130          (concat (substring filename 0 (match-beginning 0)) ".elc"))
131         (t (concat filename ".elc"))))
132
133 (require 'bytecomp)
134
135 (defvar srcdir (or (getenv "srcdir") "."))
136
137 (push srcdir load-path)
138 ;(push "/usr/share/emacs/site-lisp" load-path)
139 (load (expand-file-name "lpath.el" srcdir) nil t)
140
141 (defalias 'device-sound-enabled-p 'ignore)
142 (defalias 'play-sound-file 'ignore)
143 (defalias 'nndb-request-article 'ignore)
144 (defalias 'efs-re-read-dir 'ignore)
145 (defalias 'ange-ftp-re-read-dir 'ignore)
146 (defalias 'define-mail-user-agent 'ignore)
147
148 (eval-and-compile
149   (unless (string-match "XEmacs" emacs-version)
150     (fset 'get-popup-menu-response 'ignore)
151     (fset 'event-object 'ignore)
152     (fset 'x-defined-colors 'ignore)
153     (fset 'read-color 'ignore)))
154
155 (defun dgnushack-compile (&optional warn)
156   ;;(setq byte-compile-dynamic t)
157   (unless warn
158     (setq byte-compile-warnings
159           '(free-vars unresolved callargs redefine)))
160   (unless (locate-library "cus-edit")
161     (error "You do not seem to have Custom installed.
162 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
163 You also then need to add the following to the lisp/dgnushack.el file:
164
165      (push \"~/lisp/custom\" load-path)
166
167 Modify to suit your needs."))
168   (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
169         (xemacs (string-match "XEmacs" emacs-version))
170         ;;(byte-compile-generate-call-tree t)
171         file elc)
172     (condition-case ()
173         (require 'w3-forms)
174       (error
175        (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
176                        "nnslashdot.el" "nnwarchive.el" "webmail.el"))
177          (setq files (delete file files)))))
178     (while (setq file (pop files))
179       (setq file (expand-file-name file srcdir))
180       (when (or (and (not xemacs)
181                      (not (member (file-name-nondirectory file)
182                                   '("gnus-xmas.el" "gnus-picon.el"
183                                     "messagexmas.el" "nnheaderxm.el"
184                                     "smiley.el" "x-overlay.el"))))
185                 (and xemacs
186                      (not (member file '("md5.el")))))
187         (when (or (not (file-exists-p (setq elc (concat file "c"))))
188                   (file-newer-than-file-p file elc))
189           (ignore-errors
190             (byte-compile-file file)))))))
191
192 (defun dgnushack-recompile ()
193   (require 'gnus)
194   (byte-recompile-directory "." 0))
195
196 ;;; dgnushack.el ends here
197