From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/47259 Path: main.gmane.org!not-for-mail From: Paul Moore Newsgroups: gmane.emacs.gnus.general Subject: Re: User format functions - text properies get lost (XEmacs) Date: Thu, 17 Oct 2002 20:48:28 +0100 Sender: owner-ding@hpc.uh.edu Message-ID: References: <848z0xp6dd.fsf@crybaby.cs.uni-dortmund.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: main.gmane.org 1034885172 27522 80.91.224.249 (17 Oct 2002 20:06:12 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 17 Oct 2002 20:06:12 +0000 (UTC) Return-path: Original-Received: from malifon.math.uh.edu ([129.7.128.13]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 182GuJ-00079m-00 for ; Thu, 17 Oct 2002 22:06:11 +0200 Original-Received: from sina.hpc.uh.edu ([129.7.128.10] ident=lists) by malifon.math.uh.edu with esmtp (Exim 3.20 #1) id 182GtJ-0003vG-00; Thu, 17 Oct 2002 15:05:09 -0500 Original-Received: by sina.hpc.uh.edu (TLB v0.09a (1.20 tibbs 1996/10/09 22:03:07)); Thu, 17 Oct 2002 15:05:51 -0500 (CDT) Original-Received: from sclp3.sclp.com (qmailr@sclp3.sclp.com [209.196.61.66]) by sina.hpc.uh.edu (8.9.3/8.9.3) with SMTP id PAA08489 for ; Thu, 17 Oct 2002 15:05:31 -0500 (CDT) Original-Received: (qmail 19051 invoked by alias); 17 Oct 2002 20:04:42 -0000 Original-Received: (qmail 19046 invoked from network); 17 Oct 2002 20:04:41 -0000 Original-Received: from anchor-post-33.mail.demon.net (194.217.242.91) by gnus.org with SMTP; 17 Oct 2002 20:04:41 -0000 Original-Received: from morpheus.demon.co.uk ([158.152.8.30]) by anchor-post-33.mail.demon.net with smtp (Exim 3.35 #1) id 182Gsm-00098M-0X for ding@gnus.org; Thu, 17 Oct 2002 21:04:37 +0100 Original-Received: from morpheus.demon.co.uk [127.0.0.1] by morpheus.demon.co.uk (127.0.0.1) (userid 1) with Hamster-NewsToMail-Gate (Classic Hamster Vr. 1.3 Build 1.3.23.191) ; Thu, 17 Oct 2002 20:48:28 +0100 X-Newsgroups: lists.ding Original-Lines: 34 User-Agent: Gnus/5.090008 (Oort Gnus v0.08) XEmacs/21.5 (brussels sprouts, i586-pc-win32) Hamster/1.3.23.191 Cancel-Lock: sha1:MqP9p4VddI5YDIgWZucskiA2HYM= Original-To: ding@gnus.org X-Gate: Hamster/1.3.23.191 NewsToMail-Gate Precedence: list X-Majordomo: 1.94.jlt7 Xref: main.gmane.org gmane.emacs.gnus.general:47259 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:47259 --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Großjohann) writes: > Two issues come to my mind. First of all, what happens if you have > "%%s" in the string? I think that this function is buggy in that > case. Secondly, converting the string to a buffer and then (for > gnus-replace-in-string) back to a string does not appear to be very > efficient. You're right on both counts. > Maybe you could search for the regexp "%[%s]", the look at > match-string (that's what actually matched the regex) and do > different things depending on that. Does this make sense? It does. I've updated the patch (attached) to do the following: 1. Adds a customisation variable gnus-make-format-preserve-properties, which allows the user to switch the behaviour off if they don't need/want it. 2. Rewrote the format replacement function to take into account your comments, and added support for pad widths (%10s), as they can occur if gnus-use-correct-string-widths is nil. I didn't do precision (%.5s) as that should never happen. Otherwise, it does the same as the previous one. Cheers, Paul. -- This signature intentionally left blank --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=gnus-spec.el.patch Content-Description: Revised patch to gnus-spec.el --- gnus-spec.el.orig Fri Oct 11 13:14:39 2002 +++ gnus-spec.el Thu Oct 17 16:26:23 2002 @@ -35,6 +35,12 @@ :group 'gnus-format :type 'boolean) +(defcustom gnus-make-format-preserve-properties (featurep 'xemacs) + "*If non-nil, use a replacement `format' function which preserves +text properties. This is only needed on XEmacs, as FSF Emacs does this anyway." + :group 'gnus-format + :type 'boolean) + ;;; Internal variables. (defvar gnus-summary-mark-positions nil) @@ -479,6 +485,41 @@ (nth 1 sform))))) form))) + +(defun gnus-xmas-format (fstring &rest args) + "A version of `format' which preserves text properties. + +Required for XEmacs, where the built in `format' function strips all text +properties from both the format string and any inserted strings. + +Only supports the format sequence %s, and %% for inserting +literal % characters. A pad width and an optional - (to right pad) +are supported for %s." + (let ((re "%%\\|%\\(-\\)?\\([1-9][0-9]*\\)?s") + (n (length args))) + (with-temp-buffer + (insert-string fstring) + (goto-char (point-min)) + (while (re-search-forward re nil t) + (goto-char (match-end 0)) + (cond + ((string= (match-string 0) "%%") + (delete-char -1)) + (t + (if (null args) + (error 'wrong-number-of-arguments #'my-format n fstring)) + (let* ((minlen (string-to-int (or (match-string 2) ""))) + (arg (car args)) + (str (if (stringp arg) arg (format "%s" arg))) + (lpad (null (match-string 1))) + (padlen (max 0 (- minlen (length str))))) + (replace-match "") + (if lpad (insert-char ?\ padlen)) + (insert str) + (unless lpad (insert-char ?\ padlen)) + (setq args (cdr args)))))) + (buffer-string)))) + (defun gnus-parse-simple-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 a @@ -644,6 +685,13 @@ ;; A single string spec in the end of the spec. ((string-match "\\`\\([^%]+\\)%[sc]\\'" fstring) (list (match-string 1 fstring) (car flist))) + ;; Only string (and %) specs (XEmacs only!) + ((and (featurep 'xemacs) + gnus-make-format-preserve-properties + (string-match + "\\`\\([^%]*\\(%%\\|%-?\\([1-9][0-9]*\\)?s\\)\\)*[^%]*\\'" + fstring)) + (list (cons 'gnus-xmas-format (cons fstring (nreverse flist))))) ;; A more complex spec. (t (list (cons 'format (cons fstring (nreverse flist))))))) --=-=-=--