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

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

Re: copy-line


From: Joe Fineman
Subject: Re: copy-line
Date: Sat, 31 Jan 2009 20:18:14 -0500
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (windows-nt)

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

> 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 :-)

I have been using the following kluge extensively for a long time.  I
mainly use it in tables, but it is also useful for duplicating a line
that contains no tabs:

(defun ditto ()
  "In a table, duplicate the entry above."
  (interactive)
  (let ((track-eol) (goal-column (current-column)))
    (skip-chars-backward "^\t\n")
    (setq newplace (point-marker))
    (previous-line 1)
    (setq oldplace (point-marker))
    (skip-chars-forward "^\t\n")
    (setq entry (buffer-substring oldplace (point)))
    (goto-char newplace)
    (skip-chars-forward "^\t\n")
    (delete-region newplace (point))
    (set-mark (point))
    (insert entry)
    )
  )
-- 
---  Joe Fineman    joe_f@verizon.net

||:  It could have been worse -- it could have been me.  :||


reply via email to

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