diff options
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/cl-lib.el | 8 | ||||
-rw-r--r-- | lisp/emacs-lisp/gv.el | 2 | ||||
-rw-r--r-- | lisp/emacs-lisp/subr-x.el | 29 |
3 files changed, 5 insertions, 34 deletions
diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el index 4208160bd12..4645b4dffb1 100644 --- a/lisp/emacs-lisp/cl-lib.el +++ b/lisp/emacs-lisp/cl-lib.el @@ -154,12 +154,10 @@ to an element already in the list stored in PLACE. `(setq ,place (cl-adjoin ,x ,place ,@keys))) `(cl-callf2 cl-adjoin ,x ,place ,@keys))) -(defun cl--set-buffer-substring (start end val) +(defun cl--set-buffer-substring (start end val &optional inherit) "Delete region from START to END and insert VAL." - (save-excursion (delete-region start end) - (goto-char start) - (insert val) - val)) + (replace-region-contents start end val 0 nil inherit) + val) (defun cl--set-substring (str start end val) (if end (if (< end 0) (incf end (length str))) diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index b44f7dc87f3..6c949f1016b 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -684,6 +684,8 @@ REF must have been previously obtained with `gv-ref'." `(insert (prog1 ,store (erase-buffer)))) (make-obsolete-generalized-variable 'buffer-string nil "29.1") +;; FIXME: Can't use `replace-region-contents' because it's not +;; expected to be costly, so we need to pass MAX-SECS==0. (gv-define-simple-setter buffer-substring cl--set-buffer-substring) (make-obsolete-generalized-variable 'buffer-substring nil "29.1") diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 6414ecab394..eaa8119ead7 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -281,35 +281,6 @@ the string." (declare (pure t) (side-effect-free t)) (string-remove-suffix "\n" string)) -(defun replace-region-contents (beg end replace-fn - &optional max-secs max-costs) - "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' -which also describes the MAX-SECS and MAX-COSTS arguments and the -return value. - -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 max-secs max-costs) - (let ((source-buffer (current-buffer))) - (with-temp-buffer - (insert repl) - (let ((tmp-buffer (current-buffer))) - (set-buffer source-buffer) - (replace-buffer-contents tmp-buffer max-secs max-costs))))))))) - ;;;###autoload (defmacro named-let (name bindings &rest body) "Looping construct taken from Scheme. |