summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/org/org-compat.el18
-rw-r--r--lisp/org/org-src.el21
2 files changed, 20 insertions, 19 deletions
diff --git a/lisp/org/org-compat.el b/lisp/org/org-compat.el
index 59d34b661c6..297e8f06045 100644
--- a/lisp/org/org-compat.el
+++ b/lisp/org/org-compat.el
@@ -292,10 +292,20 @@ older than 27.1"
(if tree (push tree elems))
(nreverse elems))))
-(if (version< emacs-version "27.1")
- (defsubst org-replace-buffer-contents (source &optional _max-secs _max-costs)
- (replace-buffer-contents source))
- (defalias 'org-replace-buffer-contents #'replace-buffer-contents))
+(defalias 'org-replace-region-contents
+ (if (> emacs-major-version 30)
+ #'replace-region-contents
+ ;; The `replace-region-contents' in Emacs<31 does not accept a buffer
+ ;; as SOURCE argument and does not preserve the position well enough.
+ (lambda (beg end source &optional max-secs max-costs)
+ (save-restriction
+ (narrow-to-region beg end)
+ (let ((eobp (eobp)))
+ (with-no-warnings
+ (if (< emacs-major-version 27)
+ (replace-buffer-contents source)
+ (replace-buffer-contents source max-secs max-costs)))
+ (if eobp (goto-char (point-max))))))))
(unless (fboundp 'proper-list-p)
;; `proper-list-p' was added in Emacs 27.1. The function below is
diff --git a/lisp/org/org-src.el b/lisp/org/org-src.el
index 302c27ac866..d8a928b1f9f 100644
--- a/lisp/org/org-src.el
+++ b/lisp/org/org-src.el
@@ -1414,13 +1414,9 @@ EVENT is passed to `mouse-set-point'."
;; insert new contents.
(delete-overlay overlay)
(let ((expecting-bol (bolp)))
- (if (version< emacs-version "27.1")
- (progn (delete-region beg end)
- (insert (with-current-buffer write-back-buf (buffer-string))))
- (save-restriction
- (narrow-to-region beg end)
- (org-replace-buffer-contents write-back-buf 0.1 nil)
- (goto-char (point-max))))
+ (goto-char end)
+ (org-replace-region-contents beg end write-back-buf 0.1 nil)
+ (cl-assert (= (point) (+ beg (buffer-size write-back-buf))))
(when (and expecting-bol (not (bolp))) (insert "\n")))
(kill-buffer write-back-buf)
(save-buffer)
@@ -1461,14 +1457,9 @@ EVENT is passed to `mouse-set-point'."
(undo-boundary)
(goto-char beg)
(let ((expecting-bol (bolp)))
- (if (version< emacs-version "27.1")
- (progn (delete-region beg end)
- (insert (with-current-buffer write-back-buf
- (buffer-string))))
- (save-restriction
- (narrow-to-region beg end)
- (org-replace-buffer-contents write-back-buf 0.1 nil)
- (goto-char (point-max))))
+ (goto-char end)
+ (org-replace-region-contents beg end write-back-buf 0.1 nil)
+ (cl-assert (= (point) (+ beg (buffer-size write-back-buf))))
(when (and expecting-bol (not (bolp))) (insert "\n")))))
(when write-back-buf (kill-buffer write-back-buf))
;; If we are to return to source buffer, put point at an