;; for discoverability:
(defalias 'flatten-list 'flatten-tree)
+(defun replace-region-contents (beg end replace-fn)
+ "Replace the region between BEG and END using REPLACE-FN.
+REPLACE-FN runs on the current buffer narrowed to the region. It
+should return either a string or a buffer replacing the region.
+
+The replacement is performed using `replace-buffer-contents'.
+
+Note: If the replacement is a string, it'll be placed in a
+temporary buffer so that `replace-buffer-contents' can operate on
+it. Therefore, if you already have the replacement in a buffer,
+it makes no sense to convert it to a string using
+`buffer-substring' or similar."
+ (save-excursion
+ (save-restriction
+ (narrow-to-region beg end)
+ (goto-char (point-min))
+ (let ((repl (funcall replace-fn)))
+ (if (bufferp repl)
+ (replace-buffer-contents repl)
+ (let ((source-buffer (current-buffer)))
+ (with-temp-buffer
+ (insert repl)
+ (let ((tmp-buffer (current-buffer)))
+ (set-buffer source-buffer)
+ (replace-buffer-contents tmp-buffer)))))))))
+
;;; subr.el ends here
#undef ELEMENT
#undef EQUAL
+#define USE_HEURISTIC
+
+#ifdef USE_HEURISTIC
+#define DIFFSEQ_HEURISTIC
+#endif
/* Counter used to rarely_quit in replace-buffer-contents. */
static unsigned short rbc_quitcounter;
.insertions = SAFE_ALLOCA (ins_bytes),
.fdiag = buffer + size_b + 1,
.bdiag = buffer + diags + size_b + 1,
+#ifdef DIFFSEQ_HEURISTIC
+ .heuristic = true,
+#endif
/* FIXME: Find a good number for .too_expensive. */
- .too_expensive = 1000000,
+ .too_expensive = 64,
};
memclear (ctx.deletions, del_bytes);
memclear (ctx.insertions, ins_bytes);