* gnus-msg.el (gnus-configure-posting-styles): Allow nil values to
[gnus] / lisp / dgnushack.el
1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994-2000 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Version: 4.19
6 ;; Keywords: news, path
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (fset 'facep 'ignore)
30
31 (require 'cl)
32
33 (push "/usr/share/emacs/site-lisp" load-path)
34
35 (unless (featurep 'xemacs)
36   (define-compiler-macro last (&whole form x &optional n)
37     (if (and (fboundp 'last)
38              (subrp (symbol-function 'last)))
39         form
40       (if n
41           `(let* ((x ,x)
42                   (n ,n)
43                   (m 0)
44                   (p x))
45              (while (consp p)
46                (incf m)
47                (pop p))
48              (if (<= n 0)
49                  p
50                (if (< n m)
51                    (nthcdr (- m n) x)
52                  x)))
53         `(let ((x ,x))
54            (while (consp (cdr x))
55              (pop x))
56            x))))
57
58   (define-compiler-macro mapcon (&whole form fn seq &rest rest)
59     (if (and (fboundp 'mapcon)
60              (subrp (symbol-function 'mapcon)))
61         form
62       (if rest
63           `(let (res
64                  (args (list ,seq ,@rest))
65                  p)
66              (while (not (memq nil args))
67                (push (apply ,fn args) res)
68                (setq p args)
69                (while p
70                  (setcar p (cdr (pop p)))
71                  ))
72              (apply (function nconc) (nreverse res)))
73         `(let (res
74                (arg ,seq))
75            (while arg
76              (push (funcall ,fn arg) res)
77              (setq arg (cdr arg)))
78            (apply (function nconc) (nreverse res))))))
79
80   (define-compiler-macro member-if (&whole form pred list)
81     (if (and (fboundp 'member-if)
82              (subrp (symbol-function 'member-if)))
83         form
84       `(let ((fn ,pred)
85              (seq ,list))
86          (while (and seq
87                      (not (funcall fn (car seq))))
88            (pop seq))
89          seq)))
90
91   (define-compiler-macro union (&whole form list1 list2)
92     (if (and (fboundp 'union)
93              (subrp (symbol-function 'union)))
94         form
95       `(let ((a ,list1)
96              (b ,list2))
97          (cond ((null a) b)
98                ((null b) a)
99                ((equal a b) a)
100                (t
101                 (or (>= (length a) (length b))
102                     (setq a (prog1 b (setq b a))))
103                 (while b
104                   (or (memq (car b) a)
105                       (push (car b) a))
106                   (pop b))
107                 a)))))
108   )
109
110 ;; If we are building w3 in a different directory than the source
111 ;; directory, we must read *.el from source directory and write *.elc
112 ;; into the building directory.  For that, we define this function
113 ;; before loading bytecomp.  Bytecomp doesn't overwrite this function.
114 (defun byte-compile-dest-file (filename)
115   "Convert an Emacs Lisp source file name to a compiled file name.
116  In addition, remove directory name part from FILENAME."
117   (setq filename (byte-compiler-base-file-name filename))
118   (setq filename (file-name-sans-versions filename))
119   (setq filename (file-name-nondirectory filename))
120   (if (memq system-type '(win32 w32 mswindows windows-nt))
121       (setq filename (downcase filename)))
122   (cond ((eq system-type 'vax-vms)
123          (concat (substring filename 0 (string-match ";" filename)) "c"))
124         ((string-match emacs-lisp-file-regexp filename)
125          (concat (substring filename 0 (match-beginning 0)) ".elc"))
126         (t (concat filename ".elc"))))
127
128 (require 'bytecomp)
129
130 (defvar srcdir (or (getenv "srcdir") "."))
131
132 (push srcdir load-path)
133 ;(push "/usr/share/emacs/site-lisp" load-path)
134 (load (expand-file-name "lpath.el" srcdir) nil t)
135
136 (defalias 'device-sound-enabled-p 'ignore)
137 (defalias 'play-sound-file 'ignore)
138 (defalias 'nndb-request-article 'ignore)
139 (defalias 'efs-re-read-dir 'ignore)
140 (defalias 'ange-ftp-re-read-dir 'ignore)
141 (defalias 'define-mail-user-agent 'ignore)
142
143 (eval-and-compile
144   (unless (string-match "XEmacs" emacs-version)
145     (fset 'get-popup-menu-response 'ignore)
146     (fset 'event-object 'ignore)
147     (fset 'x-defined-colors 'ignore)
148     (fset 'read-color 'ignore)))
149
150 (defun dgnushack-compile (&optional warn)
151   ;;(setq byte-compile-dynamic t)
152   (unless warn
153     (setq byte-compile-warnings
154           '(free-vars unresolved callargs redefine)))
155   (unless (locate-library "cus-edit")
156     (error "You do not seem to have Custom installed.
157 Fetch it from <URL:http://www.dina.kvl.dk/~abraham/custom/>.
158 You also then need to add the following to the lisp/dgnushack.el file:
159
160      (push \"~/lisp/custom\" load-path)
161
162 Modify to suit your needs."))
163   (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
164         (xemacs (string-match "XEmacs" emacs-version))
165         ;;(byte-compile-generate-call-tree t)
166         file elc)
167     (condition-case ()
168         (require 'w3-forms)
169       (error
170        (dolist (file '("nnweb.el" "nnlistserv.el" "nnultimate.el"
171                        "nnslashdot.el" "nnwarchive.el" "webmail.el"))
172          (setq files (delete file files)))))
173     (while (setq file (pop files))
174       (setq file (expand-file-name file srcdir))
175       (when (or (and (not xemacs)
176                      (not (member (file-name-nondirectory file)
177                                   '("gnus-xmas.el" "gnus-picon.el"
178                                     "messagexmas.el" "nnheaderxm.el"
179                                     "smiley.el" "x-overlay.el"))))
180                 (and xemacs
181                      (not (member file '("md5.el")))))
182         (when (or (not (file-exists-p (setq elc (concat file "c"))))
183                   (file-newer-than-file-p file elc))
184           (ignore-errors
185             (byte-compile-file file)))))))
186
187 (defun dgnushack-recompile ()
188   (require 'gnus)
189   (byte-recompile-directory "." 0))
190
191 ;;; dgnushack.el ends here
192