diff options
| author | Philipp Stephani | 2017-06-01 00:09:43 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2017-06-02 00:22:13 +0200 |
| commit | 0dd1bbb0bb228acab21b8e16f2f2a0b5a17b19ab (patch) | |
| tree | 279fbd070724c1d04945b69db32eb69957274e72 /lisp | |
| parent | 404273aeacba39833ae3a38ce6764cc7a636e9d9 (diff) | |
| download | emacs-0dd1bbb0bb228acab21b8e16f2f2a0b5a17b19ab.tar.gz emacs-0dd1bbb0bb228acab21b8e16f2f2a0b5a17b19ab.zip | |
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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 12a7d4afc2a..e5b9b47b1d0 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el | |||
| @@ -1375,10 +1375,15 @@ extra args." | |||
| 1375 | (let ((nfields (with-temp-buffer | 1375 | (let ((nfields (with-temp-buffer |
| 1376 | (insert (nth 1 form)) | 1376 | (insert (nth 1 form)) |
| 1377 | (goto-char (point-min)) | 1377 | (goto-char (point-min)) |
| 1378 | (let ((n 0)) | 1378 | (let ((i 0) (n 0)) |
| 1379 | (while (re-search-forward "%." nil t) | 1379 | (while (re-search-forward "%." nil t) |
| 1380 | (unless (eq ?% (char-after (1+ (match-beginning 0)))) | 1380 | (backward-char) |
| 1381 | (setq n (1+ n)))) | 1381 | (unless (eq ?% (char-after)) |
| 1382 | (setq i (if (looking-at "\\([0-9]+\\)\\$") | ||
| 1383 | (string-to-number (match-string 1) 10) | ||
| 1384 | (1+ i)) | ||
| 1385 | n (max n i))) | ||
| 1386 | (forward-char)) | ||
| 1382 | n))) | 1387 | n))) |
| 1383 | (nargs (- (length form) 2))) | 1388 | (nargs (- (length form) 2))) |
| 1384 | (unless (= nargs nfields) | 1389 | (unless (= nargs nfields) |