Emacs Key Macro Example: Modify Webfeed Entries

By Xah Lee. Date: . Last updated: .

Here's a example of keyboard macro use.

I have a webfeed file blog.xml in Atom Webfeed format. [see Atom Webfeed Basics] There are many text blocks like this:

  <content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>see <a href="http://xahlee.blogspot.com/2011/11/emacs-lisp-exercise-insert-random-uuid.html">http://xahlee.blogspot.com/2011/11/emacs-lisp-exercise-insert-random-uuid.html</a></p>
 <link rel="alternate" href="http://xahlee.org/emacs/blog.html"/>

I need to remove the “content” part and simply put the URL in the alternate link, like this:

 <link rel="alternate" href="http://xahlee.blogspot.com/2011/11/emacs-lisp-exercise-insert-random-uuid.html"/>

Kmacro is excellent solution for this. You just call interactive search to move cursor to places you want, and do delete or copy and paste. Like this.

  1. isearch-forwardCtrl+s】 for http://xahlee.blogspot.
  2. isearch-backwardCtrl+r】 for ", move cursor forward 1 position, set mark.
  3. isearch-forward for ", do a copy. Now the blog URL is in clipboard
  4. isearch-backward for <content , set mark.
  5. isearch-forward for </content>.
  6. Press delete to delete the content section.
  7. isearch-forward for href=.
  8. Do steps to delete the URL (using isearch and set mark like above), then paste the new one.

Once i recorded these steps, then i call kmacro-end-and-call-macroCtrl+x e】. This way, every 2 keystrokes makes one entry change. This allows me to visually verify what i've done is correct. I could also press 【Ctrl+u】, then a number, then 【Ctrl+x e】 to repeat it automatically n times.

Emacs Keyboard Macro Topic

  1. Emacs: Keyboard Macro
  2. Emacs Key Macro Example: Add Title of URL
  3. Emacs Key Macro Example: Add HTML Attribute
  4. Emacs Key Macro Example: Modify Webfeed Entries
  5. Emacs Key Macro Example: Insert All Unicode Bullets
  6. Emacs Key Macro Example: Eval Emacs Lisp Repeatedly
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.