Call format-spec substitution functions in current buffer

* lisp/format-spec.el (format-spec): Call format-spec substitution
functions in current buffer.  I.e., in the same buffer in which
substitution expressions are evaluated.  Previously functions were
instead called in the temporary buffer used to deal with FORMAT.
This commit is contained in:
Jonas Bernoulli 2026-04-27 21:11:52 +02:00
parent 1538090889
commit 046db64044
No known key found for this signature in database
GPG key ID: 230C2EFBB326D927

View file

@ -87,6 +87,7 @@ any occurrences of \"%%\" in FORMAT verbatim in the result.
If SPLIT, instead of returning a single string, a list of strings
is returned, where each format spec is its own element."
(let ((orig-buffer (current-buffer)))
(with-temp-buffer
(let ((split-start (point-min))
(split-result nil))
@ -110,7 +111,10 @@ is returned, where each format spec is its own element."
(trunc (match-string 3))
(char (string-to-char (match-string 4)))
(text (let ((res (cdr (assq char specification))))
(if (functionp res) (funcall res) res))))
(if (functionp res)
(with-current-buffer orig-buffer
(funcall res))
res))))
(when (and split
(not (= (1- beg) split-start)))
(push (buffer-substring split-start (1- beg)) split-result))
@ -142,7 +146,7 @@ is returned, where each format spec is its own element."
(buffer-string)
(unless (= split-start (point-max))
(push (buffer-substring split-start (point-max)) split-result))
(nreverse split-result)))))
(nreverse split-result))))))
(defun format-spec--do-flags (str flags width trunc)
"Return STR formatted according to FLAGS, WIDTH, and TRUNC.