From: Mattias EngdegÄrd Date: Wed, 28 Jun 2023 12:36:39 +0000 (+0200) Subject: Speed up duplicate-dwim and duplicate-line by another factor 10 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=85335157dd4a8bf6a0c92525360ec35362750c30;p=emacs.git Speed up duplicate-dwim and duplicate-line by another factor 10 * lisp/misc.el (duplicate--insert-copies): New. (duplicate-line, duplicate-dwim): Call it. --- diff --git a/lisp/misc.el b/lisp/misc.el index de82b97fa6f..ab083728a69 100644 --- a/lisp/misc.el +++ b/lisp/misc.el @@ -63,6 +63,10 @@ Also see the `duplicate-line' command." (+ n (point))))))) (insert string))) +(defun duplicate--insert-copies (n string) + "Insert N copies of STRING at point." + (insert (mapconcat #'identity (make-list n string)))) + ;;;###autoload (defun duplicate-line (&optional n) "Duplicate the current line N times. @@ -78,8 +82,7 @@ Also see the `copy-from-above-command' command." (forward-line 1) (unless (bolp) (insert "\n")) - (dotimes (_ n) - (insert line))))) + (duplicate--insert-copies n line)))) (declare-function rectangle--duplicate-right "rect" (n)) @@ -111,8 +114,7 @@ Interactively, N is the prefix numeric argument, and defaults to 1." (text (buffer-substring beg end))) (save-excursion (goto-char end) - (dotimes (_ n) - (insert text)))) + (duplicate--insert-copies n text))) (setq deactivate-mark nil)) ;; Duplicate line.