aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias EngdegÄrd2023-06-27 17:00:11 +0200
committerMattias EngdegÄrd2023-06-27 17:05:54 +0200
commitcf4ccc58284de50959ea66b1cd2655ab2fa4d15b (patch)
tree65d6adea4b8aa13347ba7d6579b8fe7d8d3292ad
parenteca7394bdf2f57632238b2cf66c996b43cca2aef (diff)
downloademacs-cf4ccc58284de50959ea66b1cd2655ab2fa4d15b.tar.gz
emacs-cf4ccc58284de50959ea66b1cd2655ab2fa4d15b.zip
Speed up duplicate-line by a factor of 2
* lisp/misc.el (duplicate-line): Add the newline to the string to be inserted instead of inserting it separately. This makes duplicate-line as fast as duplicate-dwim with a contiguous region. Both could easily be made faster yet by making the code more complex.
-rw-r--r--lisp/misc.el6
1 files changed, 4 insertions, 2 deletions
diff --git a/lisp/misc.el b/lisp/misc.el
index 81769696f95..de82b97fa6f 100644
--- a/lisp/misc.el
+++ b/lisp/misc.el
@@ -71,13 +71,15 @@ Also see the `copy-from-above-command' command."
71 (interactive "p") 71 (interactive "p")
72 (unless n 72 (unless n
73 (setq n 1)) 73 (setq n 1))
74 (let ((line (buffer-substring (line-beginning-position) (line-end-position)))) 74 (let ((line (concat (buffer-substring (line-beginning-position)
75 (line-end-position))
76 "\n")))
75 (save-excursion 77 (save-excursion
76 (forward-line 1) 78 (forward-line 1)
77 (unless (bolp) 79 (unless (bolp)
78 (insert "\n")) 80 (insert "\n"))
79 (dotimes (_ n) 81 (dotimes (_ n)
80 (insert line "\n"))))) 82 (insert line)))))
81 83
82(declare-function rectangle--duplicate-right "rect" (n)) 84(declare-function rectangle--duplicate-right "rect" (n))
83 85