Function: magit--format-spec
magit--format-spec is a byte-compiled function defined in
magit-base.el.
Signature
(magit--format-spec FORMAT SPECIFICATION)
Documentation
Like format-spec but preserve text properties in SPECIFICATION.
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-base.el
(defun magit--format-spec (format specification)
"Like `format-spec' but preserve text properties in SPECIFICATION."
(with-temp-buffer
(insert format)
(goto-char (point-min))
(while (search-forward "%" nil t)
(cond
;; Quoted percent sign.
((eq (char-after) ?%)
(delete-char 1))
;; Valid format spec.
((looking-at "\\([-0-9.]*\\)\\([a-zA-Z]\\)")
(let* ((num (match-str 1))
(spec (string-to-char (match-str 2)))
(val (assq spec specification)))
(unless val
(error "Invalid format character: `%%%c'" spec))
(setq val (cdr val))
;; Pad result to desired length.
(let ((text (format (concat "%" num "s") val)))
;; Insert first, to preserve text properties.
(if (next-property-change 0 (concat " " text))
;; If the inserted text has properties, then preserve those.
(insert text)
;; Otherwise preserve FORMAT's properties, like `format-spec'.
(insert-and-inherit text))
;; Delete the specifier body.
(delete-region (+ (match-beginning 0) (length text))
(+ (match-end 0) (length text)))
;; Delete the percent sign.
(delete-region (1- (match-beginning 0)) (match-beginning 0)))))
;; Signal an error on bogus format strings.
((error "Invalid format string"))))
(buffer-string)))