1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003,
3 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; Keywords: news, path
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
31 (defvar dgnushack-default-load-path (copy-sequence load-path))
33 (defalias 'facep 'ignore)
37 (defvar srcdir (or (getenv "srcdir") "."))
38 (defvar loaddir (and load-file-name (file-name-directory load-file-name)))
40 (defun my-getenv (str)
41 (let ((val (getenv str)))
42 (if (equal val "no") nil val)))
44 (if (my-getenv "lispdir")
45 (push (my-getenv "lispdir") load-path))
47 (push (or (my-getenv "URLDIR") (expand-file-name "../../url/lisp/" loaddir))
50 (push (or (my-getenv "W3DIR") (expand-file-name "../../w3/lisp/" loaddir))
53 ;(push "/usr/share/emacs/site-lisp" load-path)
55 ;; If we are building w3 in a different directory than the source
56 ;; directory, we must read *.el from source directory and write *.elc
57 ;; into the building directory. For that, we define this function
58 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
59 (defun byte-compile-dest-file (filename)
60 "Convert an Emacs Lisp source file name to a compiled file name.
61 In addition, remove directory name part from FILENAME."
62 (setq filename (byte-compiler-base-file-name filename))
63 (setq filename (file-name-sans-versions filename))
64 (setq filename (file-name-nondirectory filename))
65 (if (eq system-type 'windows-nt)
66 (setq filename (downcase filename)))
67 (cond ((eq system-type 'vax-vms)
68 (concat (substring filename 0 (string-match ";" filename)) "c"))
69 ((string-match emacs-lisp-file-regexp filename)
70 (concat (substring filename 0 (match-beginning 0)) ".elc"))
71 (t (concat filename ".elc"))))
74 ;; To avoid having defsubsts and inlines happen.
75 ;(if (featurep 'xemacs)
76 ; (require 'byte-optimize)
77 ; (require 'byte-opt))
78 ;(defun byte-optimize-inline-handler (form)
79 ; "byte-optimize-handler for the `inline' special-form."
80 ; (cons 'progn (cdr form)))
81 ;(defalias 'byte-compile-file-form-defsubst 'byte-compile-file-form-defun)
83 ;; Work around for an incompatibility (XEmacs 21.4 vs. 21.5), see the
86 ;; http://thread.gmane.org/gmane.emacs.gnus.general/56414
87 ;; Subject: attachment problems found but not fixed
89 ;; http://thread.gmane.org/gmane.emacs.gnus.general/56459
90 ;; Subject: Splitting mail -- XEmacs 21.4 vs 21.5
92 ;; http://thread.gmane.org/gmane.emacs.xemacs.beta/20519
93 ;; Subject: XEmacs 21.5 and Gnus fancy splitting.
95 ;; Should be fixed in XEmacs (March 2007).
96 ;; http://thread.gmane.org/gmane.emacs.xemacs.patches/8124
97 ;; When should we remove this workaround?
99 (when (and (featurep 'xemacs)
100 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
101 (modify-syntax-entry ?= " " table)
103 (with-syntax-table table
105 (goto-char (point-min))
108 ;; The original `with-syntax-table' uses `copy-syntax-table' which
109 ;; doesn't seem to copy modified syntax entries in old XEmacs 21.5.
110 (defmacro with-syntax-table (syntab &rest body)
111 "Evaluate BODY with the SYNTAB as the current syntax table."
112 `(let ((stab (syntax-table)))
115 ;;(set-syntax-table (copy-syntax-table ,syntab))
116 (set-syntax-table ,syntab)
118 (set-syntax-table stab)))))
120 (push srcdir load-path)
121 (push loaddir load-path)
122 (load (expand-file-name "lpath.el" loaddir) nil t)
124 (defalias 'device-sound-enabled-p 'ignore)
125 (defalias 'play-sound-file 'ignore)
126 (defalias 'efs-re-read-dir 'ignore)
127 (defalias 'ange-ftp-re-read-dir 'ignore)
128 (defalias 'define-mail-user-agent 'ignore)
131 (unless (featurep 'xemacs)
132 (defalias 'get-popup-menu-response 'ignore)
133 (defalias 'event-object 'ignore)
134 (autoload 'netrc-credentials "netrc")
135 (defalias 'x-defined-colors 'ignore)
136 (defalias 'read-color 'ignore)))
139 (when (featurep 'xemacs)
140 (unless (fboundp 'defadvice)
141 (autoload 'defadvice "advice" nil nil 'macro))
142 (autoload 'Info-directory "info" nil t)
143 (autoload 'Info-index "info" nil t)
144 (autoload 'Info-index-next "info" nil t)
145 (autoload 'Info-menu "info" nil t)
146 (autoload 'ad-add-advice "advice")
147 (unless (and (emacs-version>= 21 5)
148 (not (featurep 'sxemacs)))
149 ;; calendar/auto-autoloads.el provides it.
150 (autoload 'add-to-invisibility-spec "dummy"))
151 (autoload 'annotations-at "annotations")
152 (autoload 'apropos "apropos" nil t)
153 (autoload 'apropos-command "apropos" nil t)
154 (autoload 'bbdb-complete-name "bbdb-com" nil t)
155 (autoload 'browse-url "browse-url" nil t)
156 (autoload 'browse-url-of-file "browse-url" nil t)
157 (autoload 'c-mode "cc-mode" nil t)
158 (autoload 'customize-apropos "cus-edit" nil t)
159 (autoload 'customize-group "cus-edit" nil t)
160 (autoload 'customize-save-variable "cus-edit" nil t)
161 (autoload 'customize-set-variable "cus-edit" nil t)
162 (autoload 'customize-variable "cus-edit" nil t)
163 (autoload 'debug "debug" nil t)
165 (unless (locate-library "mule-ccl")
166 (autoload 'define-ccl-program "ccl" nil nil 'macro))
167 (defalias 'define-ccl-program 'ignore))
168 (autoload 'delete-annotation "annotations")
169 (autoload 'dolist "cl-macs" nil nil 'macro)
170 (autoload 'enriched-decode "enriched")
171 (autoload 'eudc-expand-inline "eudc" nil t)
172 (autoload 'executable-find "executable")
173 (autoload 'font-lock-fontify-buffer "font-lock" nil t)
174 (when (and (emacs-version>= 21 5)
175 (not (featurep 'sxemacs)))
176 (autoload 'get-display-table "disp-table")
177 (autoload 'put-display-table "disp-table"))
178 (autoload 'info "info" nil t)
179 (autoload 'mail-extract-address-components "mail-extr")
180 (autoload 'mail-fetch-field "mail-utils")
181 (autoload 'make-annotation "annotations")
182 (autoload 'make-display-table "disp-table")
183 (autoload 'pgg-snarf-keys-region "pgg" nil t)
185 (autoload 'ps-despool "ps-print" nil t)
186 (autoload 'ps-spool-buffer "ps-print" nil t)
187 (autoload 'ps-spool-buffer-with-faces "ps-print" nil t)
188 (autoload 'read-passwd "passwd")
189 (autoload 'regexp-opt "regexp-opt")
190 (autoload 'reporter-submit-bug-report "reporter")
191 (if (and (emacs-version>= 21 5)
192 (not (featurep 'sxemacs)))
193 (autoload 'setenv "process" nil t)
194 (autoload 'setenv "env" nil t))
195 (autoload 'sgml-mode "psgml" nil t)
196 (autoload 'smtpmail-send-it "smtpmail")
197 (autoload 'sort-numeric-fields "sort" nil t)
198 (autoload 'sort-subr "sort")
199 (autoload 'thing-at-point "thingatpt")
200 (autoload 'toggle-truncate-lines "view-less" nil t)
201 (autoload 'trace-function-background "trace" nil t)
202 (autoload 'unmorse-region "morse" nil t)
203 (autoload 'w3-do-setup "w3")
204 (autoload 'w3-prepare-buffer "w3-display")
205 (autoload 'w3-region "w3-display" nil t)
206 (defalias 'frame-char-height 'frame-height)
207 (defalias 'frame-char-width 'frame-width)
208 (defalias 'frame-parameter 'frame-property)
209 (defalias 'make-overlay 'ignore)
210 (defalias 'overlay-end 'ignore)
211 (defalias 'overlay-get 'ignore)
212 (defalias 'overlay-put 'ignore)
213 (defalias 'overlay-start 'ignore)
214 (defalias 'overlays-in 'ignore)
215 (defalias 'replace-dehighlight 'ignore)
216 (defalias 'replace-highlight 'ignore)
217 (defalias 'w3-coding-system-for-mime-charset 'ignore)))
219 (defun dgnushack-emacs-compile-defcustom-p ()
220 "Return non-nil if Emacs byte compiles `defcustom' forms.
221 Those Emacsen will warn against undefined variables and functions used
222 in `defcustom' forms."
223 (let ((outbuf (with-temp-buffer
224 (insert "(defcustom foo (1+ (random)) \"\" :group 'emacs)\n")
225 (byte-compile-from-buffer (current-buffer) "foo.el"))))
228 (with-current-buffer outbuf
229 (goto-char (point-min))
230 (search-forward " 'foo '(byte-code " nil t))
231 (kill-buffer outbuf)))))
233 (when (dgnushack-emacs-compile-defcustom-p)
234 (maybe-fbind '(defined-colors face-attribute))
235 (maybe-bind '(idna-program installation-directory)))
237 (defun dgnushack-compile-verbosely ()
238 "Call dgnushack-compile with warnings ENABLED. If you are compiling
239 patches to gnus, you should consider modifying make.bat to call
240 dgnushack-compile-verbosely. All other users should continue to use
242 (dgnushack-compile t))
244 (defun dgnushack-compile (&optional warn)
245 ;;(setq byte-compile-dynamic t)
247 (setq byte-compile-warnings
248 '(free-vars unresolved callargs redefine suspicious)))
249 (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
250 ;;(byte-compile-generate-call-tree t)
252 ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
254 (when (featurep 'xemacs)
255 (setq gnus-xmas-glyph-directory "dummy"))
256 (dolist (file '(".dir-locals.el" "dgnushack.el" "lpath.el"))
257 (setq files (delete file files)))
258 (when (featurep 'base64)
259 (setq files (delete "base64.el" files)))
263 (message "No w3: %s %s" (cadr code) (or (locate-library "w3-parse") ""))
264 (dolist (file '("webmail.el" "nnwfm.el"))
265 (setq files (delete file files)))))
267 ;; Under XEmacs 21.4 this loads easy-mmode.elc that provides
268 ;; the Emacs functions `propertize' and `replace-regexp-in-string'.
271 (message "No mh-e: %s %s" (cadr code) (or (locate-library "mh-e") ""))
272 (setq files (delete "gnus-mh.el" files))))
276 (message "No xml: %s %s" (cadr code) (or (locate-library "xml") ""))
277 (setq files (delete "nnrss.el" files))))
279 (if (featurep 'xemacs)
281 '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el")))
282 (setq files (delete file files)))
285 (setq file (expand-file-name file srcdir))
286 (when (and (file-exists-p
287 (setq elc (concat (file-name-nondirectory file) "c")))
288 (file-newer-than-file-p file elc))
291 (while (setq file (pop files))
292 (setq file (expand-file-name file srcdir))
293 (when (or (not (file-exists-p
294 (setq elc (concat (file-name-nondirectory file) "c"))))
295 (file-newer-than-file-p file elc))
297 (byte-compile-file file))))))
299 (defun dgnushack-recompile ()
301 (byte-recompile-directory "." 0))
303 (defvar dgnushack-gnus-load-file
304 (if (featurep 'xemacs)
305 (expand-file-name "auto-autoloads.el")
306 (expand-file-name "gnus-load.el")))
308 (defvar dgnushack-cus-load-file
309 (if (featurep 'xemacs)
310 (expand-file-name "custom-load.el")
311 (expand-file-name "cus-load.el")))
313 (defun dgnushack-make-cus-load ()
315 (let ((cusload-base-file dgnushack-cus-load-file))
316 (defadvice directory-files (after exclude-dir-locals activate)
317 "Exclude .dir-locals.el file."
318 (dolist (file ad-return-value)
319 (if (string-match "\\(?:\\`\\|/\\)\\.dir-locals\\.el\\'" file)
320 (setq ad-return-value (delete file ad-return-value)))))
322 (if (fboundp 'custom-make-dependencies)
323 (custom-make-dependencies)
324 (Custom-make-dependencies))
325 (ad-unadvise 'directory-files))
326 (when (featurep 'xemacs)
327 (message "Compiling %s..." dgnushack-cus-load-file)
328 (byte-compile-file dgnushack-cus-load-file))))
330 (defun dgnushack-make-auto-load ()
332 (let ((generated-autoload-file dgnushack-gnus-load-file)
333 (make-backup-files nil)
334 (autoload-package-name "gnus"))
335 (if (featurep 'xemacs)
336 (if (file-exists-p generated-autoload-file)
337 (delete-file generated-autoload-file))
338 (with-temp-file generated-autoload-file
340 (defadvice directory-files (after exclude-dir-locals activate)
341 "Exclude .dir-locals.el file."
342 (dolist (file ad-return-value)
343 (if (string-match "\\(?:\\`\\|/\\)\\.dir-locals\\.el\\'" file)
344 (setq ad-return-value (delete file ad-return-value)))))
346 (batch-update-autoloads)
347 (ad-unadvise 'directory-files))))
349 (defun dgnushack-make-load ()
350 (unless (featurep 'xemacs)
351 (message "Generating %s..." dgnushack-gnus-load-file)
352 (with-temp-file dgnushack-gnus-load-file
353 (insert-file-contents dgnushack-cus-load-file)
354 (delete-file dgnushack-cus-load-file)
355 (goto-char (point-min))
356 (search-forward ";;; Code:")
358 (delete-region (point-min) (point))
360 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
364 (goto-char (point-max))
365 (if (search-backward "custom-versions-load-alist" nil t)
368 (while (eq (char-after) ?\;)
371 (delete-region (point) (point-max))
373 ;; smiley-* are duplicated. Remove them all.
374 (let ((point (point)))
375 (insert-file-contents dgnushack-gnus-load-file)
377 (while (search-forward "smiley-" nil t)
379 (if (looking-at "(autoload ")
380 (delete-region (point) (progn (forward-sexp) (point)))
383 (goto-char (point-max))
384 (when (search-backward "\n(provide " nil t)
386 (delete-region (point) (point-max)))
389 \(provide 'gnus-load)
392 ;;; version-control: never
393 ;;; no-byte-compile: t
394 ;;; no-update-autoloads: t
396 ;;; gnus-load.el ends here
399 (message "Compiling %s..." dgnushack-gnus-load-file)
400 (byte-compile-file dgnushack-gnus-load-file)
401 (when (featurep 'xemacs)
402 (message "Creating dummy gnus-load.el...")
403 (with-temp-file (expand-file-name "gnus-load.el")
406 \(provide 'gnus-load)
409 ;;; version-control: never
410 ;;; no-byte-compile: t
411 ;;; no-update-autoloads: t
413 ;;; gnus-load.el ends here"))))
415 (defun dgnushack-find-lisp-shadows (&optional lispdir)
416 "Return a list of directories in which other Gnus installations exist.
417 This function looks for the other Gnus installations which will shadow
418 the new Gnus Lisp modules which have been installed in LISPDIR, using
419 the default `load-path'. The return value will make sense only when
420 LISPDIR is existent and is listed in the default `load-path'. Assume
421 LISPDIR will be prepended to `load-path' by a user if the default
422 `load-path' does not contain it."
424 (setq lispdir (getenv "lispdir")))
425 (when (and lispdir (file-directory-p lispdir))
426 (setq lispdir (file-truename (directory-file-name lispdir)))
427 (let ((indices '("gnus.elc" "gnus.el" "gnus.el.bz2" "gnus.el.gz"
428 "message.elc" "message.el" "message.el.bz2"
430 (path (delq nil (mapcar
433 (when (and p (file-directory-p p))
434 (file-truename (directory-file-name p)))
436 dgnushack-default-load-path)))
439 (setq rest (cons (car path) rest)
440 path (delete (car rest) (cdr path))))
441 (setq path (nreverse (cdr (member lispdir rest)))
446 (when (file-exists-p (expand-file-name (pop elcs) (car path)))
447 (setq rest (cons (car path) rest)
449 (setq path (cdr path)))
451 (setq path (nreverse rest))
453 (let (print-level print-length)
455 WARNING: The other Gnus installation" (if (cdr path) "s have" " has") "\
456 been detected in:\n\n " (mapconcat 'identity path "\n ") "\n\n\
457 You will need to modify the run-time `load-path', remove them manually,
458 or remove them using `make remove-installed-shadows'.\n\n"))))))))
460 (defun dgnushack-remove-lisp-shadows (&optional lispdir)
461 "Remove the other Gnus installations which shadow the recent one."
462 (let ((path (with-temp-buffer
463 (let ((standard-output (current-buffer)))
464 (dgnushack-find-lisp-shadows lispdir))))
465 elcs files shadows file)
467 (unless (setq elcs (directory-files srcdir nil "\\.elc\\'"))
468 (error "You should build .elc files first."))
474 (list (concat el "c") el (concat el ".bz2") (concat el ".gz")))
476 (list (file-name-nondirectory dgnushack-gnus-load-file)
477 (file-name-nondirectory dgnushack-cus-load-file))
478 (mapcar (lambda (elc) (substring elc 0 -1)) elcs)))))
482 (setq file (expand-file-name (pop shadows) (car path)))
483 (when (file-exists-p file)
484 (princ (concat " Removing " file "..."))
489 (error (princ "failed\n")))))
490 (setq path (cdr path))))))
492 ;;; dgnushack.el ends here