aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2005-10-09 15:37:35 +0000
committerRichard M. Stallman2005-10-09 15:37:35 +0000
commit827d67f3b670d6dee517ebcfb00fe81f80519bdb (patch)
tree256ae6a62527fdd4f07ee0d6e8e58d9398f227b6
parent865729da260be99e14c91bbbea3a8108cf7d828c (diff)
downloademacs-827d67f3b670d6dee517ebcfb00fe81f80519bdb.tar.gz
emacs-827d67f3b670d6dee517ebcfb00fe81f80519bdb.zip
(format-spec): Propagate text properties of % spec.
-rw-r--r--lisp/gnus/format-spec.el14
1 files changed, 11 insertions, 3 deletions
diff --git a/lisp/gnus/format-spec.el b/lisp/gnus/format-spec.el
index fc34b50bc11..b2fde53b3f1 100644
--- a/lisp/gnus/format-spec.el
+++ b/lisp/gnus/format-spec.el
@@ -33,7 +33,8 @@
33 "Return a string based on FORMAT and SPECIFICATION. 33 "Return a string based on FORMAT and SPECIFICATION.
34FORMAT is a string containing `format'-like specs like \"bash %u %k\", 34FORMAT is a string containing `format'-like specs like \"bash %u %k\",
35while SPECIFICATION is an alist mapping from format spec characters 35while SPECIFICATION is an alist mapping from format spec characters
36to values." 36to values. Any text properties on a %-spec itself are propagated to
37the text that it generates."
37 (with-temp-buffer 38 (with-temp-buffer
38 (insert format) 39 (insert format)
39 (goto-char (point-min)) 40 (goto-char (point-min))
@@ -47,10 +48,17 @@ to values."
47 (let* ((num (match-string 1)) 48 (let* ((num (match-string 1))
48 (spec (string-to-char (match-string 2))) 49 (spec (string-to-char (match-string 2)))
49 (val (cdr (assq spec specification)))) 50 (val (cdr (assq spec specification))))
50 (delete-region (1- (match-beginning 0)) (match-end 0))
51 (unless val 51 (unless val
52 (error "Invalid format character: %s" spec)) 52 (error "Invalid format character: %s" spec))
53 (insert (format (concat "%" num "s") val)))) 53 ;; Pad result to desired length.
54 (let ((text (format (concat "%" num "s") val)))
55 ;; Insert first, to preserve text properties.
56 (insert-and-inherit text)
57 ;; Delete the specifier body.
58 (delete-region (+ (match-beginning 0) (length text))
59 (+ (match-end 0) (length text)))
60 ;; Delete the percent sign.
61 (delete-region (1- (match-beginning 0)) (match-beginning 0)))))
54 ;; Signal an error on bogus format strings. 62 ;; Signal an error on bogus format strings.
55 (t 63 (t
56 (error "Invalid format string")))) 64 (error "Invalid format string"))))