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)
38 (defvar srcdir (or (getenv "srcdir") "."))
39 (defvar loaddir (and load-file-name (file-name-directory load-file-name)))
41 (defun my-getenv (str)
42 (let ((val (getenv str)))
43 (if (equal val "no") nil val)))
45 (if (my-getenv "lispdir")
46 (push (my-getenv "lispdir") load-path))
48 (push (or (my-getenv "URLDIR") (expand-file-name "../../url/lisp/" loaddir))
51 (push (or (my-getenv "W3DIR") (expand-file-name "../../w3/lisp/" loaddir))
54 ;(push "/usr/share/emacs/site-lisp" load-path)
56 ;; If we are building w3 in a different directory than the source
57 ;; directory, we must read *.el from source directory and write *.elc
58 ;; into the building directory. For that, we define this function
59 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
60 (defun byte-compile-dest-file (filename)
61 "Convert an Emacs Lisp source file name to a compiled file name.
62 In addition, remove directory name part from FILENAME."
63 (setq filename (byte-compiler-base-file-name filename))
64 (setq filename (file-name-sans-versions filename))
65 (setq filename (file-name-nondirectory filename))
66 (if (eq system-type 'windows-nt)
67 (setq filename (downcase filename)))
68 (cond ((eq system-type 'vax-vms)
69 (concat (substring filename 0 (string-match ";" filename)) "c"))
70 ((string-match emacs-lisp-file-regexp filename)
71 (concat (substring filename 0 (match-beginning 0)) ".elc"))
72 (t (concat filename ".elc"))))
75 ;; To avoid having defsubsts and inlines happen.
76 ;(if (featurep 'xemacs)
77 ; (require 'byte-optimize)
78 ; (require 'byte-opt))
79 ;(defun byte-optimize-inline-handler (form)
80 ; "byte-optimize-handler for the `inline' special-form."
81 ; (cons 'progn (cdr form)))
82 ;(defalias 'byte-compile-file-form-defsubst 'byte-compile-file-form-defun)
84 ;; Work around for an incompatibility (XEmacs 21.4 vs. 21.5), see the
87 ;; http://thread.gmane.org/gmane.emacs.gnus.general/56414
88 ;; Subject: attachment problems found but not fixed
90 ;; http://thread.gmane.org/gmane.emacs.gnus.general/56459
91 ;; Subject: Splitting mail -- XEmacs 21.4 vs 21.5
93 ;; http://thread.gmane.org/gmane.emacs.xemacs.beta/20519
94 ;; Subject: XEmacs 21.5 and Gnus fancy splitting.
96 ;; Should be fixed in XEmacs (March 2007).
97 ;; http://thread.gmane.org/gmane.emacs.xemacs.patches/8124
98 ;; When should we remove this workaround?
100 (when (and (featurep 'xemacs)
101 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
102 (modify-syntax-entry ?= " " table)
104 (with-syntax-table table
106 (goto-char (point-min))
109 ;; The original `with-syntax-table' uses `copy-syntax-table' which
110 ;; doesn't seem to copy modified syntax entries in old XEmacs 21.5.
111 (defmacro with-syntax-table (syntab &rest body)
112 "Evaluate BODY with the SYNTAB as the current syntax table."
113 `(let ((stab (syntax-table)))
116 ;;(set-syntax-table (copy-syntax-table ,syntab))
117 (set-syntax-table ,syntab)
119 (set-syntax-table stab)))))
121 (push srcdir load-path)
122 (push loaddir load-path)
123 (load (expand-file-name "lpath.el" loaddir) nil t)
125 (defalias 'device-sound-enabled-p 'ignore)
126 (defalias 'play-sound-file 'ignore)
127 (defalias 'efs-re-read-dir 'ignore)
128 (defalias 'ange-ftp-re-read-dir 'ignore)
129 (defalias 'define-mail-user-agent 'ignore)
132 (unless (featurep 'xemacs)
133 (defalias 'get-popup-menu-response 'ignore)
134 (defalias 'event-object 'ignore)
135 (autoload 'iswitchb-read-buffer "iswitchb")
136 (autoload 'netrc-credentials "netrc")
137 (defalias 'x-defined-colors 'ignore)
138 (defalias 'read-color 'ignore)))
141 (when (featurep 'xemacs)
142 (unless (fboundp 'defadvice)
143 (autoload 'defadvice "advice" nil nil 'macro))
144 (autoload 'Info-directory "info" nil t)
145 (autoload 'Info-index "info" nil t)
146 (autoload 'Info-index-next "info" nil t)
147 (autoload 'Info-menu "info" nil t)
148 (autoload 'ad-add-advice "advice")
149 (unless (and (emacs-version>= 21 5)
150 (not (featurep 'sxemacs)))
151 ;; calendar/auto-autoloads.el provides it.
152 (autoload 'add-to-invisibility-spec "dummy"))
153 (autoload 'annotations-at "annotations")
154 (autoload 'apropos "apropos" nil t)
155 (autoload 'apropos-command "apropos" nil t)
156 (autoload 'bbdb-complete-name "bbdb-com" nil t)
157 (autoload 'browse-url "browse-url" nil t)
158 (autoload 'browse-url-of-file "browse-url" nil t)
159 (autoload 'c-mode "cc-mode" nil t)
160 (autoload 'customize-apropos "cus-edit" nil t)
161 (autoload 'customize-group "cus-edit" nil t)
162 (autoload 'customize-save-variable "cus-edit" nil t)
163 (autoload 'customize-set-variable "cus-edit" nil t)
164 (autoload 'customize-variable "cus-edit" nil t)
165 (autoload 'debug "debug" nil t)
167 (unless (locate-library "mule-ccl")
168 (autoload 'define-ccl-program "ccl" nil nil 'macro))
169 (defalias 'define-ccl-program 'ignore))
170 (autoload 'delete-annotation "annotations")
171 (autoload 'dolist "cl-macs" nil nil 'macro)
172 (autoload 'enriched-decode "enriched")
173 (autoload 'eudc-expand-inline "eudc" nil t)
174 (autoload 'executable-find "executable")
175 (autoload 'font-lock-fontify-buffer "font-lock" nil t)
176 (when (and (emacs-version>= 21 5)
177 (not (featurep 'sxemacs)))
178 (autoload 'get-display-table "disp-table")
179 (autoload 'put-display-table "disp-table"))
180 (autoload 'info "info" nil t)
181 (autoload 'mail-extract-address-components "mail-extr")
182 (autoload 'mail-fetch-field "mail-utils")
183 (autoload 'make-annotation "annotations")
184 (autoload 'make-display-table "disp-table")
185 (autoload 'pgg-snarf-keys-region "pgg" nil t)
187 (autoload 'ps-despool "ps-print" nil t)
188 (autoload 'ps-spool-buffer "ps-print" nil t)
189 (autoload 'ps-spool-buffer-with-faces "ps-print" nil t)
190 (autoload 'read-passwd "passwd")
191 (autoload 'regexp-opt "regexp-opt")
192 (autoload 'reporter-submit-bug-report "reporter")
193 (if (and (emacs-version>= 21 5)
194 (not (featurep 'sxemacs)))
195 (autoload 'setenv "process" nil t)
196 (autoload 'setenv "env" nil t))
197 (autoload 'sgml-mode "psgml" nil t)
198 (autoload 'smtpmail-send-it "smtpmail")
199 (autoload 'sort-numeric-fields "sort" nil t)
200 (autoload 'sort-subr "sort")
201 (autoload 'thing-at-point "thingatpt")
202 (autoload 'toggle-truncate-lines "view-less" nil t)
203 (autoload 'trace-function-background "trace" nil t)
204 (autoload 'unmorse-region "morse" nil t)
205 (autoload 'w3-do-setup "w3")
206 (autoload 'w3-prepare-buffer "w3-display")
207 (autoload 'w3-region "w3-display" nil t)
208 (defalias 'frame-char-height 'frame-height)
209 (defalias 'frame-char-width 'frame-width)
210 (defalias 'frame-parameter 'frame-property)
211 (defalias 'make-overlay 'ignore)
212 (defalias 'overlay-end 'ignore)
213 (defalias 'overlay-get 'ignore)
214 (defalias 'overlay-put 'ignore)
215 (defalias 'overlay-start 'ignore)
216 (defalias 'overlays-in 'ignore)
217 (defalias 'replace-dehighlight 'ignore)
218 (defalias 'replace-highlight 'ignore)
219 (defalias 'w3-coding-system-for-mime-charset 'ignore)))
221 (defun dgnushack-emacs-compile-defcustom-p ()
222 "Return non-nil if Emacs byte compiles `defcustom' forms.
223 Those Emacsen will warn against undefined variables and functions used
224 in `defcustom' forms."
225 (let ((outbuf (with-temp-buffer
226 (insert "(defcustom foo (1+ (random)) \"\" :group 'emacs)\n")
227 (byte-compile-from-buffer (current-buffer) "foo.el"))))
230 (with-current-buffer outbuf
231 (goto-char (point-min))
232 (search-forward " 'foo '(byte-code " nil t))
233 (kill-buffer outbuf)))))
235 (when (dgnushack-emacs-compile-defcustom-p)
236 (maybe-fbind '(defined-colors face-attribute))
237 (maybe-bind '(idna-program installation-directory)))
239 (when (featurep 'xemacs)
240 (defadvice byte-optimize-apply (before use-mapcan (form) activate)
241 "Replace (apply 'nconc (mapcar ...)) with (mapcan ...)."
242 (let ((last (nth (1- (length form)) form)))
243 (when (and (eq last (third form))
245 (eq 'mapcar (car last))
246 (equal (nth 1 form) ''nconc))
247 (setq form (cons 'mapcan (cdr last)))))))
249 (defun dgnushack-compile-verbosely ()
250 "Call dgnushack-compile with warnings ENABLED. If you are compiling
251 patches to gnus, you should consider modifying make.bat to call
252 dgnushack-compile-verbosely. All other users should continue to use
254 (dgnushack-compile t))
256 (defun dgnushack-compile (&optional warn)
257 ;;(setq byte-compile-dynamic t)
259 (setq byte-compile-warnings
260 '(free-vars unresolved callargs redefine suspicious)))
261 (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
262 ;;(byte-compile-generate-call-tree t)
264 ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
266 (when (featurep 'xemacs)
267 (setq gnus-xmas-glyph-directory "dummy"))
268 (dolist (file '(".dir-locals.el" "dgnushack.el" "lpath.el"))
269 (setq files (delete file files)))
270 (when (featurep 'base64)
271 (setq files (delete "base64.el" files)))
275 (message "No w3: %s %s" (cadr code) (or (locate-library "w3-parse") ""))
276 (dolist (file '("webmail.el" "nnwfm.el"))
277 (setq files (delete file files)))))
279 ;; Under XEmacs 21.4 this loads easy-mmode.elc that provides
280 ;; the Emacs functions `propertize' and `replace-regexp-in-string'.
283 (message "No mh-e: %s %s" (cadr code) (or (locate-library "mh-e") ""))
284 (setq files (delete "gnus-mh.el" files))))
288 (message "No xml: %s %s" (cadr code) (or (locate-library "xml") ""))
289 (setq files (delete "nnrss.el" files))))
291 (if (featurep 'xemacs)
293 '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el")))
294 (setq files (delete file files)))
295 (unless (and (fboundp 'libxml-parse-html-region)
296 ;; lpath.el binds it.
297 (not (eq (symbol-function 'libxml-parse-html-region)
299 (setq files (delete "shr.el" files)))
302 (setq file (expand-file-name file srcdir))
303 (when (and (file-exists-p
304 (setq elc (concat (file-name-nondirectory file) "c")))
305 (file-newer-than-file-p file elc))
308 (while (setq file (pop files))
309 (setq file (expand-file-name file srcdir))
310 (when (or (not (file-exists-p
311 (setq elc (concat (file-name-nondirectory file) "c"))))
312 (file-newer-than-file-p file elc))
314 (byte-compile-file file))))))
316 (defun dgnushack-recompile ()
318 (byte-recompile-directory "." 0))
320 (defvar dgnushack-gnus-load-file
321 (if (featurep 'xemacs)
322 (expand-file-name "auto-autoloads.el")
323 (expand-file-name "gnus-load.el")))
325 (defvar dgnushack-cus-load-file
326 (if (featurep 'xemacs)
327 (expand-file-name "custom-load.el")
328 (expand-file-name "cus-load.el")))
330 (defun dgnushack-make-cus-load ()
332 (let ((cusload-base-file dgnushack-cus-load-file))
333 (defadvice directory-files (after exclude-dir-locals activate)
334 "Exclude .dir-locals.el file."
335 (dolist (file ad-return-value)
336 (if (string-match "\\(?:\\`\\|/\\)\\.dir-locals\\.el\\'" file)
337 (setq ad-return-value (delete file ad-return-value)))))
339 (if (fboundp 'custom-make-dependencies)
340 (custom-make-dependencies)
341 (Custom-make-dependencies))
342 (ad-unadvise 'directory-files))
343 (when (featurep 'xemacs)
344 (message "Compiling %s..." dgnushack-cus-load-file)
345 (byte-compile-file dgnushack-cus-load-file))))
347 (defun dgnushack-make-auto-load ()
349 (let ((generated-autoload-file dgnushack-gnus-load-file)
350 (make-backup-files nil)
351 (autoload-package-name "gnus"))
352 (if (featurep 'xemacs)
353 (if (file-exists-p generated-autoload-file)
354 (delete-file generated-autoload-file))
355 (with-temp-file generated-autoload-file
357 (defadvice directory-files (after exclude-dir-locals activate)
358 "Exclude .dir-locals.el file."
359 (dolist (file ad-return-value)
360 (if (string-match "\\(?:\\`\\|/\\)\\.dir-locals\\.el\\'" file)
361 (setq ad-return-value (delete file ad-return-value)))))
363 (batch-update-autoloads)
364 (ad-unadvise 'directory-files))))
366 (defun dgnushack-make-load ()
367 (unless (featurep 'xemacs)
368 (message "Generating %s..." dgnushack-gnus-load-file)
369 (with-temp-file dgnushack-gnus-load-file
370 (insert-file-contents dgnushack-cus-load-file)
371 (delete-file dgnushack-cus-load-file)
372 (goto-char (point-min))
373 (search-forward ";;; Code:")
375 (delete-region (point-min) (point))
377 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
381 (goto-char (point-max))
382 (if (search-backward "custom-versions-load-alist" nil t)
385 (while (eq (char-after) ?\;)
388 (delete-region (point) (point-max))
390 ;; smiley-* are duplicated. Remove them all.
391 (let ((point (point)))
392 (insert-file-contents dgnushack-gnus-load-file)
394 (while (search-forward "smiley-" nil t)
396 (if (looking-at "(autoload ")
397 (delete-region (point) (progn (forward-sexp) (point)))
400 (goto-char (point-max))
401 (when (search-backward "\n(provide " nil t)
403 (delete-region (point) (point-max)))
406 \(provide 'gnus-load)
409 ;;; version-control: never
410 ;;; no-byte-compile: t
411 ;;; no-update-autoloads: t
413 ;;; gnus-load.el ends here
416 (message "Compiling %s..." dgnushack-gnus-load-file)
417 (byte-compile-file dgnushack-gnus-load-file)
418 (when (featurep 'xemacs)
419 (message "Creating dummy gnus-load.el...")
420 (with-temp-file (expand-file-name "gnus-load.el")
423 \(provide 'gnus-load)
426 ;;; version-control: never
427 ;;; no-byte-compile: t
428 ;;; no-update-autoloads: t
430 ;;; gnus-load.el ends here"))))
432 (defun dgnushack-find-lisp-shadows (&optional lispdir)
433 "Return a list of directories in which other Gnus installations exist.
434 This function looks for the other Gnus installations which will shadow
435 the new Gnus Lisp modules which have been installed in LISPDIR, using
436 the default `load-path'. The return value will make sense only when
437 LISPDIR is existent and is listed in the default `load-path'. Assume
438 LISPDIR will be prepended to `load-path' by a user if the default
439 `load-path' does not contain it."
441 (setq lispdir (getenv "lispdir")))
442 (when (and lispdir (file-directory-p lispdir))
443 (setq lispdir (file-truename (directory-file-name lispdir)))
444 (let ((indices '("gnus.elc" "gnus.el" "gnus.el.bz2" "gnus.el.gz"
445 "message.elc" "message.el" "message.el.bz2"
447 (path (delq nil (mapcar
450 (when (and p (file-directory-p p))
451 (file-truename (directory-file-name p)))
453 dgnushack-default-load-path)))
456 (setq rest (cons (car path) rest)
457 path (delete (car rest) (cdr path))))
458 (setq path (nreverse (cdr (member lispdir rest)))
463 (when (file-exists-p (expand-file-name (pop elcs) (car path)))
464 (setq rest (cons (car path) rest)
466 (setq path (cdr path)))
468 (setq path (nreverse rest))
470 (let (print-level print-length)
472 WARNING: The other Gnus installation" (if (cdr path) "s have" " has") "\
473 been detected in:\n\n " (mapconcat 'identity path "\n ") "\n\n\
474 You will need to modify the run-time `load-path', remove them manually,
475 or remove them using `make remove-installed-shadows'.\n\n"))))))))
477 (defun dgnushack-remove-lisp-shadows (&optional lispdir)
478 "Remove the other Gnus installations which shadow the recent one."
479 (let ((path (with-temp-buffer
480 (let ((standard-output (current-buffer)))
481 (dgnushack-find-lisp-shadows lispdir))))
482 elcs files shadows file)
484 (unless (setq elcs (directory-files srcdir nil "\\.elc\\'"))
485 (error "You should build .elc files first."))
491 (list (concat el "c") el (concat el ".bz2") (concat el ".gz")))
493 (list (file-name-nondirectory dgnushack-gnus-load-file)
494 (file-name-nondirectory dgnushack-cus-load-file))
495 (mapcar (lambda (elc) (substring elc 0 -1)) elcs)))))
499 (setq file (expand-file-name (pop shadows) (car path)))
500 (when (file-exists-p file)
501 (princ (concat " Removing " file "..."))
506 (error (princ "failed\n")))))
507 (setq path (cdr path))))))
509 ;;; dgnushack.el ends here