diff options
| -rw-r--r-- | lisp/gnus/format-spec.el | 14 |
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. |
| 34 | FORMAT is a string containing `format'-like specs like \"bash %u %k\", | 34 | FORMAT is a string containing `format'-like specs like \"bash %u %k\", |
| 35 | while SPECIFICATION is an alist mapping from format spec characters | 35 | while SPECIFICATION is an alist mapping from format spec characters |
| 36 | to values." | 36 | to values. Any text properties on a %-spec itself are propagated to |
| 37 | the 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")))) |