Function: org-replace-region-contents
org-replace-region-contents is a function alias and interactive for
replace-region-contents, defined in editfns.c.
Signature
(org-replace-region-contents BEG END SOURCE &optional MAX-SECS MAX-COSTS INHERIT)
Documentation
Replace the region between BEG and END with that of SOURCE.
SOURCE can be a buffer, a string, or a vector [SBUF SBEG SEND] denoting the substring SBEG..SEND of buffer SBUF.
If optional argument INHERIT is non-nil, the inserted text will inherit properties from adjoining text.
As far as possible the replacement is non-destructive, i.e. existing buffer contents, markers, point, properties, and overlays in the current buffer stay intact. Point is treated like an "insert before" marker: if point starts at END, it will always be at the end of the replacement when this function returns, whereas if point starts at BEG it will remain at BEG only if the replaced text is not empty.
Because this function can be very slow if there is a large number of differences between the two buffers, there are two optional arguments mitigating this issue.
The MAX-SECS argument, if given, defines a hard limit on the time used
for comparing the buffers. If it takes longer than MAX-SECS, the
function falls back to a plain delete-region and
insert-buffer-substring. (Note that the checks are not performed
too evenly over time, so in some cases it may run a bit longer than
allowed). In particular, passing zero as the value of MAX-SECS
disables the comparison step, so this function immediately falls
back to a plain delete/insert method.
The optional argument MAX-COSTS defines the quality of the difference computation. If the actual costs exceed this limit, heuristics are used to provide a faster but suboptimal solution. The default value is 1000000.
Note: If the replacement is a string, it'll usually be placed internally in a temporary buffer. Therefore, all else being equal, it is preferable to pass a buffer rather than a string as SOURCE argument.
This function returns t if a non-destructive replacement could be performed. Otherwise, i.e., if MAX-SECS was exceeded, it returns nil.
SOURCE can also be a function that will be called with no arguments and with current buffer narrowed to BEG..END, and should return a buffer or a string. But this is deprecated.
Key Bindings