(defun my/duplicate-line (arg)
"Duplicate current line, leaving point in lower line. With ARG duplicates the line that many lines."
(interactive "*p")
- (kill-ring-save (line-beginning-position 1)
- (line-beginning-position 2))
- (forward-line)
- (dotimes (ignored arg)
- (yank))
- (forward-line (- arg))
- (back-to-indentation))
+ (let* ((start (line-beginning-position 1))
+ (end (line-beginning-position 2))
+ (at-eof (= end (line-end-position) (point-max))))
+ (kill-ring-save start end)
+ (when at-eof
+ (kill-append "\n" t))
+ (save-excursion
+ (forward-line)
+ (dotimes (ignored arg)
+ (yank)))
+ (forward-line)
+ (back-to-indentation)))
(defun my/open-line-above (arg)
"Open a new line above point with indentation. With ARG insert that many lines."