<?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/"
		>
<channel>
	<title>Comments on: Removing blank lines in a buffer</title>
	<atom:link href="http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/</link>
	<description>a blog about mastering the world&#039;s best text editor</description>
	<lastBuildDate>Fri, 17 May 2013 21:26:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Christian Weiske</title>
		<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/#comment-19087</link>
		<dc:creator>Christian Weiske</dc:creator>
		<pubDate>Wed, 09 Jan 2013 07:38:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.masteringemacs.org/?p=379#comment-19087</guid>
		<description><![CDATA[Thanks.]]></description>
		<content:encoded><![CDATA[<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mickey</title>
		<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/#comment-1403</link>
		<dc:creator>mickey</dc:creator>
		<pubDate>Fri, 05 Aug 2011 19:23:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.masteringemacs.org/?p=379#comment-1403</guid>
		<description><![CDATA[Hi Sean,

That is correct behaviour as far as Emacs is concerned (whether it is sensible is another debate...)

Before transient-mark-mode came about Emacs would work from point &quot;onwards&quot; to the end of the buffer or the end of the mark. This effect is still present in Emacs hence its slightly annoying &quot;two-tier&quot; region system.

The solution is to either &lt;code&gt;C-x h&lt;/code&gt; first to mark the region or alter the function to work on the entire region. 

Mickey.]]></description>
		<content:encoded><![CDATA[<p>Hi Sean,</p>
<p>That is correct behaviour as far as Emacs is concerned (whether it is sensible is another debate&#8230;)</p>
<p>Before transient-mark-mode came about Emacs would work from point &#8220;onwards&#8221; to the end of the buffer or the end of the mark. This effect is still present in Emacs hence its slightly annoying &#8220;two-tier&#8221; region system.</p>
<p>The solution is to either <code>C-x h</code> first to mark the region or alter the function to work on the entire region. </p>
<p>Mickey.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/#comment-1402</link>
		<dc:creator>Sean</dc:creator>
		<pubDate>Fri, 05 Aug 2011 19:13:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.masteringemacs.org/?p=379#comment-1402</guid>
		<description><![CDATA[Actually, mickey I do not see the same behavior with your flush-blank-lines and sameer&#039;s. If I run yours without first marking a region it starts at point, not point-min.]]></description>
		<content:encoded><![CDATA[<p>Actually, mickey I do not see the same behavior with your flush-blank-lines and sameer&#8217;s. If I run yours without first marking a region it starts at point, not point-min.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: onano</title>
		<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/#comment-1228</link>
		<dc:creator>onano</dc:creator>
		<pubDate>Sun, 19 Jun 2011 21:04:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.masteringemacs.org/?p=379#comment-1228</guid>
		<description><![CDATA[&gt; Why did I search in reverse with C-M-r instead of using C-M-s?

To save a C-p.]]></description>
		<content:encoded><![CDATA[<p>&gt; Why did I search in reverse with C-M-r instead of using C-M-s?</p>
<p>To save a C-p.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mickey</title>
		<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/#comment-1128</link>
		<dc:creator>mickey</dc:creator>
		<pubDate>Fri, 03 Jun 2011 17:41:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.masteringemacs.org/?p=379#comment-1128</guid>
		<description><![CDATA[Hi ozan,

That is not quite the same as C-x C-o will only work on the area around point; and if there happens to only be one empty line then that line is removed, which is not what we want.]]></description>
		<content:encoded><![CDATA[<p>Hi ozan,</p>
<p>That is not quite the same as C-x C-o will only work on the area around point; and if there happens to only be one empty line then that line is removed, which is not what we want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ozan</title>
		<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/#comment-1094</link>
		<dc:creator>ozan</dc:creator>
		<pubDate>Wed, 01 Jun 2011 14:47:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.masteringemacs.org/?p=379#comment-1094</guid>
		<description><![CDATA[You can also do it by C-x C-o]]></description>
		<content:encoded><![CDATA[<p>You can also do it by C-x C-o</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mickey</title>
		<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/#comment-780</link>
		<dc:creator>mickey</dc:creator>
		<pubDate>Sun, 03 Apr 2011 12:26:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.masteringemacs.org/?p=379#comment-780</guid>
		<description><![CDATA[Sameer,

Not bad for a first attempt! I think the first one can be simplified to this:

&lt;pre lang=&quot;lisp&quot;&gt;
(defun flush-blank-lines (start end)
  (interactive &quot;r&quot;)
  (flush-lines &quot;^\\s-*$&quot; start end nil))
&lt;/pre&gt;

This way we use Emacs&#039;s built-in support for working with regions by using the interactive &quot;r&quot; code letter which will pass in the start/end of point and mark automatically -- this is important for people who don&#039;t use transient-mark-mode. This approach also lets use pass in explicit ranges from lisp.

The second function works in much the same way as the first, although I have opted to use the interactionversion instead of the &quot;proper&quot; elisp regexp function:

&lt;pre lang=&quot;lisp&quot;&gt;
(defun collapse-blank-lines (start end)
  (interactive &quot;r&quot;)
  (replace-regexp &quot;^\n\\{2,\\}&quot; &quot;\n&quot; nil start end))
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Sameer,</p>
<p>Not bad for a first attempt! I think the first one can be simplified to this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> flush-blank-lines <span style="color: #66cc66;">&#40;</span>start end<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>interactive <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>flush-lines <span style="color: #ff0000;">&quot;^<span style="color: #000099; font-weight: bold;">\\</span>s-*$&quot;</span> start end <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>This way we use Emacs&#8217;s built-in support for working with regions by using the interactive &#8220;r&#8221; code letter which will pass in the start/end of point and mark automatically &#8212; this is important for people who don&#8217;t use transient-mark-mode. This approach also lets use pass in explicit ranges from lisp.</p>
<p>The second function works in much the same way as the first, although I have opted to use the interactionversion instead of the &#8220;proper&#8221; elisp regexp function:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> collapse-blank-lines <span style="color: #66cc66;">&#40;</span>start end<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>interactive <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>replace-regexp <span style="color: #ff0000;">&quot;^<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\\</span>{2,<span style="color: #000099; font-weight: bold;">\\</span>}&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">nil</span> start end<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: Sameer Morar</title>
		<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/#comment-766</link>
		<dc:creator>Sameer Morar</dc:creator>
		<pubDate>Sat, 02 Apr 2011 02:40:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.masteringemacs.org/?p=379#comment-766</guid>
		<description><![CDATA[Herewith two functions to do what you&#039;ve described in this article:

(defun flush-blank-lines ()
  &quot;Removes all blank lines from buffer or region&quot;
  (interactive)
  (save-excursion
    (let (min max)
      (if (equal (region-active-p) nil)
	    (mark-whole-buffer))
	(setq min (region-beginning) max (region-end))
	(flush-lines &quot;^ *$&quot; min max t)
      )
    )
  )

(defun collapse-blank-lines ()
  &quot;Collapse multiple blank lines from buffer or region into a single blank line&quot;
  (interactive)
  (save-excursion
    (let (min max)
      (if (equal (region-active-p) nil)
	  (mark-whole-buffer))
      (setq min (region-beginning) max (region-end))
      (query-replace-regexp &quot;^
\\{2,\\}&quot; &quot;
&quot; nil min max)
      )
    )
  )

Any suggestions on improving these?]]></description>
		<content:encoded><![CDATA[<p>Herewith two functions to do what you&#8217;ve described in this article:</p>
<p>(defun flush-blank-lines ()<br />
  &#8220;Removes all blank lines from buffer or region&#8221;<br />
  (interactive)<br />
  (save-excursion<br />
    (let (min max)<br />
      (if (equal (region-active-p) nil)<br />
	    (mark-whole-buffer))<br />
	(setq min (region-beginning) max (region-end))<br />
	(flush-lines &#8220;^ *$&#8221; min max t)<br />
      )<br />
    )<br />
  )</p>
<p>(defun collapse-blank-lines ()<br />
  &#8220;Collapse multiple blank lines from buffer or region into a single blank line&#8221;<br />
  (interactive)<br />
  (save-excursion<br />
    (let (min max)<br />
      (if (equal (region-active-p) nil)<br />
	  (mark-whole-buffer))<br />
      (setq min (region-beginning) max (region-end))<br />
      (query-replace-regexp &#8220;^<br />
\\{2,\\}&#8221; &#8221;<br />
&#8221; nil min max)<br />
      )<br />
    )<br />
  )</p>
<p>Any suggestions on improving these?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mickey</title>
		<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/#comment-710</link>
		<dc:creator>mickey</dc:creator>
		<pubDate>Sun, 20 Mar 2011 09:29:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.masteringemacs.org/?p=379#comment-710</guid>
		<description><![CDATA[It is indeed, piyo, and it is very useful when you&#039;re editing text but not so good if you want to remove all the blank lines in a buffer as it only acts on lines around point. My example in the article where I used a macro I did use delete-blank-lines.]]></description>
		<content:encoded><![CDATA[<p>It is indeed, piyo, and it is very useful when you&#8217;re editing text but not so good if you want to remove all the blank lines in a buffer as it only acts on lines around point. My example in the article where I used a macro I did use delete-blank-lines.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: piyo</title>
		<link>http://www.masteringemacs.org/articles/2011/03/16/removing-blank-lines-buffer/#comment-699</link>
		<dc:creator>piyo</dc:creator>
		<pubDate>Sun, 20 Mar 2011 01:14:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.masteringemacs.org/?p=379#comment-699</guid>
		<description><![CDATA[Is M-x delete-blank-lines available on your Emacs? I verified I can use it on Gnu Emacs 22.3.]]></description>
		<content:encoded><![CDATA[<p>Is M-x delete-blank-lines available on your Emacs? I verified I can use it on Gnu Emacs 22.3.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
