+(when (and (not (featurep 'xemacs))
+ (= emacs-major-version 21)
+ (>= emacs-minor-version 3)
+ (condition-case code
+ (let ((byte-compile-error-on-warn t))
+ (byte-optimize-form (quote (pop x)) t)
+ nil)
+ (error (string-match "called for effect"
+ (error-message-string code)))))
+ (defadvice byte-optimize-form-code-walker (around silence-warn-for-pop
+ (form for-effect)
+ activate)
+ "Silence the warning \"...called for effect\" for the `pop' form.
+It is effective only when the `pop' macro is defined by cl.el rather
+than subr.el."
+ (let (tmp)
+ (if (and (eq (car-safe form) 'car)
+ for-effect
+ (setq tmp (get 'car 'side-effect-free))
+ (not byte-compile-delete-errors)
+ (not (eq tmp 'error-free))
+ (eq (car-safe (cadr form)) 'prog1)
+ (let ((var (cadr (cadr form)))
+ (last (nth 2 (cadr form))))
+ (and (symbolp var)
+ (null (nthcdr 3 (cadr form)))
+ (eq (car-safe last) 'setq)
+ (eq (cadr last) var)
+ (eq (car-safe (nth 2 last)) 'cdr)
+ (eq (cadr (nth 2 last)) var))))
+ (progn
+ (put 'car 'side-effect-free 'error-free)
+ (unwind-protect
+ ad-do-it
+ (put 'car 'side-effect-free tmp)))
+ ad-do-it))))
+
+(when (and (not (featurep 'xemacs))
+ (byte-optimize-form
+ '(and (> 0 1)
+ (message "This should not appear in the byte-code."))
+ t))
+ (defadvice byte-optimize-form-code-walker
+ (around fix-bug-in-and/or-forms (form for-effect) activate)
+ "Optimize the rest of the and/or forms.
+It has been fixed in XEmacs before releasing 21.4 and also has been
+fixed in Emacs 22."
+ (if (and for-effect (memq (car-safe form) '(and or)))
+ (let ((fn (car form))
+ (backwards (reverse (cdr form))))
+ (while (and backwards
+ (null (setcar backwards
+ (byte-optimize-form (car backwards) t))))
+ (setq backwards (cdr backwards)))
+ (if (and (cdr form) (null backwards))
+ (byte-compile-log
+ " all subforms of %s called for effect; deleted" form))
+ (when backwards
+ (setcdr backwards
+ (mapcar 'byte-optimize-form (cdr backwards))))
+ (setq ad-return-value (cons fn (nreverse backwards))))
+ ad-do-it)))
+
+;; Work around for an incompatibility (XEmacs 21.4 vs. 21.5), see the
+;; following threads:
+;;
+;; http://thread.gmane.org/gmane.emacs.gnus.general/56414
+;; Subject: attachment problems found but not fixed
+;;
+;; http://thread.gmane.org/gmane.emacs.gnus.general/56459
+;; Subject: Splitting mail -- XEmacs 21.4 vs 21.5
+;;
+;; http://thread.gmane.org/gmane.emacs.xemacs.beta/20519
+;; Subject: XEmacs 21.5 and Gnus fancy splitting.
+;;
+;; Should be fixed in XEmacs (March 2007).
+;; http://thread.gmane.org/gmane.emacs.xemacs.patches/8124
+;; When should we remove this workaround?
+;;
+(when (and (featurep 'xemacs)
+ (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
+ (modify-syntax-entry ?= " " table)
+ (with-temp-buffer
+ (with-syntax-table table
+ (insert "foo=bar")
+ (goto-char (point-min))
+ (forward-sexp 1)
+ (eolp)))))
+ ;; The original `with-syntax-table' uses `copy-syntax-table' which
+ ;; doesn't seem to copy modified syntax entries in XEmacs 21.5.
+ (defmacro with-syntax-table (syntab &rest body)
+ "Evaluate BODY with the SYNTAB as the current syntax table."
+ `(let ((stab (syntax-table)))
+ (unwind-protect
+ (progn
+ ;;(set-syntax-table (copy-syntax-table ,syntab))
+ (set-syntax-table ,syntab)
+ ,@body)
+ (set-syntax-table stab)))))
+