1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994-2014 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news, path
8 ;; This file is part of GNU Emacs.
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 3, or (at your option)
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 (defvar dgnushack-default-load-path (copy-sequence load-path))
29 (defalias 'facep 'ignore)
35 (require 'org-entities)
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 "/usr/share/emacs/site-lisp" load-path)
50 ;; If we are building Gnus in a different directory than the source
51 ;; directory, we must read *.el from source directory and write *.elc
52 ;; into the building directory. For that, we define this function
53 ;; before loading bytecomp. Bytecomp doesn't overwrite this function.
54 (defun byte-compile-dest-file (filename)
55 "Convert an Emacs Lisp source file name to a compiled file name.
56 In addition, remove directory name part from FILENAME."
57 (setq filename (byte-compiler-base-file-name filename))
58 (setq filename (file-name-sans-versions filename))
59 (setq filename (file-name-nondirectory filename))
60 (if (eq system-type 'windows-nt)
61 (setq filename (downcase filename)))
62 (cond ((eq system-type 'vax-vms)
63 (concat (substring filename 0 (string-match ";" filename)) "c"))
64 ((string-match emacs-lisp-file-regexp filename)
65 (concat (substring filename 0 (match-beginning 0)) ".elc"))
66 (t (concat filename ".elc"))))
69 ;; To avoid having defsubsts and inlines happen.
70 ;(if (featurep 'xemacs)
71 ; (require 'byte-optimize)
72 ; (require 'byte-opt))
73 ;(defun byte-optimize-inline-handler (form)
74 ; "byte-optimize-handler for the `inline' special-form."
75 ; (cons 'progn (cdr form)))
76 ;(defalias 'byte-compile-file-form-defsubst 'byte-compile-file-form-defun)
78 ;; Work around for an incompatibility (XEmacs 21.4 vs. 21.5), see the
81 ;; http://thread.gmane.org/gmane.emacs.gnus.general/56414
82 ;; Subject: attachment problems found but not fixed
84 ;; http://thread.gmane.org/gmane.emacs.gnus.general/56459
85 ;; Subject: Splitting mail -- XEmacs 21.4 vs 21.5
87 ;; http://thread.gmane.org/gmane.emacs.xemacs.beta/20519
88 ;; Subject: XEmacs 21.5 and Gnus fancy splitting.
90 ;; Should be fixed in XEmacs (March 2007).
91 ;; http://thread.gmane.org/gmane.emacs.xemacs.patches/8124
92 ;; When should we remove this workaround?
94 (when (and (featurep 'xemacs)
95 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
96 (modify-syntax-entry ?= " " table)
98 (with-syntax-table table
100 (goto-char (point-min))
103 ;; The original `with-syntax-table' uses `copy-syntax-table' which
104 ;; doesn't seem to copy modified syntax entries in old XEmacs 21.5.
105 (defmacro with-syntax-table (syntab &rest body)
106 "Evaluate BODY with the SYNTAB as the current syntax table."
107 `(let ((stab (syntax-table)))
110 ;;(set-syntax-table (copy-syntax-table ,syntab))
111 (set-syntax-table ,syntab)
113 (set-syntax-table stab)))))
115 (push srcdir load-path)
116 (push loaddir load-path)
117 (load (expand-file-name "lpath.el" loaddir) nil t)
119 (defalias 'device-sound-enabled-p 'ignore)
120 (defalias 'play-sound-file 'ignore)
121 (defalias 'efs-re-read-dir 'ignore)
122 (defalias 'ange-ftp-re-read-dir 'ignore)
123 (defalias 'define-mail-user-agent 'ignore)
124 (defalias 'debbugs-gnu-summary-mode 'ignore)
125 (defvar debbugs-gnu-bug-number nil)
128 (unless (featurep 'xemacs)
129 (defalias 'get-popup-menu-response 'ignore)
130 (defalias 'event-object 'ignore)
131 (autoload 'iswitchb-read-buffer "iswitchb")
132 (autoload 'netrc-credentials "netrc")
133 (defalias 'x-defined-colors 'ignore)
134 (defalias 'read-color 'ignore)))
137 (when (featurep 'xemacs)
138 (defvar window-point-insertion-type nil)
139 (unless (fboundp 'defadvice)
140 (autoload 'defadvice "advice" nil nil 'macro))
141 (unless (boundp 'help-echo-owns-message)
142 (defvar help-echo-owns-message))
143 (unless (boundp 'gnus-registry-enabled)
144 (defvar gnus-registry-enabled nil))
145 (unless (boundp 'mail-dont-reply-to-names)
146 (defvar mail-dont-reply-to-names nil))
147 (unless (fboundp 'url-retrieve-synchronously)
148 (defalias 'url-retrieve-synchronously 'url-retrieve))
149 (unless (fboundp 'url-queue-retrieve)
150 (defun url-queue-retrieve (url callback &optional cbargs silent
152 (url-retrieve url callback cbargs)))
153 (autoload 'Info-directory "info" nil t)
154 (autoload 'Info-index "info" nil t)
155 (autoload 'Info-index-next "info" nil t)
156 (autoload 'Info-menu "info" nil t)
157 (autoload 'ad-add-advice "advice")
158 (unless (and (emacs-version>= 21 5)
159 (not (featurep 'sxemacs)))
160 ;; calendar/auto-autoloads.el provides it.
161 (autoload 'add-to-invisibility-spec "dummy"))
162 (autoload 'annotations-at "annotations")
163 (autoload 'apropos "apropos" nil t)
164 (autoload 'apropos-command "apropos" nil t)
165 (autoload 'bbdb-complete-name "bbdb-com" nil t)
166 (autoload 'browse-url "browse-url" nil t)
167 (autoload 'browse-url-of-file "browse-url" nil t)
168 (autoload 'c-mode "cc-mode" nil t)
169 (autoload 'customize-apropos "cus-edit" nil t)
170 (autoload 'customize-group "cus-edit" nil t)
171 (autoload 'customize-save-variable "cus-edit" nil t)
172 (autoload 'customize-set-variable "cus-edit" nil t)
173 (autoload 'customize-variable "cus-edit" nil t)
174 (autoload 'debug "debug" nil t)
175 (autoload 'sha1 "sha1")
177 (unless (locate-library "mule-ccl")
178 (autoload 'define-ccl-program "ccl" nil nil 'macro))
179 (defalias 'define-ccl-program 'ignore))
180 (autoload 'delete-annotation "annotations")
181 (autoload 'dolist "cl-macs" nil nil 'macro)
182 (autoload 'enriched-decode "enriched")
183 (autoload 'eudc-expand-inline "eudc" nil t)
184 (autoload 'executable-find "executable")
185 (autoload 'font-lock-fontify-buffer "font-lock" nil t)
186 (when (and (emacs-version>= 21 5)
187 (not (featurep 'sxemacs)))
188 (autoload 'get-display-table "disp-table")
189 (autoload 'put-display-table "disp-table"))
190 (autoload 'info "info" nil t)
191 (autoload 'mail-extract-address-components "mail-extr")
192 (autoload 'mail-fetch-field "mail-utils")
193 (autoload 'make-annotation "annotations")
194 (autoload 'make-display-table "disp-table")
196 (autoload 'ps-despool "ps-print" nil t)
197 (autoload 'ps-spool-buffer "ps-print" nil t)
198 (autoload 'ps-spool-buffer-with-faces "ps-print" nil t)
199 (autoload 'read-passwd "passwd")
200 (autoload 'regexp-opt "regexp-opt")
201 (autoload 'reporter-submit-bug-report "reporter")
202 (if (condition-case nil
205 (not (fboundp 'rot13-string)))
207 (defmacro rot13-string (string)
208 "Return ROT13 encryption of STRING."
209 `(let ((string ,string))
212 (translate-region (point-min) (point-max) ,rot13-display-table)
214 (if (and (emacs-version>= 21 5)
215 (not (featurep 'sxemacs)))
216 (autoload 'setenv "process" nil t)
217 (autoload 'setenv "env" nil t))
218 (autoload 'sgml-mode "psgml" nil t)
219 (autoload 'smtpmail-send-it "smtpmail")
220 (autoload 'sort-numeric-fields "sort" nil t)
221 (autoload 'sort-subr "sort")
222 (autoload 'thing-at-point "thingatpt")
223 (autoload 'toggle-truncate-lines "view-less" nil t)
224 (autoload 'trace-function-background "trace" nil t)
225 (autoload 'unmorse-region "morse" nil t)
226 (defalias 'frame-char-height 'frame-height)
227 (defalias 'frame-char-width 'frame-width)
228 (defalias 'frame-parameter 'frame-property)
229 (defalias 'make-overlay 'ignore)
230 (defalias 'overlay-end 'ignore)
231 (defalias 'overlay-get 'ignore)
232 (defalias 'overlay-put 'ignore)
233 (defalias 'overlay-start 'ignore)
234 (defalias 'overlays-in 'ignore)
235 (defalias 'replace-dehighlight 'ignore)
236 (defalias 'replace-highlight 'ignore)
237 (defalias 'gnutls-available-p 'ignore)
238 (defvar timer-list nil)
239 (defvar scroll-margin 0)))
241 (defun dgnushack-emacs-compile-defcustom-p ()
242 "Return non-nil if Emacs byte compiles `defcustom' forms.
243 Those Emacsen will warn against undefined variables and functions used
244 in `defcustom' forms."
245 (let ((outbuf (with-temp-buffer
246 (insert "(defcustom foo (1+ (random)) \"\" :group 'emacs)\n")
247 (byte-compile-from-buffer (current-buffer) "foo.el"))))
250 (with-current-buffer outbuf
251 (goto-char (point-min))
252 (search-forward " 'foo '(byte-code " nil t))
253 (kill-buffer outbuf)))))
255 (when (and (featurep 'xemacs)
256 (dgnushack-emacs-compile-defcustom-p))
257 (maybe-fbind '(defined-colors face-attribute))
258 (maybe-bind '(idna-program installation-directory)))
260 (when (featurep 'xemacs)
261 (defadvice byte-optimize-apply (before use-mapcan (form) activate)
262 "Replace (apply 'nconc (mapcar ...)) with (mapcan ...)."
263 (let ((last (nth (1- (length form)) form)))
264 (when (and (eq last (third form))
266 (eq 'mapcar (car last))
267 (equal (nth 1 form) ''nconc))
268 (setq form (cons 'mapcan (cdr last)))))))
270 (defun dgnushack-compile-verbosely ()
271 "Call dgnushack-compile with warnings ENABLED. If you are compiling
272 patches to gnus, you should consider modifying make.bat to call
273 dgnushack-compile-verbosely. All other users should continue to use
275 (dgnushack-compile t))
277 (defun dgnushack-compile-error-on-warn ()
278 "Call dgnushack-compile with minimal warnings, but with error-on-warn ENABLED.
279 This means that every warning will be reported as an error."
280 (unless (dgnushack-compile nil t)
281 (error "Error during byte compilation (warnings were reported as errors!).")))
283 (defun dgnushack-compile (&optional warn error-on-warn)
284 ;;(setq byte-compile-dynamic t)
286 (setq byte-compile-warnings
287 '(free-vars unresolved callargs redefine suspicious)))
288 (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
290 ;;(byte-compile-generate-call-tree t)
292 ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
294 (when (featurep 'xemacs)
295 (setq gnus-xmas-glyph-directory "dummy"))
296 (dolist (file '(".dir-locals.el" "dgnushack.el" "lpath.el"))
297 (setq files (delete file files)))
298 (when (featurep 'base64)
299 (setq files (delete "base64.el" files)))
301 ;; Under XEmacs 21.4 this loads easy-mmode.elc that provides
302 ;; the Emacs functions `propertize' and `replace-regexp-in-string'.
305 (message "No mh-e: %s %s" (cadr code) (or (locate-library "mh-e") ""))
306 (setq files (delete "gnus-mh.el" files))))
310 (message "No xml: %s %s" (cadr code) (or (locate-library "xml") ""))
311 (setq files (delete "nnrss.el" files))))
313 (if (featurep 'xemacs)
315 '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el")))
316 (setq files (delete file files)))
317 (unless (and (fboundp 'libxml-parse-html-region)
318 ;; lpath.el binds it.
319 (not (eq (symbol-function 'libxml-parse-html-region)
321 (dolist (file '("color.el"))
322 (setq files (delete file files))))
323 (unless (locate-library "epg")
324 (setq files (delete "plstore.el" files)))
325 ;; Temporary code until we fix pcase and defmethod stuff.
326 (when (or (featurep 'xemacs)
327 (or (< emacs-major-version 24)
328 (< emacs-minor-version 3)))
329 (setq files (delete "gnus-icalendar.el" files)))
331 (setq file (expand-file-name file srcdir))
332 (when (and (file-exists-p
333 (setq elc (concat (file-name-nondirectory file) "c")))
334 (file-newer-than-file-p file elc))
337 (while (setq file (pop files))
338 (setq file (expand-file-name file srcdir))
339 (when (or (not (file-exists-p
340 (setq elc (concat (file-name-nondirectory file) "c"))))
341 (file-newer-than-file-p file elc))
343 (let ((byte-compile-error-on-warn t))
344 (unless (ignore-errors
345 (byte-compile-file file))
346 (setq compilesuccess nil)))
348 (byte-compile-file file)))))
351 (defun dgnushack-recompile ()
353 (byte-recompile-directory "." 0))
355 (defvar dgnushack-gnus-load-file
356 (if (featurep 'xemacs)
357 (expand-file-name "auto-autoloads.el")
358 (expand-file-name "gnus-load.el")))
360 (defvar dgnushack-cus-load-file
361 (if (featurep 'xemacs)
362 (expand-file-name "custom-load.el")
363 (expand-file-name "cus-load.el")))
365 (defun dgnushack-make-cus-load ()
367 (let ((cusload-base-file dgnushack-cus-load-file))
368 (defadvice directory-files (after exclude-dir-locals activate)
369 "Exclude .dir-locals.el file."
370 (dolist (file ad-return-value)
371 (if (string-match "\\(?:\\`\\|/\\)\\.dir-locals\\.el\\'" file)
372 (setq ad-return-value (delete file ad-return-value)))))
374 (if (fboundp 'custom-make-dependencies)
375 (custom-make-dependencies)
376 (Custom-make-dependencies))
377 (ad-unadvise 'directory-files))
378 (when (featurep 'xemacs)
379 (message "Compiling %s..." dgnushack-cus-load-file)
380 (byte-compile-file dgnushack-cus-load-file))))
382 (defun dgnushack-make-auto-load ()
384 (let ((generated-autoload-file dgnushack-gnus-load-file)
385 (make-backup-files nil)
386 (autoload-package-name "gnus"))
387 (if (featurep 'xemacs)
388 (if (file-exists-p generated-autoload-file)
389 (delete-file generated-autoload-file))
390 (with-temp-file generated-autoload-file
392 (defadvice directory-files (after exclude-dir-locals activate)
393 "Exclude .dir-locals.el file."
394 (dolist (file ad-return-value)
395 (if (string-match "\\(?:\\`\\|/\\)\\.dir-locals\\.el\\'" file)
396 (setq ad-return-value (delete file ad-return-value)))))
398 (batch-update-autoloads)
399 (ad-unadvise 'directory-files))))
401 (defun dgnushack-make-load ()
402 (unless (featurep 'xemacs)
403 (message "Generating %s..." dgnushack-gnus-load-file)
404 (with-temp-file dgnushack-gnus-load-file
405 (insert-file-contents dgnushack-cus-load-file)
406 (delete-file dgnushack-cus-load-file)
407 (goto-char (point-min))
408 (search-forward ";;; Code:")
410 (delete-region (point-min) (point))
412 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
416 (goto-char (point-max))
417 (if (search-backward "custom-versions-load-alist" nil t)
420 (while (eq (char-after) ?\;)
423 (delete-region (point) (point-max))
425 ;; smiley-* are duplicated. Remove them all.
426 (let ((point (point)))
427 (insert-file-contents dgnushack-gnus-load-file)
429 (while (search-forward "smiley-" nil t)
431 (if (looking-at "(autoload ")
432 (delete-region (point) (progn (forward-sexp) (point)))
435 (goto-char (point-max))
436 (when (search-backward "\n(provide " nil t)
438 (delete-region (point) (point-max)))
441 \(provide 'gnus-load)
444 ;;; version-control: never
445 ;;; no-byte-compile: t
446 ;;; no-update-autoloads: t
448 ;;; gnus-load.el ends here
451 (message "Compiling %s..." dgnushack-gnus-load-file)
452 (byte-compile-file dgnushack-gnus-load-file)
453 (when (featurep 'xemacs)
454 (message "Creating dummy gnus-load.el...")
455 (with-temp-file (expand-file-name "gnus-load.el")
458 \(provide 'gnus-load)
461 ;;; version-control: never
462 ;;; no-byte-compile: t
463 ;;; no-update-autoloads: t
465 ;;; gnus-load.el ends here"))))
467 (defun dgnushack-find-lisp-shadows (&optional lispdir)
468 "Return a list of directories in which other Gnus installations exist.
469 This function looks for the other Gnus installations which will shadow
470 the new Gnus Lisp modules which have been installed in LISPDIR, using
471 the default `load-path'. The return value will make sense only when
472 LISPDIR is existent and is listed in the default `load-path'. Assume
473 LISPDIR will be prepended to `load-path' by a user if the default
474 `load-path' does not contain it."
476 (setq lispdir (getenv "lispdir")))
477 (when (and lispdir (file-directory-p lispdir))
478 (setq lispdir (file-truename (directory-file-name lispdir)))
479 (let ((indices '("gnus.elc" "gnus.el" "gnus.el.bz2" "gnus.el.gz"
480 "message.elc" "message.el" "message.el.bz2"
482 (path (delq nil (mapcar
485 (when (and p (file-directory-p p))
486 (file-truename (directory-file-name p)))
488 dgnushack-default-load-path)))
491 (setq rest (cons (car path) rest)
492 path (delete (car rest) (cdr path))))
493 (setq path (nreverse (cdr (member lispdir rest)))
498 (when (file-exists-p (expand-file-name (pop elcs) (car path)))
499 (setq rest (cons (car path) rest)
501 (setq path (cdr path)))
503 (setq path (nreverse rest))
505 (let (print-level print-length)
507 WARNING: The other Gnus installation" (if (cdr path) "s have" " has") "\
508 been detected in:\n\n " (mapconcat 'identity path "\n ") "\n\n\
509 You will need to modify the run-time `load-path', remove them manually,
510 or remove them using `make remove-installed-shadows'.\n\n"))))))))
512 (defun dgnushack-remove-lisp-shadows (&optional lispdir)
513 "Remove the other Gnus installations which shadow the recent one."
514 (let ((path (with-temp-buffer
515 (let ((standard-output (current-buffer)))
516 (dgnushack-find-lisp-shadows lispdir))))
517 elcs files shadows file)
519 (unless (setq elcs (directory-files srcdir nil "\\.elc\\'"))
520 (error "You should build .elc files first."))
526 (list (concat el "c") el (concat el ".bz2") (concat el ".gz")))
528 (list (file-name-nondirectory dgnushack-gnus-load-file)
529 (file-name-nondirectory dgnushack-cus-load-file))
530 (mapcar (lambda (elc) (substring elc 0 -1)) elcs)))))
534 (setq file (expand-file-name (pop shadows) (car path)))
535 (when (file-exists-p file)
536 (princ (concat " Removing " file "..."))
541 (error (princ "failed\n")))))
542 (setq path (cdr path))))))
544 (unless (fboundp 'with-demoted-errors)
545 (defmacro with-demoted-errors (&rest body)
546 "Run BODY and demote any errors to simple messages.
547 If `debug-on-error' is non-nil, run BODY without catching its errors.
548 This is to be used around code which is not expected to signal an error
549 but which should be robust in the unexpected case that an error is signaled."
550 (declare (debug t) (indent 0))
551 (let ((err (make-symbol "err")))
552 `(condition-case ,err
554 (error (message "Error: %S" ,err) nil)))))
556 ;; XEmacs's `define-obsolete-variable-alias' takes only two arguments:
557 ;; (define-obsolete-variable-alias OLDVAR NEWVAR)
560 (defvar dgnushack-obsolete-name nil)
561 (defvar dgnushack-current-name nil)
563 (define-obsolete-variable-alias
564 'dgnushack-obsolete-name 'dgnushack-current-name "0")
565 (makunbound 'dgnushack-obsolete-name)
566 (makunbound 'dgnushack-current-name)))
567 (wrong-number-of-arguments
568 (defadvice define-obsolete-variable-alias (around ignore-rest-args
569 (oldvar newvar &rest args)
571 "Ignore arguments other than the 1st and the 2nd ones."
573 (put 'define-obsolete-variable-alias 'byte-optimizer
575 (setcdr (nthcdr 2 form) nil)
578 ;;; dgnushack.el ends here