diff options
| author | Eli Zaretskii | 2016-07-09 11:01:17 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2016-07-09 11:01:17 +0300 |
| commit | 0a2aedfe6d650e825a50f25f972bac20d669f5cb (patch) | |
| tree | 28e53a5fc20ec6531b6f5179a09d4f503e317345 | |
| parent | e52ad7fdfc7148a75897c92588712169894f7a5c (diff) | |
| download | emacs-0a2aedfe6d650e825a50f25f972bac20d669f5cb.tar.gz emacs-0a2aedfe6d650e825a50f25f972bac20d669f5cb.zip | |
Minor tweaks of copying text properties when padding strings
* src/editfns.c (styled_format): Don't include padding on the left
in the properties at the beginning of the string. (Bug#23897)
* test/src/editfns-tests.el (format-properties): Add tests for
faces when the string is padded on the left or on the right.
| -rw-r--r-- | src/editfns.c | 2 | ||||
| -rw-r--r-- | test/src/editfns-tests.el | 28 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/editfns.c b/src/editfns.c index 73f024409b1..4c8336b8c82 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -4175,13 +4175,13 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) | |||
| 4175 | convbytes += padding; | 4175 | convbytes += padding; |
| 4176 | if (convbytes <= buf + bufsize - p) | 4176 | if (convbytes <= buf + bufsize - p) |
| 4177 | { | 4177 | { |
| 4178 | info[n].start = nchars; | ||
| 4179 | if (! minus_flag) | 4178 | if (! minus_flag) |
| 4180 | { | 4179 | { |
| 4181 | memset (p, ' ', padding); | 4180 | memset (p, ' ', padding); |
| 4182 | p += padding; | 4181 | p += padding; |
| 4183 | nchars += padding; | 4182 | nchars += padding; |
| 4184 | } | 4183 | } |
| 4184 | info[n].start = nchars; | ||
| 4185 | 4185 | ||
| 4186 | if (p > buf | 4186 | if (p > buf |
| 4187 | && multibyte | 4187 | && multibyte |
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index 62d7bc4f5be..507ceef2f7d 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el | |||
| @@ -54,7 +54,7 @@ | |||
| 54 | ;; Bug #23859 | 54 | ;; Bug #23859 |
| 55 | (should (ert-equal-including-properties | 55 | (should (ert-equal-including-properties |
| 56 | (format "%4s" (propertize "hi" 'face 'bold)) | 56 | (format "%4s" (propertize "hi" 'face 'bold)) |
| 57 | #(" hi" 0 4 (face bold)))) | 57 | #(" hi" 2 4 (face bold)))) |
| 58 | 58 | ||
| 59 | ;; Bug #23897 | 59 | ;; Bug #23897 |
| 60 | (should (ert-equal-including-properties | 60 | (should (ert-equal-including-properties |
| @@ -64,4 +64,28 @@ | |||
| 64 | (format "%s" (concat (propertize "01" 'face 'bold) | 64 | (format "%s" (concat (propertize "01" 'face 'bold) |
| 65 | (propertize "23" 'face 'underline) | 65 | (propertize "23" 'face 'underline) |
| 66 | "45")) | 66 | "45")) |
| 67 | #("012345" 0 2 (face bold) 2 4 (face underline))))) | 67 | #("012345" 0 2 (face bold) 2 4 (face underline)))) |
| 68 | ;; The last property range is extended to include padding on the | ||
| 69 | ;; right, but the first range is not extended to the left to include | ||
| 70 | ;; padding on the left! | ||
| 71 | (should (ert-equal-including-properties | ||
| 72 | (format "%12s" (concat (propertize "01234" 'face 'bold) "56789")) | ||
| 73 | #(" 0123456789" 2 7 (face bold)))) | ||
| 74 | (should (ert-equal-including-properties | ||
| 75 | (format "%-12s" (concat (propertize "01234" 'face 'bold) "56789")) | ||
| 76 | #("0123456789 " 0 5 (face bold)))) | ||
| 77 | (should (ert-equal-including-properties | ||
| 78 | (format "%10s" (concat (propertize "01" 'face 'bold) | ||
| 79 | (propertize "23" 'face 'underline) | ||
| 80 | "45")) | ||
| 81 | #(" 012345" 4 6 (face bold) 6 8 (face underline)))) | ||
| 82 | (should (ert-equal-including-properties | ||
| 83 | (format "%-10s" (concat (propertize "01" 'face 'bold) | ||
| 84 | (propertize "23" 'face 'underline) | ||
| 85 | "45")) | ||
| 86 | #("012345 " 0 2 (face bold) 2 4 (face underline)))) | ||
| 87 | (should (ert-equal-including-properties | ||
| 88 | (format "%-10s" (concat (propertize "01" 'face 'bold) | ||
| 89 | (propertize "23" 'face 'underline) | ||
| 90 | (propertize "45" 'face 'italic))) | ||
| 91 | #("012345 " 0 2 (face bold) 2 4 (face underline) 4 10 (face italic))))) | ||