GNU bug report logs -
#64185
proposal for new function: copy-line
Previous Next
Full log
View this message in rfc822 format
Just a couple of thoughts:
Zachary Kanfer <zkanfer <at> 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)))
This bug report was last modified 1 year and 286 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.