diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2025-03-28 00:49:33 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2025-03-29 17:49:49 -0400 |
commit | 6bcf41c311b220e84f4eb423700f36ac1ddfffa7 (patch) | |
tree | 02691864aa0b9137f1f9af569bf70bcf1ac98515 | |
parent | 1d07a6d7e34677be1653b1d4d464ff00cabfa102 (diff) | |
download | emacs-6bcf41c311b220e84f4eb423700f36ac1ddfffa7.tar.gz emacs-6bcf41c311b220e84f4eb423700f36ac1ddfffa7.tar.bz2 emacs-6bcf41c311b220e84f4eb423700f36ac1ddfffa7.zip |
Org: Use new `replace-region-contents`
* lisp/org/org-compat.el (org-replace-buffer-contents): Delete function.
(org-replace-region-contents): New function.
* lisp/org/org-src.el (org-edit-src-save, org-edit-src-exit): Use it.
-rw-r--r-- | lisp/org/org-compat.el | 18 | ||||
-rw-r--r-- | lisp/org/org-src.el | 21 |
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 |