diff options
| -rw-r--r-- | lisp/subr.el | 26 | ||||
| -rw-r--r-- | src/editfns.c | 10 |
2 files changed, 35 insertions, 1 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 122a0d8da4c..44a1c608949 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -5476,4 +5476,30 @@ returned list are in the same order as in TREE. | |||
| 5476 | ;; for discoverability: | 5476 | ;; for discoverability: |
| 5477 | (defalias 'flatten-list 'flatten-tree) | 5477 | (defalias 'flatten-list 'flatten-tree) |
| 5478 | 5478 | ||
| 5479 | (defun replace-region-contents (beg end replace-fn) | ||
| 5480 | "Replace the region between BEG and END using REPLACE-FN. | ||
| 5481 | REPLACE-FN runs on the current buffer narrowed to the region. It | ||
| 5482 | should return either a string or a buffer replacing the region. | ||
| 5483 | |||
| 5484 | The replacement is performed using `replace-buffer-contents'. | ||
| 5485 | |||
| 5486 | Note: If the replacement is a string, it'll be placed in a | ||
| 5487 | temporary buffer so that `replace-buffer-contents' can operate on | ||
| 5488 | it. Therefore, if you already have the replacement in a buffer, | ||
| 5489 | it makes no sense to convert it to a string using | ||
| 5490 | `buffer-substring' or similar." | ||
| 5491 | (save-excursion | ||
| 5492 | (save-restriction | ||
| 5493 | (narrow-to-region beg end) | ||
| 5494 | (goto-char (point-min)) | ||
| 5495 | (let ((repl (funcall replace-fn))) | ||
| 5496 | (if (bufferp repl) | ||
| 5497 | (replace-buffer-contents repl) | ||
| 5498 | (let ((source-buffer (current-buffer))) | ||
| 5499 | (with-temp-buffer | ||
| 5500 | (insert repl) | ||
| 5501 | (let ((tmp-buffer (current-buffer))) | ||
| 5502 | (set-buffer source-buffer) | ||
| 5503 | (replace-buffer-contents tmp-buffer))))))))) | ||
| 5504 | |||
| 5479 | ;;; subr.el ends here | 5505 | ;;; subr.el ends here |
diff --git a/src/editfns.c b/src/editfns.c index a9ac263dafa..7a600bacf18 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -1910,6 +1910,11 @@ determines whether case is significant or ignored. */) | |||
| 1910 | 1910 | ||
| 1911 | #undef ELEMENT | 1911 | #undef ELEMENT |
| 1912 | #undef EQUAL | 1912 | #undef EQUAL |
| 1913 | #define USE_HEURISTIC | ||
| 1914 | |||
| 1915 | #ifdef USE_HEURISTIC | ||
| 1916 | #define DIFFSEQ_HEURISTIC | ||
| 1917 | #endif | ||
| 1913 | 1918 | ||
| 1914 | /* Counter used to rarely_quit in replace-buffer-contents. */ | 1919 | /* Counter used to rarely_quit in replace-buffer-contents. */ |
| 1915 | static unsigned short rbc_quitcounter; | 1920 | static unsigned short rbc_quitcounter; |
| @@ -2017,8 +2022,11 @@ differences between the two buffers. */) | |||
| 2017 | .insertions = SAFE_ALLOCA (ins_bytes), | 2022 | .insertions = SAFE_ALLOCA (ins_bytes), |
| 2018 | .fdiag = buffer + size_b + 1, | 2023 | .fdiag = buffer + size_b + 1, |
| 2019 | .bdiag = buffer + diags + size_b + 1, | 2024 | .bdiag = buffer + diags + size_b + 1, |
| 2025 | #ifdef DIFFSEQ_HEURISTIC | ||
| 2026 | .heuristic = true, | ||
| 2027 | #endif | ||
| 2020 | /* FIXME: Find a good number for .too_expensive. */ | 2028 | /* FIXME: Find a good number for .too_expensive. */ |
| 2021 | .too_expensive = 1000000, | 2029 | .too_expensive = 64, |
| 2022 | }; | 2030 | }; |
| 2023 | memclear (ctx.deletions, del_bytes); | 2031 | memclear (ctx.deletions, del_bytes); |
| 2024 | memclear (ctx.insertions, ins_bytes); | 2032 | memclear (ctx.insertions, ins_bytes); |