[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 47374d4416: duplicate-line: fix optional argument and add test (b
From: |
Mattias Engdegård |
Subject: |
master 47374d4416: duplicate-line: fix optional argument and add test (bug#46621) |
Date: |
Wed, 22 Jun 2022 10:11:52 -0400 (EDT) |
branch: master
commit 47374d44167ce7a20d78c3c544434f389e0d726e
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
duplicate-line: fix optional argument and add test (bug#46621)
The test assumes that the current semantics are intended and desired,
which may or may not be true, but it's better than not having any at
all.
* lisp/misc.el (duplicate-line): Don't crash if called with no argument.
* test/lisp/misc-tests.el (misc--duplicate-line): New test.
---
lisp/misc.el | 2 ++
test/lisp/misc-tests.el | 16 ++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/lisp/misc.el b/lisp/misc.el
index 3fb30e5372..8a01b51c6d 100644
--- a/lisp/misc.el
+++ b/lisp/misc.el
@@ -69,6 +69,8 @@ Also see the `duplicate-line' command."
Interactively, N is the prefix numeric argument, and defaults to 1.
Also see the `copy-from-above-command' command."
(interactive "p")
+ (unless n
+ (setq n 1))
(let ((line (buffer-substring (line-beginning-position)
(line-end-position))))
(save-excursion
(forward-line 1)
diff --git a/test/lisp/misc-tests.el b/test/lisp/misc-tests.el
index 236223ef49..a56feaa049 100644
--- a/test/lisp/misc-tests.el
+++ b/test/lisp/misc-tests.el
@@ -80,5 +80,21 @@
(backward-to-word 3)
(should (equal (point) 1))))
+(ert-deftest misc--duplicate-line ()
+ ;; Duplicate a line (twice).
+ (with-temp-buffer
+ (insert "abc\ndefg\nh\n")
+ (goto-char 7)
+ (duplicate-line 2)
+ (should (equal (buffer-string) "abc\ndefg\ndefg\ndefg\nh\n"))
+ (should (equal (point) 7)))
+ ;; Duplicate a non-terminated line.
+ (with-temp-buffer
+ (insert "abc")
+ (goto-char 2)
+ (duplicate-line)
+ (should (equal (buffer-string) "abc\nabc\n"))
+ (should (equal (point) 2))))
+
(provide 'misc-tests)
;;; misc-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 47374d4416: duplicate-line: fix optional argument and add test (bug#46621),
Mattias Engdegård <=