1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-07 06:50:23 -08:00

Implement field numbers in format strings

A field number explicitly specifies the argument to be formatted.
This is especially important for potential localization work, since
grammars of various languages dictate different word orders.

* src/editfns.c (Fformat): Update documentation.
(styled_format): Implement field numbers.

* doc/lispref/strings.texi (Formatting Strings): Document field numbers.

* lisp/emacs-lisp/bytecomp.el (byte-compile-format-warn): Adapt.

* test/src/editfns-tests.el (format-with-field): New unit test.
This commit is contained in:
Philipp Stephani 2017-06-01 00:09:43 +02:00
parent 404273aeac
commit 0dd1bbb0bb
5 changed files with 104 additions and 14 deletions

View file

@ -1375,10 +1375,15 @@ extra args."
(let ((nfields (with-temp-buffer
(insert (nth 1 form))
(goto-char (point-min))
(let ((n 0))
(let ((i 0) (n 0))
(while (re-search-forward "%." nil t)
(unless (eq ?% (char-after (1+ (match-beginning 0))))
(setq n (1+ n))))
(backward-char)
(unless (eq ?% (char-after))
(setq i (if (looking-at "\\([0-9]+\\)\\$")
(string-to-number (match-string 1) 10)
(1+ i))
n (max n i)))
(forward-char))
n)))
(nargs (- (length form) 2)))
(unless (= nargs nfields)