Mine's with a region. (defun comment-and-duplicate-region (start end) (interactive "r") (let ((s (buffer-substring start end))) (comment-region start end) (beginning-of-line) (save-excursion (insert s)))) On Sun, Jan 17, 2010 at 6:37 AM, Dirk-Jan C. Binnema wrote: > Hi, > > >>>>> "alin" == alin s 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:djcb@djcbsoftware.nl w: > www.djcbsoftware.nl > pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C > > >