help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: copy-line


From: Andy Stewart
Subject: Re: copy-line
Date: Sun, 01 Feb 2009 10:09:26 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Hi,

Below are my code:

------------------------------> Code start <------------------------------
(defun duplicate-line-above (&optional reverse)
  "Duplicate current line above."
  (interactive)
  (let ((origianl-column (current-column))
        line-content)
    (setq line-content (buffer-substring (line-beginning-position) 
(line-end-position)))
    (beginning-of-line)
    (and reverse (forward-line +1))
    (newline +1)
    (forward-line -1)
    (insert line-content)
    (goto-column origianl-column)))

(defun duplicate-line-below ()
  "Duplicate current line below"
  (interactive)
  (duplicate-line-above t))

(defun duplicate-line-above-comment (&optional reverse)
  "Duplicate current line above, and comment current line."
  (interactive)
  (if reverse
      (duplicate-line-below)
    (duplicate-line-above))
  (save-excursion
    (if reverse
        (forward-line -1)
      (forward-line +1))
    (comment-or-uncomment-region+)))

(defun duplicate-line-below-comment ()
  "Duplicate current line below, and comment current line."
  (interactive)
  (duplicate-line-above-comment t))
------------------------------> Code end   <------------------------------

You can find those code at 
http://www.emacswiki.org/cgi-bin/emacs/lazycat-toolkit.el

Below are my keybing for those command:

------------------------------> keybinding start <------------------------------
("C-S-o" . duplicate-line-above)
("C-S-l" . duplicate-line-below)
("C-S-s-o" . duplicate-line-above-comment)
("C-S-s-l" . duplicate-line-below-comment)
------------------------------> keybinding end   <------------------------------

Enjoy!

  -- Andy


Helmut Eller <eller.helmut@gmail.com> writes:

> Hello,
>
> is there a command (and standard key) to copy the current line?  The
> command should duplicate the text of the current line and move point to
> the copied line.  I think that vi has something like that, and
> occasionally it would be quite useful.
>
> I can write that myself but maybe Emacs has something already and I
> don't know it?  It's also a bit hard to find a free key :-)
>
> Helmut.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]