--- gnus-spec.el.orig Wed Feb 20 00:15:32 2002 +++ gnus-spec.el Sat Oct 12 16:38:48 2002 @@ -396,6 +396,24 @@ ,(when (not side) '(make-string need ?\ ))) val))))) +(defun gnus-simple-format (str &rest objects) + ;; A replacement for FORMAT which only handles %s and %% formats. + ;; Xemacs FORMAT does not preserve text properties on the input + ;; strings, whereas this version does. Without this function, returning + ;; strings with properties set from user-defined spec functions does not + ;; work in xemacs. Arguably, this function should just be an alias for + ;; format in FSF emacs (where properties are preserved), for speed if + ;; nothing else. + (with-temp-buffer + (insert str) + (goto-char (point-min)) + (while (search-forward "%s" nil t) + (let ((obj (car objects))) + (replace-match (if (stringp obj) obj (format "%s" obj)) + nil t)) + (setq objects (cdr objects))) + (gnus-replace-in-string (buffer-string) "%%" "%"))) + (defun gnus-parse-format (format spec-alist &optional insert) ;; This function parses the FORMAT string with the help of the ;; SPEC-ALIST and returns a list that can be eval'ed to return the @@ -642,6 +660,19 @@ ;; A single string spec in the end of the spec. ((string-match "\\`\\([^%]+\\)%[sc]\\'" fstring) (list (match-string 1 fstring) (car flist))) + ;; Nothing but %% and (bare) %s specs. + ;; We use a special replacement for format here to work around the + ;; fact that XEmacs FORMAT does not preserve text properties, + ;; without having to reimplement FORMAT in all its glory. + ;; The code above never uses format codes other than %% and %s for + ;; XEmacs in any case. (It uses %NNNs if gnus-use-correct-string-widths + ;; is not set, but we don't consider that here - it's a non-standard + ;; case and complicates the implementation of gnus-simple-format). + ;; Only do this for XEmacs, as we don't want FSF Emacs users to suffer + ;; an unnecessary performance hit. + ((and (featurep 'xemacs) + (string-match "\\`\\([^%]\\|%[s%]\\)*\\'" fstring))) + (list (cons 'gnus-simple-format (cons fstring (nreverse flist))))) ;; A more complex spec. (t (list (cons 'format (cons fstring (nreverse flist)))))))