From 88c18efb3a1b9e48a5fb72b80cc7cdd5d03fa894 Mon Sep 17 00:00:00 2001 From: Stephen Gildea Date: Wed, 15 Oct 2025 20:42:07 -0700 Subject: [PATCH] time-stamp: padding with mixed uni- and multibyte * lisp/time-stamp.el (time-stamp-string-preprocess): Use 'length' instead of 'format' to calculate string padding, so that we consistently count characters, not bytes. --- lisp/time-stamp.el | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lisp/time-stamp.el b/lisp/time-stamp.el index faf5d51d441..1280c86bcbe 100644 --- a/lisp/time-stamp.el +++ b/lisp/time-stamp.el @@ -769,16 +769,21 @@ and all `time-stamp-format' compatibility." (eq cur-char ?X)) ;full system name, experimental (system-name)) )) - (and (numberp field-result) - (= colon-cnt 0) - (or (string-equal field-width "") - (string-equal field-width "0")) - ;; no width provided; set width for default - (setq field-width "02")) - (format (format "%%%s%c" - field-width - (if (numberp field-result) ?d ?s)) - (or field-result "")))))) ;end of handle-one-conversion + (if (numberp field-result) + (progn + (and (= colon-cnt 0) + (or (string-equal field-width "") + (string-equal field-width "0")) + ;; no width provided; set width for default + (setq field-width "02")) + (format (format "%%%sd" field-width) + (or field-result ""))) + (let* ((field-width-num (string-to-number field-width)) + (needed-padding (- field-width-num (length field-result)))) + (if (> needed-padding 0) + (concat (make-string needed-padding ?\s) field-result) + field-result))) + )))) ;end of handle-one-conversion ;; iterate over the format string (while (< ind fmt-len) (setq cur-char (aref format ind))