diff options
| author | Philipp Stephani | 2017-05-07 21:01:53 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2017-06-17 15:40:58 +0200 |
| commit | d682f0daa3c0bfdd5ee8ce0e9226353d505e85a9 (patch) | |
| tree | ef0a6de2163d2f3c3c9bcb5012875e0018ef496f /test/src | |
| parent | 46279c1ea117bab75bdeccfd04703033c9e7d26d (diff) | |
| download | emacs-d682f0daa3c0bfdd5ee8ce0e9226353d505e85a9.tar.gz emacs-d682f0daa3c0bfdd5ee8ce0e9226353d505e85a9.zip | |
Add command to replace buffer contents
Add a new command 'replace-buffer-contents' that uses the Myers diff
algorithm to non-destructively replace the accessible portion of the
current buffer. The Myers algorithm is implemented in Gnulib.
* src/editfns.c (Freplace_buffer_contents): New command.
(set_bit, bit_is_set, buffer_chars_equal): New helper functions.
(syms_of_editfns): Define new command.
* test/src/editfns-tests.el (replace-buffer-contents-1)
(replace-buffer-contents-2): New unit tests.
* src/buffer.h (BUF_FETCH_CHAR_AS_MULTIBYTE): New helper macro.
* admin/merge-gnulib (GNULIB_MODULES): Add diffseq.h and minmax.h.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/editfns-tests.el | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index 3073e371933..a3ea8ab60b5 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el | |||
| @@ -208,4 +208,35 @@ | |||
| 208 | '(error "Invalid format operation %$"))) | 208 | '(error "Invalid format operation %$"))) |
| 209 | (should (equal (format "%1$c %1$s" ?±) "± 177"))) | 209 | (should (equal (format "%1$c %1$s" ?±) "± 177"))) |
| 210 | 210 | ||
| 211 | (ert-deftest replace-buffer-contents-1 () | ||
| 212 | (with-temp-buffer | ||
| 213 | (insert #("source" 2 4 (prop 7))) | ||
| 214 | (let ((source (current-buffer))) | ||
| 215 | (with-temp-buffer | ||
| 216 | (insert "before dest after") | ||
| 217 | (let ((marker (set-marker (make-marker) 14))) | ||
| 218 | (save-restriction | ||
| 219 | (narrow-to-region 8 12) | ||
| 220 | (replace-buffer-contents source)) | ||
| 221 | (should (equal (marker-buffer marker) (current-buffer))) | ||
| 222 | (should (equal (marker-position marker) 16))) | ||
| 223 | (should (equal-including-properties | ||
| 224 | (buffer-string) | ||
| 225 | #("before source after" 9 11 (prop 7)))) | ||
| 226 | (should (equal (point) 9)))) | ||
| 227 | (should (equal-including-properties | ||
| 228 | (buffer-string) | ||
| 229 | #("source" 2 4 (prop 7)))))) | ||
| 230 | |||
| 231 | (ert-deftest replace-buffer-contents-2 () | ||
| 232 | (with-temp-buffer | ||
| 233 | (insert "foo bar baz qux") | ||
| 234 | (let ((source (current-buffer))) | ||
| 235 | (with-temp-buffer | ||
| 236 | (insert "foo BAR baz qux") | ||
| 237 | (replace-buffer-contents source) | ||
| 238 | (should (equal-including-properties | ||
| 239 | (buffer-string) | ||
| 240 | "foo bar baz qux")))))) | ||
| 241 | |||
| 211 | ;;; editfns-tests.el ends here | 242 | ;;; editfns-tests.el ends here |