* lisp/minibuffer.el (completion--replace):
* lisp/emacs-lisp/cl-lib.el (cl--set-buffer-substring):
* lisp/subr.el (replace-string-in-region):
Use `replace-region-contents` instead of insert+delete.
* lisp/help-fns.el (help-fns--signature):
Use `replace-region-contents` instead of `cl--set-buffer-substring`.
* lisp/language/japan-util.el (japanese-replace-region):
Rewrite using `replace-region-contents` and mark obsolete.
(japanese-katakana-region, japanese-hankaku-region):
Use `replace-region-contents` instead.
* lisp/progmodes/flymake-proc.el (flymake-proc--replace-region):
Rewrite using `replace-region-contents` and mark obsolete.
(flymake-proc--check-patch-master-file-buffer):
Use `replace-region-contents` instead.
(cherry picked from commit
1d07a6d7e34677be1653b1d4d464ff00cabfa102)
`(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)))
`(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")
(save-excursion
(forward-char -1)
(<= (current-column) (- fill-column 12)))
- (cl--set-buffer-substring (- beg 3) beg " ")))))
+ (replace-region-contents (- beg 3) beg " " 0)))))
high-doc)))))
(defun help-fns--parent-mode (function)
(defun japanese-replace-region (from to string)
"Replace the region specified by FROM and TO to STRING."
- (goto-char from)
- (insert string)
- (delete-char (- to from)))
+ (declare (obsolete replace-region-contents "31.1"))
+ (goto-char to)
+ (replace-region-contents from to string 0))
;;;###autoload
(defun japanese-katakana-region (from to &optional hankaku)
(get-char-code-property kana 'kana-composition)))
slot) ;; next
(if (and composition (setq slot (assq (following-char) composition)))
- (japanese-replace-region (match-beginning 0) (1+ (point))
- (cdr slot))
+ (progn
+ (goto-char (1+ (point)))
+ (replace-region-contents (match-beginning 0) (point)
+ (cdr slot) 0))
(let ((kata (get-char-code-property
kana (if hankaku 'jisx0201 'katakana))))
(if kata
- (japanese-replace-region (match-beginning 0) (point)
- kata)))))))))
+ (replace-region-contents (match-beginning 0) (point)
+ kata 0)))))))))
;;;###autoload
(composition (get-char-code-property kata 'kana-composition))
slot) ;; next
(if (and composition (setq slot (assq (following-char) composition)))
- (japanese-replace-region (match-beginning 0) (1+ (point))
- (get-char-code-property
- (cdr slot) 'hiragana))
+ (progn
+ (goto-char (1+ (point)))
+ (replace-region-contents (match-beginning 0) (point)
+ (get-char-code-property
+ (cdr slot) 'hiragana)
+ 0))
(let ((hira (get-char-code-property kata 'hiragana)))
(if hira
- (japanese-replace-region (match-beginning 0) (point)
- hira)))))))))
+ (replace-region-contents (match-beginning 0) (point)
+ hira 0)))))))))
;;;###autoload
(defun japanese-hankaku-region (from to &optional ascii-only)
(get-char-code-property zenkaku 'jisx0201))
(get-char-code-property zenkaku 'ascii))))
(if hankaku
- (japanese-replace-region (match-beginning 0) (match-end 0)
- hankaku)))))))
+ (replace-region-contents (match-beginning 0) (match-end 0)
+ hankaku 0)))))))
;;;###autoload
(defun japanese-zenkaku-region (from to &optional katakana-only)
(composition (get-char-code-property hankaku 'kana-composition))
slot) ;; next
(if (and composition (setq slot (assq (following-char) composition)))
- (japanese-replace-region (match-beginning 0) (1+ (point))
- (cdr slot))
+ (progn
+ (goto-char (1+ (point)))
+ (replace-region-contents (match-beginning 0) (point)
+ (cdr slot) 0))
(let ((zenkaku (japanese-zenkaku hankaku)))
(if zenkaku
- (japanese-replace-region (match-beginning 0) (match-end 0)
- zenkaku)))))))))
+ (replace-region-contents (match-beginning 0) (match-end 0)
+ zenkaku 0)))))))))
;;;###autoload
(defun read-hiragana-string (prompt &optional initial-input)
(remove-text-properties 0 (length newtext)
'(face nil display nil completion--unquoted nil)
newtext)
- ;; Maybe this should be in subr.el.
- ;; You'd think this is trivial to do, but details matter if you want
- ;; to keep markers "at the right place" and be robust in the face of
- ;; after-change-functions that may themselves modify the buffer.
- (let ((prefix-len 0))
- ;; Don't touch markers in the shared prefix (if any).
- (while (and (< prefix-len (length newtext))
- (< (+ beg prefix-len) end)
- (eq (char-after (+ beg prefix-len))
- (aref newtext prefix-len)))
- (setq prefix-len (1+ prefix-len)))
- (unless (zerop prefix-len)
- (setq beg (+ beg prefix-len))
- (setq newtext (substring newtext prefix-len))))
- (let ((suffix-len 0))
- ;; Don't touch markers in the shared suffix (if any).
- (while (and (< suffix-len (length newtext))
- (< beg (- end suffix-len))
- (eq (char-before (- end suffix-len))
- (aref newtext (- (length newtext) suffix-len 1))))
- (setq suffix-len (1+ suffix-len)))
- (unless (zerop suffix-len)
- (setq end (- end suffix-len))
- (setq newtext (substring newtext 0 (- suffix-len))))
- (goto-char beg)
- (let ((length (- end beg))) ;Read `end' before we insert the text.
- (insert-and-inherit newtext)
- (delete-region (point) (+ (point) length)))
- (forward-char suffix-len)))
+ (replace-region-contents beg end newtext 0.1 nil 'inherit)
+ (goto-char (+ beg (length newtext))))
(defvar completion-in-region-mode nil
"This variable is obsolete and no longer used.")
\(passing the same four arguments that it received) to do the work,
and returns whatever it does. The return value should be nil
if there was no valid completion, else t."
- (cl-assert (<= start (point)) (<= (point) end))
+ (cl-assert (<= start (point) end) t)
(funcall completion-in-region-function start end collection predicate))
(defcustom read-file-name-completion-ignore-case
(let ((matches 0)
(case-fold-search nil))
(while (search-forward string nil t)
- (delete-region (match-beginning 0) (match-end 0))
- (insert replacement)
+ (replace-region-contents (match-beginning 0) (match-end 0)
+ replacement 0)
(setq matches (1+ matches)))
(and (not (zerop matches))
matches)))))