ec791a867315cd4ca1b83486615efe34a7361956
[gnus] / lisp / dgnushack.el
1 ;;; dgnushack.el --- a hack to set the load path for byte-compiling
2 ;; Copyright (C) 1994-2015 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                  (equal (nth 1 form) ''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     (dolist (file files)
349       (setq file (expand-file-name file srcdir))
350       (when (and (file-exists-p
351                   (setq elc (concat (file-name-nondirectory file) "c")))
352                  (file-newer-than-file-p file elc))
353         (delete-file elc)))
354
355     (while (setq file (pop files))
356       (setq file (expand-file-name file srcdir))
357       (when (or (not (file-exists-p
358                       (setq elc (concat (file-name-nondirectory file) "c"))))
359                 (file-newer-than-file-p file elc))
360         (if error-on-warn
361             (let ((byte-compile-error-on-warn t))
362               (unless (ignore-errors
363                         (dgnushack-compile-file file))
364                 (setq compilesuccess nil)))
365           (ignore-errors
366             (dgnushack-compile-file file)))))
367     compilesuccess))
368
369 (defun dgnushack-recompile ()
370   (require 'gnus)
371   (byte-recompile-directory "." 0))
372
373 (defvar dgnushack-gnus-load-file
374   (if (featurep 'xemacs)
375       (expand-file-name "auto-autoloads.el")
376     (expand-file-name "gnus-load.el")))
377
378 (defvar dgnushack-cus-load-file
379   (if (featurep 'xemacs)
380       (expand-file-name "custom-load.el")
381     (expand-file-name "cus-load.el")))
382
383 (defun dgnushack-make-cus-load ()
384   (load "cus-dep")
385   (let ((cusload-base-file dgnushack-cus-load-file))
386     (defadvice directory-files (after exclude-dir-locals activate)
387       "Exclude .dir-locals.el file."
388       (dolist (file ad-return-value)
389         (if (string-match "\\(?:\\`\\|/\\)\\.dir-locals\\.el\\'" file)
390             (setq ad-return-value (delete file ad-return-value)))))
391     (unwind-protect
392         (if (fboundp 'custom-make-dependencies)
393             (custom-make-dependencies)
394           (Custom-make-dependencies))
395       (ad-unadvise 'directory-files))
396     (when (featurep 'xemacs)
397       (message "Compiling %s..." dgnushack-cus-load-file)
398       (byte-compile-file dgnushack-cus-load-file))))
399
400 (defun dgnushack-make-auto-load ()
401   (require 'autoload)
402   (let ((generated-autoload-file dgnushack-gnus-load-file)
403         (make-backup-files nil)
404         (autoload-package-name "gnus"))
405     (if (featurep 'xemacs)
406         (if (file-exists-p generated-autoload-file)
407             (delete-file generated-autoload-file))
408       (with-temp-file generated-autoload-file
409         (insert ?\014)))
410     (defadvice directory-files (after exclude-dir-locals activate)
411       "Exclude .dir-locals.el file."
412       (dolist (file ad-return-value)
413         (if (string-match "\\(?:\\`\\|/\\)\\.dir-locals\\.el\\'" file)
414             (setq ad-return-value (delete file ad-return-value)))))
415     (unwind-protect
416         (batch-update-autoloads)
417       (ad-unadvise 'directory-files))))
418
419 (defun dgnushack-make-load ()
420   (unless (featurep 'xemacs)
421     (message "Generating %s..." dgnushack-gnus-load-file)
422     (with-temp-file dgnushack-gnus-load-file
423       (insert-file-contents dgnushack-cus-load-file)
424       (delete-file dgnushack-cus-load-file)
425       (goto-char (point-min))
426       (search-forward ";;; Code:")
427       (forward-line)
428       (delete-region (point-min) (point))
429       (insert "\
430 ;;; gnus-load.el --- automatically extracted custom dependencies and autoload
431 ;;
432 ;;; Code:
433 ")
434       (goto-char (point-max))
435       (if (search-backward "custom-versions-load-alist" nil t)
436           (forward-line -1)
437         (forward-line -1)
438         (while (eq (char-after) ?\;)
439           (forward-line -1))
440         (forward-line))
441       (delete-region (point) (point-max))
442       (insert "\n")
443       ;; smiley-* are duplicated. Remove them all.
444       (let ((point (point)))
445         (insert-file-contents dgnushack-gnus-load-file)
446         (goto-char point)
447         (while (search-forward "smiley-" nil t)
448           (beginning-of-line)
449           (if (looking-at "(autoload ")
450               (delete-region (point) (progn (forward-sexp) (point)))
451             (forward-line))))
452       ;;
453       (goto-char (point-max))
454       (when (search-backward "\n(provide " nil t)
455         (forward-line -1)
456         (delete-region (point) (point-max)))
457       (insert "\
458
459 \(provide 'gnus-load)
460
461 ;;; Local Variables:
462 ;;; version-control: never
463 ;;; no-byte-compile: t
464 ;;; no-update-autoloads: t
465 ;;; End:
466 ;;; gnus-load.el ends here
467 ")
468       ))
469   (message "Compiling %s..." dgnushack-gnus-load-file)
470   (byte-compile-file dgnushack-gnus-load-file)
471   (when (featurep 'xemacs)
472     (message "Creating dummy gnus-load.el...")
473     (with-temp-file (expand-file-name "gnus-load.el")
474       (insert "\
475
476 \(provide 'gnus-load)
477
478 ;;; Local Variables:
479 ;;; version-control: never
480 ;;; no-byte-compile: t
481 ;;; no-update-autoloads: t
482 ;;; End:
483 ;;; gnus-load.el ends here"))))
484
485 (defun dgnushack-find-lisp-shadows (&optional lispdir)
486   "Return a list of directories in which other Gnus installations exist.
487 This function looks for the other Gnus installations which will shadow
488 the new Gnus Lisp modules which have been installed in LISPDIR, using
489 the default `load-path'.  The return value will make sense only when
490 LISPDIR is existent and is listed in the default `load-path'.  Assume
491 LISPDIR will be prepended to `load-path' by a user if the default
492 `load-path' does not contain it."
493   (unless lispdir
494     (setq lispdir (getenv "lispdir")))
495   (when (and lispdir (file-directory-p lispdir))
496     (setq lispdir (file-truename (directory-file-name lispdir)))
497     (let ((indices '("gnus.elc" "gnus.el" "gnus.el.bz2" "gnus.el.gz"
498                      "message.elc" "message.el" "message.el.bz2"
499                      "message.el.gz"))
500           (path (delq nil (mapcar
501                            (lambda (p)
502                              (condition-case nil
503                                  (when (and p (file-directory-p p))
504                                    (file-truename (directory-file-name p)))
505                                (error nil)))
506                            dgnushack-default-load-path)))
507           rest elcs)
508       (while path
509         (setq rest (cons (car path) rest)
510               path (delete (car rest) (cdr path))))
511       (setq path (nreverse (cdr (member lispdir rest)))
512             rest nil)
513       (while path
514         (setq elcs indices)
515         (while elcs
516           (when (file-exists-p (expand-file-name (pop elcs) (car path)))
517             (setq rest (cons (car path) rest)
518                   elcs nil)))
519         (setq path (cdr path)))
520       (prog1
521           (setq path (nreverse rest))
522         (when path
523           (let (print-level print-length)
524             (princ (concat "\n\
525 WARNING: The other Gnus installation" (if (cdr path) "s have" " has") "\
526  been detected in:\n\n  " (mapconcat 'identity path "\n  ") "\n\n\
527 You will need to modify the run-time `load-path', remove them manually,
528 or remove them using `make remove-installed-shadows'.\n\n"))))))))
529
530 (defun dgnushack-remove-lisp-shadows (&optional lispdir)
531   "Remove the other Gnus installations which shadow the recent one."
532   (let ((path (with-temp-buffer
533                 (let ((standard-output (current-buffer)))
534                   (dgnushack-find-lisp-shadows lispdir))))
535         elcs files shadows file)
536     (when path
537       (unless (setq elcs (directory-files srcdir nil "\\.elc\\'"))
538         (error "You should build .elc files first."))
539       (setq files
540             (apply
541              'append
542              (mapcar
543               (lambda (el)
544                 (list (concat el "c") el (concat el ".bz2") (concat el ".gz")))
545               (append
546                (list (file-name-nondirectory dgnushack-gnus-load-file)
547                      (file-name-nondirectory dgnushack-cus-load-file))
548                (mapcar (lambda (elc) (substring elc 0 -1)) elcs)))))
549       (while path
550         (setq shadows files)
551         (while shadows
552           (setq file (expand-file-name (pop shadows) (car path)))
553           (when (file-exists-p file)
554             (princ (concat "  Removing " file "..."))
555             (condition-case nil
556                 (progn
557                   (delete-file file)
558                   (princ "done\n"))
559               (error (princ "failed\n")))))
560         (setq path (cdr path))))))
561
562 (unless (fboundp 'with-demoted-errors)
563   (defmacro with-demoted-errors (&rest body)
564     "Run BODY and demote any errors to simple messages.
565 If `debug-on-error' is non-nil, run BODY without catching its errors.
566 This is to be used around code which is not expected to signal an error
567 but which should be robust in the unexpected case that an error is signaled."
568     (declare (debug t) (indent 0))
569     (let ((err (make-symbol "err")))
570       `(condition-case ,err
571            (progn ,@body)
572          (error (message "Error: %S" ,err) nil)))))
573
574 ;; `define-obsolete-function-alias' and `define-obsolete-variable-alias'
575 ;; take only two arguments in XEmacs:
576 ;; (define-obsolete-function-alias OLDFUN NEWFUN)
577 ;; (define-obsolete-variable-alias OLDVAR NEWVAR)
578 (condition-case nil
579     (define-obsolete-function-alias
580       'dgnushack-obsolete-name 'dgnushack-current-name "0")
581   (wrong-number-of-arguments
582    (defadvice define-obsolete-function-alias (around ignore-rest-args
583                                                      (oldfun newfun &rest args)
584                                                      activate)
585      "Ignore arguments other than the 1st and the 2nd ones."
586      ad-do-it)
587    (put 'define-obsolete-function-alias 'byte-optimizer
588         (lambda (form)
589           (setcdr (nthcdr 2 form) nil)
590           form))))
591 (condition-case nil
592     (define-obsolete-variable-alias
593       'dgnushack-obsolete-name 'dgnushack-current-name "0")
594   (wrong-number-of-arguments
595    (defadvice define-obsolete-variable-alias (around ignore-rest-args
596                                                      (oldvar newvar &rest args)
597                                                      activate)
598      "Ignore arguments other than the 1st and the 2nd ones."
599      ad-do-it)
600    (put 'define-obsolete-variable-alias 'byte-optimizer
601         (lambda (form)
602           (setcdr (nthcdr 2 form) nil)
603           form))))
604
605 ;;; dgnushack.el ends here