[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#64185: proposal for new function: copy-line
From: |
Eshel Yaron |
Subject: |
bug#64185: proposal for new function: copy-line |
Date: |
Tue, 20 Jun 2023 09:15:51 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Just a couple of thoughts:
Zachary Kanfer <zkanfer@gmail.com> writes:
> This proposal is a function that copies the line point is on, duplicating it
> in the buffer.
>
> I find it useful for both text and code. It makes writing certain types of
> repetitive things a lot simpler.
>
How does this relate to the existing `duplicate-line`?
> +(defun copy-line (&optional copy-above)
> + "Copy the line point is on, placing the copy above the current line.
> +
> +With prefix argument COPY-ABOVE, put the copy below the current line."
> + (interactive "*P")
> + (let ((line (buffer-substring-no-properties (line-beginning-position)
> (line-end-position)))
> + (where-in-line (- (point) (line-beginning-position))))
> + (if copy-above
> + (progn (beginning-of-line)
> + (open-line 1))
> + (progn (end-of-line)
> + (insert "\n")))
> + (insert line)
> + (goto-char (line-beginning-position))
> + (forward-char where-in-line))
> + (set-transient-map
> + (define-keymap "c" (lambda () (interactive) (copy-line copy-above))))
> + (message "press c to copy again?"))
I think you can get the same behavior by using `duplicate-line` as follows:
(defun esy/copy-line (&optional copy-above)
(interactive "*P")
(duplicate-line)
(unless copy-above (line-move 1)))
- bug#64185: proposal for new function: copy-line, Zachary Kanfer, 2023/06/20
- bug#64185: proposal for new function: copy-line,
Eshel Yaron <=
- bug#64185: proposal for new function: copy-line, Eli Zaretskii, 2023/06/20
- bug#64185: proposal for new function: copy-line, Zachary Kanfer, 2023/06/21
- bug#64185: proposal for new function: copy-line, Eli Zaretskii, 2023/06/22
- bug#64185: proposal for new function: copy-line, Juri Linkov, 2023/06/22
- bug#64185: proposal for new function: copy-line, Eli Zaretskii, 2023/06/22
- bug#64185: proposal for new function: copy-line, Juri Linkov, 2023/06/22
- bug#64185: proposal for new function: copy-line, Eli Zaretskii, 2023/06/22
- bug#64185: proposal for new function: copy-line, Drew Adams, 2023/06/22
- bug#64185: proposal for new function: copy-line, Juri Linkov, 2023/06/22
- bug#64185: proposal for new function: copy-line, Drew Adams, 2023/06/22