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