<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: A Simple Emacs Shortcut &#8211; Duplicate Line</title>
	<atom:link href="http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/feed/" rel="self" type="application/rss+xml" />
	<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/</link>
	<description>Leveraging Perl and Emacs</description>
	<lastBuildDate>Tue, 07 May 2013 11:25:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Marius Andersen</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/#comment-7561</link>
		<dc:creator><![CDATA[Marius Andersen]]></dc:creator>
		<pubDate>Wed, 20 May 2009 19:39:57 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=204#comment-7561</guid>
		<description><![CDATA[You may modify the default copy and cut commands so that they act on the current line when no text is selected. That&#039;s how SlickEdit and TextMate do it. To implement it in Emacs, see http://www.emacswiki.org/emacs/SlickCopy]]></description>
		<content:encoded><![CDATA[<p>You may modify the default copy and cut commands so that they act on the current line when no text is selected. That&#8217;s how SlickEdit and TextMate do it. To implement it in Emacs, see <a href="http://www.emacswiki.org/emacs/SlickCopy" rel="nofollow">http://www.emacswiki.org/emacs/SlickCopy</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/#comment-7326</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Sat, 07 Mar 2009 15:33:06 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=204#comment-7326</guid>
		<description><![CDATA[Hi Chris,

I don&#039;t think the intention of your code is similar to mine.  Mine is simply to provide a shortcut to duplicate the current line.  As far as I can see, yours doesn&#039;t do that.]]></description>
		<content:encoded><![CDATA[<p>Hi Chris,</p>
<p>I don&#8217;t think the intention of your code is similar to mine.  Mine is simply to provide a shortcut to duplicate the current line.  As far as I can see, yours doesn&#8217;t do that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/#comment-7323</link>
		<dc:creator><![CDATA[Chris]]></dc:creator>
		<pubDate>Sat, 07 Mar 2009 01:05:58 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=204#comment-7323</guid>
		<description><![CDATA[I&#039;ve used the code below for many years to do something similar.  You kill whatever text you want to copy and call cbb-copy-kill-ring-regexp which prompts you for a regexp.
Then, you do cbb-yank-with-regexp, which yanks the copied text and prompts for replacement text. 

;;;; copy-regexp.el
;;;; emacs lisp for kill/yank with regexp

(defvar cbb-copy-regexp-text nil
  &quot;Holds the text which will be used in the next yank-regexp operation&quot;)

(defvar cbb-copy-regexp-regexp nil
  &quot;Holds the regexp which will be used in the next yank-regexp operation&quot;)

(defun cbb-copy-kill-ring-regexp ()
  &quot;Copy the kill-ring-yank-pointer and prompt for source regexp&quot;
  (interactive &quot;&quot;)
  (setq cbb-copy-regexp-text (car kill-ring-yank-pointer))
  (setq cbb-copy-regexp-regexp (read-string &quot;Replace regexp: &quot;)))

(defun cbb-yank-with-regexp ()
  &quot;Yank cbb-copy-regexp-text at point and prompt for a replacement string&quot;
  (interactive &quot;&quot;)
  (push-mark (point))
  (let ((opoint (point)))
	(insert cbb-copy-regexp-text)
	(let ((repl (read-string
				 (concat &quot;Replace regexp &quot; cbb-copy-regexp-regexp &quot; with: &quot;))))
	  (save-excursion
		(exchange-point-and-mark)
		(while (re-search-forward cbb-copy-regexp-regexp (mark))
		  (replace-match repl))))))]]></description>
		<content:encoded><![CDATA[<p>I&#8217;ve used the code below for many years to do something similar.  You kill whatever text you want to copy and call cbb-copy-kill-ring-regexp which prompts you for a regexp.<br />
Then, you do cbb-yank-with-regexp, which yanks the copied text and prompts for replacement text. </p>
<p>;;;; copy-regexp.el<br />
;;;; emacs lisp for kill/yank with regexp</p>
<p>(defvar cbb-copy-regexp-text nil<br />
  &#8220;Holds the text which will be used in the next yank-regexp operation&#8221;)</p>
<p>(defvar cbb-copy-regexp-regexp nil<br />
  &#8220;Holds the regexp which will be used in the next yank-regexp operation&#8221;)</p>
<p>(defun cbb-copy-kill-ring-regexp ()<br />
  &#8220;Copy the kill-ring-yank-pointer and prompt for source regexp&#8221;<br />
  (interactive &#8220;&#8221;)<br />
  (setq cbb-copy-regexp-text (car kill-ring-yank-pointer))<br />
  (setq cbb-copy-regexp-regexp (read-string &#8220;Replace regexp: &#8220;)))</p>
<p>(defun cbb-yank-with-regexp ()<br />
  &#8220;Yank cbb-copy-regexp-text at point and prompt for a replacement string&#8221;<br />
  (interactive &#8220;&#8221;)<br />
  (push-mark (point))<br />
  (let ((opoint (point)))<br />
	(insert cbb-copy-regexp-text)<br />
	(let ((repl (read-string<br />
				 (concat &#8220;Replace regexp &#8221; cbb-copy-regexp-regexp &#8221; with: &#8220;))))<br />
	  (save-excursion<br />
		(exchange-point-and-mark)<br />
		(while (re-search-forward cbb-copy-regexp-regexp (mark))<br />
		  (replace-match repl))))))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/#comment-7245</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Thu, 12 Feb 2009 22:05:02 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=204#comment-7245</guid>
		<description><![CDATA[Hi Eric,

Nice function, and good idea to include the increment - I like it.  The less I need to do manually the better of course :)]]></description>
		<content:encoded><![CDATA[<p>Hi Eric,</p>
<p>Nice function, and good idea to include the increment &#8211; I like it.  The less I need to do manually the better of course <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/#comment-7243</link>
		<dc:creator><![CDATA[Eric]]></dc:creator>
		<pubDate>Thu, 12 Feb 2009 03:48:24 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=204#comment-7243</guid>
		<description><![CDATA[I have a similar command I bound to M-o which I use a lot.  It is special because it also increments numbers, which is perfect for your example.  When there are no numbers, it acts like other copy lines.  It&#039;s pretty old, so there is probably a better way to do it.  It is:

;;; Original author: ttn at netcom dot com, 28-Jan-1996
;;; Modified for multiple lines: Eric
(defun another-line (num-lines)
  &quot;Copies line, preserving cursor column, and increments any numbers found.
This should probably be generalized in the future.
Argument NUM-LINES is the number of lines to modify.&quot;
  (interactive &quot;p&quot;)
  (if (not num-lines) (setq num-lines 0) (setq num-lines (1- num-lines)))
  (let* ((col (current-column))
         (bol (save-excursion (forward-line (- num-lines)) (beginning-of-line) (point)))
         (eol (progn (end-of-line) (point)))
         (line (buffer-substring bol eol)))
    (goto-char bol)
    (while (re-search-forward &quot;[0-9]+&quot; eol 1)
      (let ((num (string-to-int (buffer-substring
                                  (match-beginning 0) (match-end 0)))))
        (replace-match (int-to-string (1+ num))))
      (setq eol (save-excursion (goto-char eol) (end-of-line) (point))))
    (goto-char bol)
    (insert line &quot;\n&quot;)
    (move-to-column col)))]]></description>
		<content:encoded><![CDATA[<p>I have a similar command I bound to M-o which I use a lot.  It is special because it also increments numbers, which is perfect for your example.  When there are no numbers, it acts like other copy lines.  It&#8217;s pretty old, so there is probably a better way to do it.  It is:</p>
<p>;;; Original author: ttn at netcom dot com, 28-Jan-1996<br />
;;; Modified for multiple lines: Eric<br />
(defun another-line (num-lines)<br />
  &#8220;Copies line, preserving cursor column, and increments any numbers found.<br />
This should probably be generalized in the future.<br />
Argument NUM-LINES is the number of lines to modify.&#8221;<br />
  (interactive &#8220;p&#8221;)<br />
  (if (not num-lines) (setq num-lines 0) (setq num-lines (1- num-lines)))<br />
  (let* ((col (current-column))<br />
         (bol (save-excursion (forward-line (- num-lines)) (beginning-of-line) (point)))<br />
         (eol (progn (end-of-line) (point)))<br />
         (line (buffer-substring bol eol)))<br />
    (goto-char bol)<br />
    (while (re-search-forward &#8220;[0-9]+&#8221; eol 1)<br />
      (let ((num (string-to-int (buffer-substring<br />
                                  (match-beginning 0) (match-end 0)))))<br />
        (replace-match (int-to-string (1+ num))))<br />
      (setq eol (save-excursion (goto-char eol) (end-of-line) (point))))<br />
    (goto-char bol)<br />
    (insert line &#8220;\n&#8221;)<br />
    (move-to-column col)))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/#comment-7242</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Wed, 11 Feb 2009 23:49:17 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=204#comment-7242</guid>
		<description><![CDATA[Hi folks, thanks for the responses.

@maziran - I know about keyboard macros and use them quite extensively if you&#039;re talking about the ones using C-x ( ... C-x ).  I think this solves a different problem though: making multiple similar edits within one session rather than a few similar edits across multiple different sessions.  That is unless there is a way to store keyboard macros between invocations of emacs.  Even then, I don&#039;t see the benefit over a short interactive defun such as I described in the post.

@thomas11 &amp; Dan Lewis - I don&#039;t like setting kill-whole-line, but that is a neat trick with yanking twice, thanks.  However, I think I still like having the shortcut as C-c d as it is even quicker and I use this so frequently the 0.2s saving adds up.  I&#039;ve also added back-to-indentation to duplicate-current-line which ties in well with my normal usage.

@Dima - thanks for the fix.  I&#039;ll have to take a look at it later to see how it works.  I had previously imagined a fix using (newline).

@Peter BARABAS - thanks for the pointer to copy-from-above-command.  It looks more robust than my version and should probably be added in place of copy-region-as-kill.  There are a lot of useful functions in the .el files that aren&#039;t loaded in at start-up so I should probably take a look at these at some point.]]></description>
		<content:encoded><![CDATA[<p>Hi folks, thanks for the responses.</p>
<p>@maziran &#8211; I know about keyboard macros and use them quite extensively if you&#8217;re talking about the ones using C-x ( &#8230; C-x ).  I think this solves a different problem though: making multiple similar edits within one session rather than a few similar edits across multiple different sessions.  That is unless there is a way to store keyboard macros between invocations of emacs.  Even then, I don&#8217;t see the benefit over a short interactive defun such as I described in the post.</p>
<p>@thomas11 &amp; Dan Lewis &#8211; I don&#8217;t like setting kill-whole-line, but that is a neat trick with yanking twice, thanks.  However, I think I still like having the shortcut as C-c d as it is even quicker and I use this so frequently the 0.2s saving adds up.  I&#8217;ve also added back-to-indentation to duplicate-current-line which ties in well with my normal usage.</p>
<p>@Dima &#8211; thanks for the fix.  I&#8217;ll have to take a look at it later to see how it works.  I had previously imagined a fix using (newline).</p>
<p>@Peter BARABAS &#8211; thanks for the pointer to copy-from-above-command.  It looks more robust than my version and should probably be added in place of copy-region-as-kill.  There are a lot of useful functions in the .el files that aren&#8217;t loaded in at start-up so I should probably take a look at these at some point.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter BARABAS</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/#comment-7239</link>
		<dc:creator><![CDATA[Peter BARABAS]]></dc:creator>
		<pubDate>Wed, 11 Feb 2009 16:14:55 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=204#comment-7239</guid>
		<description><![CDATA[Hello,

Take a look at misc.el&#039;s (part of Emacs) copy-from-above-command:

&quot;Copy characters from previous nonblank line, starting just above point.
Copy ARG characters, but not past the end of that line.
If no argument given, copy the entire rest of the line.
The characters copied are inserted in the buffer before point.&quot;]]></description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>Take a look at misc.el&#8217;s (part of Emacs) copy-from-above-command:</p>
<p>&#8220;Copy characters from previous nonblank line, starting just above point.<br />
Copy ARG characters, but not past the end of that line.<br />
If no argument given, copy the entire rest of the line.<br />
The characters copied are inserted in the buffer before point.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Lewis</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/#comment-7238</link>
		<dc:creator><![CDATA[Dan Lewis]]></dc:creator>
		<pubDate>Wed, 11 Feb 2009 16:11:33 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=204#comment-7238</guid>
		<description><![CDATA[I don&#039;t kill-whole-line but I do it like thomas11: C-a C-k C-k C-y C-y, or sometimes C-a C-k C-y C-j C-y. Save the M-w (copy) stuff for multi-line blocks.]]></description>
		<content:encoded><![CDATA[<p>I don&#8217;t kill-whole-line but I do it like thomas11: C-a C-k C-k C-y C-y, or sometimes C-a C-k C-y C-j C-y. Save the M-w (copy) stuff for multi-line blocks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dima</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/#comment-7237</link>
		<dc:creator><![CDATA[Dima]]></dc:creator>
		<pubDate>Wed, 11 Feb 2009 15:21:56 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=204#comment-7237</guid>
		<description><![CDATA[Here is my version, it works on the last line in the buffer, and even if this last line does not end with newline. It also keeps the cursor position within the line:

(defun duplicate-current-line () (interactive)
  (let ((str (concat
	      (buffer-substring (point)
				(save-excursion (end-of-line) (point)))
	      &quot;\n&quot;
	      (buffer-substring (save-excursion (beginning-of-line) (point))
				(point)))))
      (insert str)
))]]></description>
		<content:encoded><![CDATA[<p>Here is my version, it works on the last line in the buffer, and even if this last line does not end with newline. It also keeps the cursor position within the line:</p>
<p>(defun duplicate-current-line () (interactive)<br />
  (let ((str (concat<br />
	      (buffer-substring (point)<br />
				(save-excursion (end-of-line) (point)))<br />
	      &#8220;\n&#8221;<br />
	      (buffer-substring (save-excursion (beginning-of-line) (point))<br />
				(point)))))<br />
      (insert str)<br />
))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thomas11</title>
		<link>http://curiousprogrammer.wordpress.com/2009/02/11/simple-emacs-shortcut/#comment-7236</link>
		<dc:creator><![CDATA[thomas11]]></dc:creator>
		<pubDate>Wed, 11 Feb 2009 15:00:44 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=204#comment-7236</guid>
		<description><![CDATA[Doing it in a vanilla emacs is easier when setting

(setq kill-whole-line t)                ; C-k deletes the end of line

I find this setting useful in almost all circumstances. 

The keystrokes for duplicating a line are then C-a; C-k, C-y; C-y. Very quick as you can keep holding C and the last two are the same key.]]></description>
		<content:encoded><![CDATA[<p>Doing it in a vanilla emacs is easier when setting</p>
<p>(setq kill-whole-line t)                ; C-k deletes the end of line</p>
<p>I find this setting useful in almost all circumstances. </p>
<p>The keystrokes for duplicating a line are then C-a; C-k, C-y; C-y. Very quick as you can keep holding C and the last two are the same key.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
