unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Andy Stewart <lazycat.manatee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: copy-line
Date: Sun, 01 Feb 2009 10:09:26 +0800	[thread overview]
Message-ID: <87ocxmgb6x.fsf@debian.domain> (raw)
In-Reply-To: m2d4e32uyg.fsf@gmail.com

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.





  parent reply	other threads:[~2009-02-01  2:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-31 18:26 copy-line Helmut Eller
2009-01-31 19:52 ` copy-line Plamen Tanovski
2009-02-01  1:18 ` copy-line Joe Fineman
2009-02-01  2:06 ` copy-line Samuel Wales
2009-02-01  2:09 ` Andy Stewart [this message]
     [not found] ` <mailman.6387.1233454226.26697.help-gnu-emacs@gnu.org>
2009-02-01  8:41   ` copy-line Helmut Eller
2009-02-01 10:17     ` copy-line Peter Dyballa
2009-02-01 10:13 ` copy-line Harald Hanche-Olsen
2009-02-01 11:45   ` copy-line Helmut Eller
2009-02-01 15:40     ` copy-line Harald Hanche-Olsen
  -- strict thread matches above, loose matches on Subject: below --
2012-07-05 19:08 copy-line (& default keychord) Enda
2012-07-24 16:06 ` copy-line Enda
2012-07-24 17:44   ` copy-line Bastien
2012-07-25 18:47   ` copy-line Guido Van Hoecke
     [not found] ` <mailman.5498.1343146029.855.help-gnu-emacs@gnu.org>
2012-07-25 12:31   ` copy-line rfflrccrd
2012-07-25 13:41     ` copy-line Dan Espen
2012-07-25 15:02       ` copy-line Raffaele Ricciardi
2012-07-25 15:06         ` copy-line Raffaele Ricciardi
2012-07-25 13:50     ` copy-line Raffaele Ricciardi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ocxmgb6x.fsf@debian.domain \
    --to=lazycat.manatee@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).