Gnus -- minor build / warning fixes [OK For Upstream]
[gnus] / lisp / dgnushack.el
1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994-2016 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 3, 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.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (defvar dgnushack-default-load-path (copy-sequence load-path))
28
29 (when (featurep 'xemacs)
30   (defmacro declare-function (fn file &optional arglist fileonly)
31     (unless (fboundp fn) (autoload fn file))
32     nil))
33
34 (defalias 'facep 'ignore)
35
36 (require 'cl)
37 (require 'iswitchb)
38
39 (condition-case nil
40     (require 'org-entities)
41   (error nil))
42
43 (defvar srcdir (or (getenv "srcdir") "."))
44 (defvar loaddir (and load-file-name (file-name-directory load-file-name)))
45
46 (defun my-getenv (str)
47   (let ((val (getenv str)))
48     (if (equal val "no") nil val)))
49
50 (if (my-getenv "lispdir")
51     (push (my-getenv "lispdir") load-path))
52
53 ;(push "/usr/share/emacs/site-lisp" load-path)
54
55 ;; If we are building Gnus 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"))))
72
73 (require 'bytecomp)
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)
82
83 ;; Work around for an incompatibility (XEmacs 21.4 vs. 21.5), see the
84 ;; following threads:
85 ;;
86 ;; http://thread.gmane.org/gmane.emacs.gnus.general/56414
87 ;; Subject: attachment problems found but not fixed
88 ;;
89 ;; http://thread.gmane.org/gmane.emacs.gnus.general/56459
90 ;; Subject: Splitting mail -- XEmacs 21.4 vs 21.5
91 ;;
92 ;; http://thread.gmane.org/gmane.emacs.xemacs.beta/20519
93 ;; Subject: XEmacs 21.5 and Gnus fancy splitting.
94 ;;
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?
98 ;;
99 (when (and (featurep 'xemacs)
100            (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
101              (modify-syntax-entry ?= " " table)
102              (with-temp-buffer
103                (with-syntax-table table
104                  (insert "foo=bar")
105                  (goto-char (point-min))
106                  (forward-sexp 1)
107                  (eolp)))))
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)))
113        (unwind-protect
114            (progn
115              ;;(set-syntax-table (copy-syntax-table ,syntab))
116              (set-syntax-table ,syntab)
117              ,@body)
118          (set-syntax-table stab)))))
119
120 (push srcdir load-path)
121 (push loaddir load-path)
122 (load (expand-file-name "lpath.el" loaddir) nil t)
123
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)
129 (defalias 'debbugs-gnu-summary-mode 'ignore)
130 (defvar debbugs-gnu-bug-number nil)
131
132 (eval-and-compile
133   (unless (featurep 'xemacs)
134     (defalias 'get-popup-menu-response 'ignore)
135     (defalias 'event-object 'ignore)
136     (autoload 'iswitchb-read-buffer "iswitchb")
137     (autoload 'netrc-credentials "netrc")
138     (defalias 'x-defined-colors 'ignore)
139     (defalias 'read-color 'ignore)))
140
141 (eval-and-compile
142   (when (featurep 'xemacs)
143     (defvar window-point-insertion-type nil)
144     (unless (fboundp 'defadvice)
145       (autoload 'defadvice "advice" nil nil 'macro))
146     (unless (boundp 'help-echo-owns-message)
147       (defvar help-echo-owns-message))
148     (unless (boundp 'gnus-registry-enabled)
149       (defvar gnus-registry-enabled nil))
150     (unless (boundp 'mail-dont-reply-to-names)
151       (defvar mail-dont-reply-to-names nil))
152     (unless (fboundp 'url-retrieve-synchronously)
153       (defalias 'url-retrieve-synchronously 'url-retrieve))
154     (unless (fboundp 'url-queue-retrieve)
155       (defun url-queue-retrieve (url callback &optional cbargs silent
156                                      inhibit-cookies)
157         (url-retrieve url callback cbargs)))
158     (unless (boundp 'w3-configuration-directory)
159       (setq w3-configuration-directory "~/.w3/"))
160     (autoload 'Info-directory "info" nil t)
161     (autoload 'Info-index "info" nil t)
162     (autoload 'Info-index-next "info" nil t)
163     (autoload 'Info-menu "info" nil t)
164     (autoload 'ad-add-advice "advice")
165     (unless (and (emacs-version>= 21 5)
166                  (not (featurep 'sxemacs)))
167       ;; calendar/auto-autoloads.el provides it.
168       (autoload 'add-to-invisibility-spec "dummy"))
169     (autoload 'annotations-at "annotations")
170     (autoload 'apropos "apropos" nil t)
171     (autoload 'apropos-command "apropos" nil t)
172     (autoload 'bbdb-complete-name "bbdb-com" nil t)
173     (autoload 'browse-url "browse-url" nil t)
174     (autoload 'browse-url-of-file "browse-url" nil t)
175     (autoload 'c-mode "cc-mode" nil t)
176     (autoload 'customize-apropos "cus-edit" nil t)
177     (autoload 'customize-group "cus-edit" nil t)
178     (autoload 'customize-save-variable "cus-edit" nil t)
179     (autoload 'customize-set-variable "cus-edit" nil t)
180     (autoload 'customize-variable "cus-edit" nil t)
181     (autoload 'debug "debug" nil t)
182     (autoload 'sha1 "sha1")
183     (if (featurep 'mule)
184         (unless (locate-library "mule-ccl")
185           (autoload 'define-ccl-program "ccl" nil nil 'macro))
186       (defalias 'define-ccl-program 'ignore))
187     (autoload 'delete-annotation "annotations")
188     (autoload 'dolist "cl-macs" nil nil 'macro)
189     (autoload 'enriched-decode "enriched")
190     (autoload 'eudc-expand-inline "eudc" nil t)
191     (autoload 'executable-find "executable")
192     (autoload 'font-lock-fontify-buffer "font-lock" nil t)
193     (when (and (emacs-version>= 21 5)
194                (not (featurep 'sxemacs)))
195       (autoload 'get-display-table "disp-table")
196       (autoload 'put-display-table "disp-table"))
197     (autoload 'info "info" nil t)
198     (autoload 'mail-extract-address-components "mail-extr")
199     (autoload 'mail-fetch-field "mail-utils")
200     (autoload 'make-annotation "annotations")
201     (autoload 'make-display-table "disp-table")
202     (autoload 'pp "pp")
203     (autoload 'ps-despool "ps-print" nil t)
204     (autoload 'ps-spool-buffer "ps-print" nil t)
205     (autoload 'ps-spool-buffer-with-faces "ps-print" nil t)
206     (autoload 'read-passwd "passwd")
207     (autoload 'regexp-opt "regexp-opt")
208     (autoload 'reporter-submit-bug-report "reporter")
209     (if (condition-case nil
210             (progn
211               (require 'rot13)
212               (not (fboundp 'rot13-string)))
213           (error nil))
214         (defmacro rot13-string (string)
215           "Return ROT13 encryption of STRING."
216           `(let ((string ,string))
217              (with-temp-buffer
218                (insert string)
219                (translate-region (point-min) (point-max) ,rot13-display-table)
220                (buffer-string)))))
221     (if (and (emacs-version>= 21 5)
222              (not (featurep 'sxemacs)))
223         (autoload 'setenv "process" nil t)
224       (autoload 'setenv "env" nil t))
225     (autoload 'sgml-mode "psgml" nil t)
226     (autoload 'smtpmail-send-it "smtpmail")
227     (autoload 'sort-numeric-fields "sort" nil t)
228     (autoload 'sort-subr "sort")
229     (autoload 'thing-at-point "thingatpt")
230     (autoload 'toggle-truncate-lines "view-less" nil t)
231     (autoload 'trace-function-background "trace" nil t)
232     (autoload 'unmorse-region "morse" nil t)
233     (defalias 'frame-char-height 'frame-height)
234     (defalias 'frame-char-width 'frame-width)
235     (defalias 'frame-parameter 'frame-property)
236     (defalias 'replace-dehighlight 'ignore)
237     (defalias 'replace-highlight 'ignore)
238     (defalias 'gnutls-available-p 'ignore)
239     (defvar timer-list nil)
240     (defvar scroll-margin 0)
241     (dolist (fn '(copy-overlay
242                   delete-overlay make-overlay move-overlay next-overlay-change
243                   overlay-buffer overlay-end overlay-get overlay-lists
244                   overlay-properties overlay-put overlay-recenter overlay-start
245                   overlayp overlays-at overlays-in previous-overlay-change
246                   remove-overlays))
247       (autoload fn "overlay"))))
248
249 (defun dgnushack-emacs-compile-defcustom-p ()
250   "Return non-nil if Emacs byte compiles `defcustom' forms.
251 Those Emacsen will warn against undefined variables and functions used
252 in `defcustom' forms."
253   (let ((outbuf (with-temp-buffer
254                   (insert "(defcustom foo (1+ (random)) \"\" :group 'emacs)\n")
255                   (byte-compile-from-buffer (current-buffer) "foo.el"))))
256     (when outbuf
257       (prog1
258           (with-current-buffer outbuf
259             (goto-char (point-min))
260             (search-forward " 'foo '(byte-code " nil t))
261         (kill-buffer outbuf)))))
262
263 (when (and (featurep 'xemacs)
264            (dgnushack-emacs-compile-defcustom-p))
265   (maybe-fbind '(defined-colors face-attribute))
266   (maybe-bind '(idna-program installation-directory)))
267
268 (when (featurep 'xemacs)
269   (defadvice byte-optimize-apply (before use-mapcan (form) activate)
270     "Replace (apply 'nconc (mapcar ...)) with (mapcan ...)."
271     (let ((last (nth (1- (length form)) form)))
272       (when (and (eq last (third form))
273                  (consp last)
274                  (eq 'mapcar (car last))
275                  (member (nth 1 form) '('nconc #'nconc)))
276         (setq form (cons 'mapcan (cdr last)))))))
277
278 (if (featurep 'emacs)
279     (defun dgnushack-compile-file (file)
280       "Byte-compile FILE after reporting that it's being compiled."
281       (message "Compiling %s..." (file-name-nondirectory file))
282       ;; The Emacs 25 version of it doesn't say much.
283       (byte-compile-file file))
284   (defalias 'dgnushack-compile-file 'byte-compile-file))
285
286 (defun dgnushack-compile-verbosely ()
287   "Call dgnushack-compile with warnings ENABLED.  If you are compiling
288 patches to gnus, you should consider modifying make.bat to call
289 dgnushack-compile-verbosely.  All other users should continue to use
290 dgnushack-compile."
291   (dgnushack-compile t))
292
293 (defun dgnushack-compile-error-on-warn ()
294   "Call dgnushack-compile with minimal warnings, but with error-on-warn ENABLED.
295 This means that every warning will be reported as an error."
296   (unless (dgnushack-compile nil t)
297     (error "Error during byte compilation (warnings were reported as errors!).")))
298
299 (defun dgnushack-compile (&optional warn error-on-warn)
300   ;;(setq byte-compile-dynamic t)
301   (unless warn
302     (setq byte-compile-warnings
303           '(free-vars unresolved callargs redefine suspicious)))
304   (let ((files (directory-files srcdir nil "^[^=].*\\.el$"))
305         (compilesuccess t)
306         ;;(byte-compile-generate-call-tree t)
307         file elc)
308     ;; Avoid barfing (from gnus-xmas) because the etc directory is not yet
309     ;; installed.
310     (when (featurep 'xemacs)
311       (setq gnus-xmas-glyph-directory "dummy"))
312     (dolist (file '(".dir-locals.el" "dgnushack.el" "lpath.el"))
313       (setq files (delete file files)))
314     (when (featurep 'base64)
315       (setq files (delete "base64.el" files)))
316     (condition-case code
317         ;; Under XEmacs 21.4 this loads easy-mmode.elc that provides
318         ;; the Emacs functions `propertize' and `replace-regexp-in-string'.
319         (require 'mh-e)
320       (error
321        (message "No mh-e: %s %s" (cadr code) (or (locate-library "mh-e") ""))
322        (setq files (delete "gnus-mh.el" files))))
323     (condition-case code
324         (require 'xml)
325       (error
326        (message "No xml: %s %s" (cadr code) (or (locate-library "xml") ""))
327        (setq files (delete "nnrss.el" files))))
328     (dolist (file
329              (if (featurep 'xemacs)
330                  '("md5.el")
331                '("gnus-xmas.el" "messagexmas.el" "nnheaderxm.el")))
332       (setq files (delete file files)))
333     (unless (and (fboundp 'libxml-parse-html-region)
334                  ;; lpath.el binds it.
335                  (not (eq (symbol-function 'libxml-parse-html-region)
336                           'ignore)))
337       (dolist (file '("color.el"))
338         (setq files (delete file files))))
339     (unless (locate-library "epg")
340       (setq files (delete "plstore.el" files)))
341     ;; Temporary code until we fix pcase and defmethod stuff.
342     (when (or (featurep 'xemacs)
343               (or (< emacs-major-version 24)
344                   (< emacs-minor-version 3)))
345       (setq files (delete "gnus-icalendar.el" files))
346       ;; Temporary during development.
347       (setq files (delete "gnus-cloud.el" files)))
348     ;; Prefer XEmacs mail-lib pkg if installed
349     (when (and (featurep 'xemacs)
350                (locate-library "mail-lib/_pkg"))
351       (dolist (file
352                '("rfc2104.el" "netrc.el" "pop3.el" "starttls.el" "tls.el"))
353         (setq files (delete file files))))
354     ;; Prefer XEmacs ecrypto pkg if installed
355     (when (and (featurep 'xemacs)
356                (locate-library "ecrypto/_pkg"))
357       (dolist (file '("md4.el" "sha1.el" "hex-util.el"))
358         (setq files (delete file files))))
359     ;; Prefer XEmacs net-utils pkg if installed
360     (when (and (featurep 'xemacs)
361                (locate-library "net-utils/_pkg"))
362       (dolist (file '("dig.el" "dns.el" "dns-mode.el"))
363         (setq files (delete file files))))
364     ;; Prefer XEmacs text-modes pkg if installed
365     (when (and (featurep 'xemacs)
366                (locate-library "text-modes/_pkg"))
367       (setq files (delete "format-spec.el" files)))
368     (dolist (file files)
369       (setq file (expand-file-name file srcdir))
370       (when (and (file-exists-p
371                   (setq elc (concat (file-name-nondirectory file) "c")))
372                  (file-newer-than-file-p file elc))
373         (delete-file elc)))
374
375     (while (setq file (pop files))
376       (setq file (expand-file-name file srcdir))
377       (when (or (not (file-exists-p
378                       (setq elc (concat (file-name-nondirectory file) "c"))))
379                 (file-newer-than-file-p file elc))
380         (if error-on-warn
381             (let ((byte-compile-error-on-warn t))
382               (unless (ignore-errors
383                         (dgnushack-compile-file file))
384                 (setq compilesuccess nil)))
385           (ignore-errors
386             (dgnushack-compile-file file)))))
387     compilesuccess))
388
389 (defun dgnushack-recompile ()
390   (require 'gnus)
391   (byte-recompile-directory "." 0))
392
393 (defvar dgnushack-gnus-load-file
394   (if (featurep 'xemacs)
395       (expand-file-name "auto-autoloads.el")
396     (expand-file-name "gnus-load.el")))
397
398 (defvar dgnushack-cus-load-file
399   (if (featurep 'xemacs)
400       (expand-file-name "custom-load.el")
401     (expand-file-name "cus-load.el")))
402
403 (defun dgnushack-make-cus-load ()
404   (load "cus-dep")
405   (let ((cusload-base-file dgnushack-cus-load-file))
406     (defadvice directory-files (after exclude-dir-locals activate)
407       "Exclude .dir-locals.el file."
408       (dolist (file ad-return-value)
409         (if (string-match "\\(?:\\`\\|/\\)\\.dir-locals\\.el\\'" file)
410             (setq ad-return-value (delete file ad-return-value)))))
411     (unwind-protect
412         (if (fboundp 'custom-make-dependencies)
413             (custom-make-dependencies)
414           (Custom-make-dependencies))
415       (ad-unadvise 'directory-files))
416     (when (featurep 'xemacs)
417       (message "Compiling %s..." dgnushack-cus-load-file)
418       (byte-compile-file dgnushack-cus-load-file))))
419
420 (defun dgnushack-make-auto-load ()
421   (require 'autoload)
422   (let ((generated-autoload-file dgnushack-gnus-load-file)
423         (make-backup-files nil)
424         (autoload-package-name "gnus"))
425     (if (featurep 'xemacs)
426         (if (file-exists-p generated-autoload-file)
427             (delete-file generated-autoload-file))
428       (with-temp-file generated-autoload-file
429         (insert ?\014)))
430     (defadvice directory-files (after exclude-dir-locals activate)
431       "Exclude .dir-locals.el file."
432       (dolist (file ad-return-value)
433         (if (string-match "\\(?:\\`\\|/\\)\\.dir-locals\\.el\\'" file)
434             (setq ad-return-value (delete file ad-return-value)))))
435     (unwind-protect
436         (batch-update-autoloads)
437       (ad-unadvise 'directory-files))))
438
439 (defun dgnushack-make-load ()
440   (unless (featurep 'xemacs)
441     (message "Generating %s..." dgnushack-gnus-load-file)
442     (with-temp-file dgnushack-gnus-load-file
443       (insert-file-contents dgnushack-cus-load-file)
444       (delete-file dgnushack-cus-load-file)
445       (goto-char (point-min))
446       (search-forward ";;; Code:")
447       (forward-line)
448       (delete-region (point-min) (point))
449       (insert "\
450 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
451 ;;
452 ;;; Code:
453 ")
454       (goto-char (point-max))
455       (if (search-backward "custom-versions-load-alist" nil t)
456           (forward-line -1)
457         (forward-line -1)
458         (while (eq (char-after) ?\;)
459           (forward-line -1))
460         (forward-line))
461       (delete-region (point) (point-max))
462       (insert "\n")
463       ;; smiley-* are duplicated. Remove them all.
464       (let ((point (point)))
465         (insert-file-contents dgnushack-gnus-load-file)
466         (goto-char point)
467         (while (search-forward "smiley-" nil t)
468           (beginning-of-line)
469           (if (looking-at "(autoload ")
470               (delete-region (point) (progn (forward-sexp) (point)))
471             (forward-line))))
472       ;;
473       (goto-char (point-max))
474       (when (search-backward "\n(provide " nil t)
475         (forward-line -1)
476         (delete-region (point) (point-max)))
477       (insert "\
478
479 \(provide 'gnus-load)
480
481 ;;; Local Variables:
482 ;;; version-control: never
483 ;;; no-byte-compile: t
484 ;;; no-update-autoloads: t
485 ;;; End:
486 ;;; gnus-load.el ends here
487 ")
488       ))
489   (message "Compiling %s..." dgnushack-gnus-load-file)
490   (byte-compile-file dgnushack-gnus-load-file)
491   (when (featurep 'xemacs)
492     (message "Creating dummy gnus-load.el...")
493     (with-temp-file (expand-file-name "gnus-load.el")
494       (insert "\
495
496 \(provide 'gnus-load)
497
498 ;;; Local Variables:
499 ;;; version-control: never
500 ;;; no-byte-compile: t
501 ;;; no-update-autoloads: t
502 ;;; End:
503 ;;; gnus-load.el ends here"))))
504
505 (defun dgnushack-find-lisp-shadows (&optional lispdir)
506   "Return a list of directories in which other Gnus installations exist.
507 This function looks for the other Gnus installations which will shadow
508 the new Gnus Lisp modules which have been installed in LISPDIR, using
509 the default `load-path'.  The return value will make sense only when
510 LISPDIR is existent and is listed in the default `load-path'.  Assume
511 LISPDIR will be prepended to `load-path' by a user if the default
512 `load-path' does not contain it."
513   (unless lispdir
514     (setq lispdir (getenv "lispdir")))
515   (when (and lispdir (file-directory-p lispdir))
516     (setq lispdir (file-truename (directory-file-name lispdir)))
517     (let ((indices '("gnus.elc" "gnus.el" "gnus.el.bz2" "gnus.el.gz"
518                      "message.elc" "message.el" "message.el.bz2"
519                      "message.el.gz"))
520           (path (delq nil (mapcar
521                            (lambda (p)
522                              (condition-case nil
523                                  (when (and p (file-directory-p p))
524                                    (file-truename (directory-file-name p)))
525                                (error nil)))
526                            dgnushack-default-load-path)))
527           rest elcs)
528       (while path
529         (setq rest (cons (car path) rest)
530               path (delete (car rest) (cdr path))))
531       (setq path (nreverse (cdr (member lispdir rest)))
532             rest nil)
533       (while path
534         (setq elcs indices)
535         (while elcs
536           (when (file-exists-p (expand-file-name (pop elcs) (car path)))
537             (setq rest (cons (car path) rest)
538                   elcs nil)))
539         (setq path (cdr path)))
540       (prog1
541           (setq path (nreverse rest))
542         (when path
543           (let (print-level print-length)
544             (princ (concat "\n\
545 WARNING: The other Gnus installation" (if (cdr path) "s have" " has") "\
546  been detected in:\n\n  " (mapconcat 'identity path "\n  ") "\n\n\
547 You will need to modify the run-time `load-path', remove them manually,
548 or remove them using `make remove-installed-shadows'.\n\n"))))))))
549
550 (defun dgnushack-remove-lisp-shadows (&optional lispdir)
551   "Remove the other Gnus installations which shadow the recent one."
552   (let ((path (with-temp-buffer
553                 (let ((standard-output (current-buffer)))
554                   (dgnushack-find-lisp-shadows lispdir))))
555         elcs files shadows file)
556     (when path
557       (unless (setq elcs (directory-files srcdir nil "\\.elc\\'"))
558         (error "You should build .elc files first."))
559       (setq files
560             (apply
561              'append
562              (mapcar
563               (lambda (el)
564                 (list (concat el "c") el (concat el ".bz2") (concat el ".gz")))
565               (append
566                (list (file-name-nondirectory dgnushack-gnus-load-file)
567                      (file-name-nondirectory dgnushack-cus-load-file))
568                (mapcar (lambda (elc) (substring elc 0 -1)) elcs)))))
569       (while path
570         (setq shadows files)
571         (while shadows
572           (setq file (expand-file-name (pop shadows) (car path)))
573           (when (file-exists-p file)
574             (princ (concat "  Removing " file "..."))
575             (condition-case nil
576                 (progn
577                   (delete-file file)
578                   (princ "done\n"))
579               (error (princ "failed\n")))))
580         (setq path (cdr path))))))
581
582 (unless (fboundp 'with-demoted-errors)
583   (defmacro with-demoted-errors (&rest body)
584     "Run BODY and demote any errors to simple messages.
585 If `debug-on-error' is non-nil, run BODY without catching its errors.
586 This is to be used around code which is not expected to signal an error
587 but which should be robust in the unexpected case that an error is signaled."
588     (declare (debug t) (indent 0))
589     (let ((err (make-symbol "err")))
590       `(condition-case ,err
591            (progn ,@body)
592          (error (message "Error: %S" ,err) nil)))))
593
594 ;; `define-obsolete-function-alias' and `define-obsolete-variable-alias'
595 ;; take only two arguments in XEmacs:
596 ;; (define-obsolete-function-alias OLDFUN NEWFUN)
597 ;; (define-obsolete-variable-alias OLDVAR NEWVAR)
598 (condition-case nil
599     (define-obsolete-function-alias
600       'dgnushack-obsolete-name 'dgnushack-current-name "0")
601   (wrong-number-of-arguments
602    (defadvice define-obsolete-function-alias (around ignore-rest-args
603                                                      (oldfun newfun &rest args)
604                                                      activate)
605      "Ignore arguments other than the 1st and the 2nd ones."
606      ad-do-it)
607    (put 'define-obsolete-function-alias 'byte-optimizer
608         (lambda (form)
609           (setcdr (nthcdr 2 form) nil)
610           form))))
611 (condition-case nil
612     (define-obsolete-variable-alias
613       'dgnushack-obsolete-name 'dgnushack-current-name "0")
614   (wrong-number-of-arguments
615    (defadvice define-obsolete-variable-alias (around ignore-rest-args
616                                                      (oldvar newvar &rest args)
617                                                      activate)
618      "Ignore arguments other than the 1st and the 2nd ones."
619      ad-do-it)
620    (put 'define-obsolete-variable-alias 'byte-optimizer
621         (lambda (form)
622           (setcdr (nthcdr 2 form) nil)
623           form))))
624
625 ;;; dgnushack.el ends here