diff options
author | Tassilo Horn <tsdh@gnu.org> | 2019-02-23 21:18:36 +0100 |
---|---|---|
committer | Tassilo Horn <tsdh@gnu.org> | 2019-02-23 21:31:15 +0100 |
commit | e96923c188a2a38d09917c5b7f606187a1413a96 (patch) | |
tree | 6ad7b9a1549bf520747db72e36eb62ceb6fcc720 /lisp/subr.el | |
parent | 5f640bfdf84753322763be23ebaa8ded92dc1c5d (diff) | |
download | emacs-e96923c188a2a38d09917c5b7f606187a1413a96.tar.gz |
Improve replace-buffer-contents/replace-region-contents
* src/editfns.c (Freplace_buffer_contents): Add two optional arguments
for mitigating performance issues.
* lisp/emacs-lisp/subr-x.el (replace-region-contents): Move from
subr.el. Add the same two arguments as for replace-buffer-contents.
* lisp/json.el (json-pretty-print-max-secs): New variable holding the
default MAX-SECS value json-pretty-print passes to
replace-buffer-contents.
(json-pretty-print): Use it.
* doc/lispref/text.texi (Replacing): Add documentation for
replace-buffer-contents two new optional arguments. Document
replace-region-contents.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 26 |
1 files changed, 0 insertions, 26 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 69ae804e200..5c8b84b8e9c 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -5476,30 +5476,4 @@ returned list are in the same order as in TREE. ;; 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 |