<?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: Emacs Utility Functions</title>
	<atom:link href="http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/feed/" rel="self" type="application/rss+xml" />
	<link>http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/</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: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/#comment-7776</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Sat, 01 Aug 2009 07:52:46 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=725#comment-7776</guid>
		<description><![CDATA[Hi dim,

Everyone should have a version of duplicate-current-line ;)  And I really should take one of these fixed version.

By the way, there is a dotimes macro in cl.el which you can use instead of your (while (&gt; n 0) ...)]]></description>
		<content:encoded><![CDATA[<p>Hi dim,</p>
<p>Everyone should have a version of duplicate-current-line <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   And I really should take one of these fixed version.</p>
<p>By the way, there is a dotimes macro in cl.el which you can use instead of your (while (&gt; n 0) &#8230;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dim</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/#comment-7775</link>
		<dc:creator><![CDATA[dim]]></dc:creator>
		<pubDate>Fri, 31 Jul 2009 21:49:55 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=725#comment-7775</guid>
		<description><![CDATA[Hi,

Reading your blog entry made me think I need a duplicate-current-line function, and one that works even when point is into last buffer&#039;s line :)

I&#039;m fond of elisp, some minutes later I&#039;m enjoying this:

;; duplicate current line
(defun duplicate-current-line (&amp;optional n)
  &quot;duplicate current line, make more than 1 copy given a numeric argument&quot;
  (interactive &quot;p&quot;)
  (save-excursion
    (let ((nb (or n 1))
	  (current-line (thing-at-point &#039;line)))
      ;; when on last line, insert a newline first
      (when (or (= 1 (forward-line 1)) (eq (point) (point-max)))
	(insert &quot;\n&quot;))

      ;; now insert as many time as requested
      (while (&gt; n 0)
	(insert current-line)
	(setq n (- n 1))))))

(global-set-key (kbd &quot;C-S-d&quot;) &#039;duplicate-current-line)]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Reading your blog entry made me think I need a duplicate-current-line function, and one that works even when point is into last buffer&#8217;s line <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;m fond of elisp, some minutes later I&#8217;m enjoying this:</p>
<p>;; duplicate current line<br />
(defun duplicate-current-line (&amp;optional n)<br />
  &#8220;duplicate current line, make more than 1 copy given a numeric argument&#8221;<br />
  (interactive &#8220;p&#8221;)<br />
  (save-excursion<br />
    (let ((nb (or n 1))<br />
	  (current-line (thing-at-point &#8216;line)))<br />
      ;; when on last line, insert a newline first<br />
      (when (or (= 1 (forward-line 1)) (eq (point) (point-max)))<br />
	(insert &#8220;\n&#8221;))</p>
<p>      ;; now insert as many time as requested<br />
      (while (&gt; n 0)<br />
	(insert current-line)<br />
	(setq n (- n 1))))))</p>
<p>(global-set-key (kbd &#8220;C-S-d&#8221;) &#8216;duplicate-current-line)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/#comment-7771</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Tue, 28 Jul 2009 19:38:25 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=725#comment-7771</guid>
		<description><![CDATA[Hi Alex,

Thanks for the list.  I have a version of chomp that looks remarkably similar myself :)

And I found Ruslan&#039;s nice htmlize snippet in a previous &lt;a href=&quot;http://curiousprogrammer.wordpress.com/2009/03/01/emacs-links-2009-09/&quot; rel=&quot;nofollow&quot;&gt;link round-up&lt;/a&gt;.

Cheers]]></description>
		<content:encoded><![CDATA[<p>Hi Alex,</p>
<p>Thanks for the list.  I have a version of chomp that looks remarkably similar myself <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And I found Ruslan&#8217;s nice htmlize snippet in a previous <a href="http://curiousprogrammer.wordpress.com/2009/03/01/emacs-links-2009-09/" rel="nofollow">link round-up</a>.</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Bennee</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/#comment-7770</link>
		<dc:creator><![CDATA[Alex Bennee]]></dc:creator>
		<pubDate>Mon, 27 Jul 2009 08:11:44 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=725#comment-7770</guid>
		<description><![CDATA[A couple from my .emacs, first a bunch of string munging functions:
&lt;pre&gt;
;; String munging functions
;
; Extract the first group in a regex

(defun extract-string(regex string)
  &quot;Extract a string in a regex (the bit in ()&#039;s)&quot;
  (interactive)
  (let ((s string)) (if (string-match regex s) (match-string 1 s) s)))

; And building on that
(defun extract-value-from-pair(key string)
  &quot;Extract the value from AAAA=value pairs&quot;
  (let ((regex (concat key &quot;=\\(.*\\)$&quot;)))
    (extract-string regex string)))

; examples:
;  (extract-string &quot;name is \\(\.*\\) &quot; &quot;my name is Alex ok&quot;) = Alex
;  (extract-value-from-pair &quot;AAA&quot; &quot;AAA=xxx&quot;) = xxx

; chomp
(defun chomp(string)
  &quot;Perform a perl-like chomp&quot;
  (let ((s string)) (if (string-match &quot;\\(.*\\)\n&quot; s) (match-string 1 s) s)))
&lt;/pre&gt;
I also have a rather ugly &quot;which&quot; implementation which I&#039;m sure could be nicer.
&lt;pre&gt;
;; which-lookup
;
; Like the shell command of the same name except it trims to &#039;nil if
; it can&#039;t find anything

(defun which-lookup(name)
  &quot;Perform a `which` like file look-up&quot;
  (let
      ((file (chomp
              (shell-command-to-string
               (concat &quot;which &quot; name)))))
    (if (and (file-exists-p file) (&gt; (length file) 0))
        (concat file)
      ())))
&lt;/pre&gt;
And finally the borrowed script that brings you the formatting of this posting.
&lt;pre&gt;
      ; From http://ruslanspivak.com/2007/08/18/htmlize-your-erlang-code-buffer/
      (defun my-htmlize-region (beg end)
        &quot;Htmlize region and put into &lt;pre&gt; tag style that is left in &lt;body&gt; tag
plus add font-size: 8pt&quot;
        (interactive &quot;r&quot;)
        (let* ((buffer-faces (htmlize-faces-in-buffer))
               (face-map (htmlize-make-face-map (adjoin &#039;default buffer-faces)))
               (pre-tag (format
                         &quot;&lt;pre style=\&quot;%s font-size: 8pt\&quot;&gt;&quot;
                         (mapconcat #&#039;identity (htmlize-css-specs
                                                (gethash &#039;default face-map)) &quot; &quot;)))
               (htmlized-reg (htmlize-region-for-paste beg end)))
          (switch-to-buffer-other-window &quot;*htmlized output*&quot;)
                                        ; clear buffer
          (kill-region (point-min) (point-max))
                                        ; set mode to have syntax highlighting
          (nxml-mode)
          (save-excursion
            (insert htmlized-reg))
          (while (re-search-forward &quot;&lt;pre&gt;&quot; nil t)
            (replace-match pre-tag nil nil))
          (goto-char (point-min))))
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>A couple from my .emacs, first a bunch of string munging functions:</p>
<pre>
;; String munging functions
;
; Extract the first group in a regex

(defun extract-string(regex string)
  "Extract a string in a regex (the bit in ()'s)"
  (interactive)
  (let ((s string)) (if (string-match regex s) (match-string 1 s) s)))

; And building on that
(defun extract-value-from-pair(key string)
  "Extract the value from AAAA=value pairs"
  (let ((regex (concat key "=\\(.*\\)$")))
    (extract-string regex string)))

; examples:
;  (extract-string "name is \\(\.*\\) " "my name is Alex ok") = Alex
;  (extract-value-from-pair "AAA" "AAA=xxx") = xxx

; chomp
(defun chomp(string)
  "Perform a perl-like chomp"
  (let ((s string)) (if (string-match "\\(.*\\)\n" s) (match-string 1 s) s)))
</pre>
<p>I also have a rather ugly &#8220;which&#8221; implementation which I&#8217;m sure could be nicer.</p>
<pre>
;; which-lookup
;
; Like the shell command of the same name except it trims to 'nil if
; it can't find anything

(defun which-lookup(name)
  "Perform a `which` like file look-up"
  (let
      ((file (chomp
              (shell-command-to-string
               (concat "which " name)))))
    (if (and (file-exists-p file) (&gt; (length file) 0))
        (concat file)
      ())))
</pre>
<p>And finally the borrowed script that brings you the formatting of this posting.</p>
<pre>
      ; From <a href="http://ruslanspivak.com/2007/08/18/htmlize-your-erlang-code-buffer/" rel="nofollow">http://ruslanspivak.com/2007/08/18/htmlize-your-erlang-code-buffer/</a>
      (defun my-htmlize-region (beg end)
        "Htmlize region and put into &lt;pre&gt; tag style that is left in &lt;body&gt; tag
plus add font-size: 8pt"
        (interactive "r")
        (let* ((buffer-faces (htmlize-faces-in-buffer))
               (face-map (htmlize-make-face-map (adjoin 'default buffer-faces)))
               (pre-tag (format
                         "&lt;pre style=\"%s font-size: 8pt\"&gt;"
                         (mapconcat #'identity (htmlize-css-specs
                                                (gethash 'default face-map)) " ")))
               (htmlized-reg (htmlize-region-for-paste beg end)))
          (switch-to-buffer-other-window "*htmlized output*")
                                        ; clear buffer
          (kill-region (point-min) (point-max))
                                        ; set mode to have syntax highlighting
          (nxml-mode)
          (save-excursion
            (insert htmlized-reg))
          (while (re-search-forward "&lt;pre&gt;" nil t)
            (replace-match pre-tag nil nil))
          (goto-char (point-min))))
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jared</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/#comment-7769</link>
		<dc:creator><![CDATA[Jared]]></dc:creator>
		<pubDate>Sun, 26 Jul 2009 20:29:14 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=725#comment-7769</guid>
		<description><![CDATA[I knew I&#039;d learn something from posting this, thanks Ian.  (I&#039;m slightly surprised about &lt;i&gt;identity&lt;/i&gt; as I thought I&#039;d looked for it, but not about the rest).]]></description>
		<content:encoded><![CDATA[<p>I knew I&#8217;d learn something from posting this, thanks Ian.  (I&#8217;m slightly surprised about <i>identity</i> as I thought I&#8217;d looked for it, but not about the rest).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Eure</title>
		<link>http://curiousprogrammer.wordpress.com/2009/07/26/emacs-utility-functions/#comment-7768</link>
		<dc:creator><![CDATA[Ian Eure]]></dc:creator>
		<pubDate>Sun, 26 Jul 2009 18:02:39 +0000</pubDate>
		<guid isPermaLink="false">http://curiousprogrammer.wordpress.com/?p=725#comment-7768</guid>
		<description><![CDATA[I don’t know why you’d want `identity&#039;, since it’s a C builtin:
`identity is a built-in function in `C source code&#039;.
(identity arg)
Return the argument unchanged.&#039;

You might also look at `normal-top-level-add-subdirs-to-load-path&#039;, which adds all subdirectories of a path to load-path. You can just point it at your lisp folder and you don’t have to worry about maintaining the load-path anymore.

ELisp also has `delete-dups&#039;, and there’s `delete-duplicates&#039; in cl.el. Both alter the source list. There&#039;s `remove-duplicates&#039; (also in cl.el), which returns a copy with dupes removed. And more generally, there’s `remove-if&#039;.

Here’s my duplicate-line, which will DTRT, at least for me:

(defun duplicate-line (&amp;optional arg)
  &quot;Duplicate the current line to the line below&quot;
  (interactive &quot;p&quot;)
  (let ((beg (line-beginning-position))
        (end (line-end-position arg)))
    (goto-char end)
    (newline)
    (insert (buffer-substring beg end))))

The string-repeat implementation can be rewritten as well:

(defun string-repeat (str n)
    (apply &#039;concat (make-list n str)))]]></description>
		<content:encoded><![CDATA[<p>I don’t know why you’d want `identity&#8217;, since it’s a C builtin:<br />
`identity is a built-in function in `C source code&#8217;.<br />
(identity arg)<br />
Return the argument unchanged.&#8217;</p>
<p>You might also look at `normal-top-level-add-subdirs-to-load-path&#8217;, which adds all subdirectories of a path to load-path. You can just point it at your lisp folder and you don’t have to worry about maintaining the load-path anymore.</p>
<p>ELisp also has `delete-dups&#8217;, and there’s `delete-duplicates&#8217; in cl.el. Both alter the source list. There&#8217;s `remove-duplicates&#8217; (also in cl.el), which returns a copy with dupes removed. And more generally, there’s `remove-if&#8217;.</p>
<p>Here’s my duplicate-line, which will DTRT, at least for me:</p>
<p>(defun duplicate-line (&amp;optional arg)<br />
  &#8220;Duplicate the current line to the line below&#8221;<br />
  (interactive &#8220;p&#8221;)<br />
  (let ((beg (line-beginning-position))<br />
        (end (line-end-position arg)))<br />
    (goto-char end)<br />
    (newline)<br />
    (insert (buffer-substring beg end))))</p>
<p>The string-repeat implementation can be rewritten as well:</p>
<p>(defun string-repeat (str n)<br />
    (apply &#8216;concat (make-list n str)))</p>
]]></content:encoded>
	</item>
</channel>
</rss>
