emacs-devel
[Top][All Lists]
Advanced

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

Re: keybinding to duplicate the current line.


From: Dirk-Jan C . Binnema
Subject: Re: keybinding to duplicate the current line.
Date: Sun, 17 Jan 2010 16:37:19 +0200
User-agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/23.1 Mule/6.0 (HANACHIRUSATO)

Hi,

>>>>> "alin" == alin s <address@hidden> writes:

    alin> For me it would be very convenient to have a key-binding to duplicate 
the
    alin> current line.

    alin> In order to duplicate it I have to press

    alin> C-a C-SPACE C-e C-f M-w C-g C-y

    alin> It's too much for an usual function. C-x C-a would be good?

    
I like 'slick copy', ie., copy without needing to select:
http://emacs-fu.blogspot.com/2009/11/copying-lines-without-selecting-them.html

Then, you can duplicate lines with:

  M-w C-y

Which is very natural.  

  
    alin> More than that, if I press C-u C-x C-a, I wish to duplicate the 
current
    alin> line, and to comment the old line.

    alin> Do you consider that such a function would be useful for many of you?
    alin> Otherwise, I have to wtite it myseld in my own .emacs...

Something quick and fairly dirty:
    
(defun comment-and-dup ()
  (interactive)
  (save-excursion
    (beginning-of-line)
    (push-mark)
    (forward-line 1)
    (let ((str (buffer-substring (region-beginning) (region-end))))
      (comment-region (region-beginning) (region-end))
      (next-line)
      (insert-string str))))

Best wishes,
Dirk.

-- 
Dirk-Jan C. Binnema                  Helsinki, Finland
e:address@hidden           w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C




reply via email to

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