From: Paul Moore <gustav@morpheus.demon.co.uk>
Subject: Re: User format functions - text properies get lost (XEmacs)
Date: Thu, 17 Oct 2002 20:48:28 +0100 [thread overview]
Message-ID: <n2m-g.ptu8q22b.fsf@morpheus.demon.co.uk> (raw)
In-Reply-To: <848z0xp6dd.fsf@crybaby.cs.uni-dortmund.de>
[-- Attachment #1: Type: text/plain, Size: 1144 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Revised patch to gnus-spec.el --]
[-- Type: text/x-patch, Size: 2535 bytes --]
--- 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)))))))
next prev parent reply other threads:[~2002-10-17 19:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-12 15:39 Paul Moore
2002-10-14 12:01 ` Kai Großjohann
2002-10-14 21:00 ` Paul Moore
2002-10-15 9:24 ` Kai Großjohann
2002-10-16 20:18 ` Paul Moore
2002-10-17 13:03 ` Kai Großjohann
2002-10-17 19:34 ` Paul Moore
2002-10-17 13:00 ` Kai Großjohann
2002-10-17 19:48 ` Paul Moore [this message]
2002-10-18 14:34 ` Kai Großjohann
2002-10-18 18:15 ` Paul Moore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=n2m-g.ptu8q22b.fsf@morpheus.demon.co.uk \
--to=gustav@morpheus.demon.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).