Useful Commands For The Emacs Minibuffer

I have long used 【Meta+p】 to recall previously entered information in the minibuffer. For example, when I’m editing Groff input it’s often convenient to typeset what I have so far to check that the result looks good or just to read what I’ve written without the markup. I do that by selecting the entire buffer with 【Ctrl+x h】, piping the buffer to groff with 【Meta+|】, and then specifying the command

groff -ms -pset -X | gxditview

It’s a pain to keep typing that so after the first time I just type 【Meta+p】 to bring up the pipeline again.

You can, of course, move forward in the minibuffer history with 【Meta+n】 but there are some other not so obvious ways of navigating the minibuffer. The command 【Meta+rregexpReturn】 will search backward in the minibuffer history for the entry matching the regular expression regexp. Similarly, 【Meta+sregexpReturn】 will search forward for the entry matching regexp. You can continue either of these searches to the next match with 【Meta+r Return】 or 【Meta+s Return】.

Finally, you can repeat the last echoed message with 【Ctrl+h e

Summary

Key Sequence Operation
Meta+p Backward one entry
Meta+n Forward one entry
Meta+rregexpReturn Search backwards for regexp
Meta+sregexpReturn Search forward for regexp
Meta+r Return Repeat backward REGEXP search
Meta+s Return Repeat foreard REGEXP search
Ctrl+h e Show last echoed message

Update: 【Meta+s】 → 【Meta+n】 in summary

Posted in General | Tagged | 1 Comment

Administrivia—Moderation

Some of you may have noticed that your comments were held in the moderation queue longer than usual the last two days. That’s because I haven’t been getting email notifications of new comments. I’ll look into what’s happening there but in the mean time this seems like the right moment to institute a change I’ve been thinking about anyway.

Since I implemented the captcha, my forum spam has disappeared so I am no longer going to hold normal messages for moderation. Some messages—those WordPress is suspicious of—get held automatically. If the forum spam becomes a problem again in the future I may have to reconsider but for now your comments should appear when you post them.

Again, I’m sorry about the captcha but over 90% of the comments were spam and I was spending a lot of time dealing with them. If you comment regularly, it may pay to register as then the captcha doesn’t appear.

Posted in Blogging | Tagged | Leave a comment

Today Is Dennis Ritchie Day

Tim O’Reilly has declared today Dennis Ritchie Day and asks us all to remember the contributions of this computing pioneer. For his part, O’Reilly insists that without Ritchie’s work, O’Reilly Media would not exist.

As I wrote in my short post about his death, Ritchie had tremendous impact on my growth and career in computing so I am happy to oblige Mr. O’Reilly and mark the day here at Irreal.

Posted in General | Leave a comment

Mickey Plays VimGolf In Emacs

I’ve written a couple of times about Tim Visher’s VimGolf In Emacs series of videos. If you’re an Emacs user and haven’t taken a look at them yet, you should do so without delay. They are very informative and entertaining.

Now Mickey Petersen over at Mastering Emacs has gotten into the act. That makes me very happy because I really enjoy seeing how other Emacs users solve editing problems. I almost invariably learn something useful by watching or reading those solutions. Mickey’s take on the problems is a little different from Visher’s. He says up front that there’s no way Emacs is going to be as efficient in terms of keystrokes as Vim and instead he concentrates on finding a general—or as he says, technically correct—solution. By that he means a solution that works for bigger or smaller data. The problem with VimGolf solutions is that they tend to be crafted for the particular piece of data that’s being edited. That’s because in order to minimize keystrokes the solution has to be tailored to the specific data in the problem.

The problem that Mickey considers is to sort the following records into alphabetical order by people’s names.

## Directory
   * Smith, George
      - 1234 Avenue, New York, NY
   * Bailey, Stephen
      - 4545 Harbor Ln, Atlanta, GA
      - Phone: (412) 291-1238
   * Thomas, Brent
      - 1482 Mystic Oaks, Anaheim, CA
   * Grant, Jenny
      - 198 Circle Dr, Houston, TX
      - Phone: (213) 198-9842
      - Email: jenny.grant@gmail.com
   * Percy, Adam
      - 221 Jaguar Pkwy, Missoula, MT
   * Garfield, Misty
      - 5988 Apple Tree Ln, Memphis, TN
   * Parsons, Betty
      - Phone: (235) 523-2378
      - Email: bettyboop123@gmail.com
   * Sanders, Terry
      - Email: sanderst@yahoo.com
   * Smith, Pete
      - Phone: (294) 984-2938
   * Frost, Jennifer
      - 2498 Temple Terrace, Miami, FL
   * Matthews, Frank
      - 418 Happy Trail, Phoenix, AZ
      - Phone: (985) 129-2394
      - Email: frank@phoenixrealtors.net
   * Allen, Taylor
      - Email: allen.taylor@hotmail.com
   * McCullen, Sarah
      - 247 Hidden Elm, Seattle, WA
      - Phone: (288) 283-4568
   * Perkins, Mike
      - 992 Peartree Ln, Bowling Green, KY

Think for a second or two how you might do that in Emacs and then jump over to Mickey’s post to see how he leveraged the power of Org-mode to solve the problem. It’s a brilliant solution and with smex installed is probably competitive with the Vim solutions even without trying.

Posted in General | Tagged | 5 Comments

Emacs Registers

Back in September I wrote about using registers to open frequently accessed files. Shortly afterwards, someone recommended just saving my desktop with desktop-save-mode and I haven’t really used registers since. More recently, I started watching Tim Visher’s excellent VimGolf in Emacs videos. Video #4 talks about, among other things, saving window/frame configurations in registers that you can then jump to. That caught my imagination so I looked into the use and abuse of registers some more.

As the name suggests, registers can hold various types of objects. They can hold

  • Positions
  • Text
  • Rectangles
  • Window and Frame configurations
  • Numbers
  • File names

Each register has a single character name by which it can be accessed. Thus a register could be named 1, or a, or A, or Ctrl-a. Only Ctrl-g is off limits for obvious reasons.

Now let’s take a look at how they can be used. First up is saving positions. This can be handy if you want to repeatedly refer to, say, a function in one of the buffers. To save a position in register ρ you would put the point at the position you want to save and type 【Ctrl+x r Space ρ】. To return to that position from the same or another buffer you would type 【Ctrl+x r j ρ】. This works even if the buffer containing the position has been killed providing the buffer was associated with a file.

You can copy or move a region into register ρ with the command 【Ctrl+x r s ρ】 and insert it at point with the command 【Ctrl+x r i ρ】. That’s how I inserted the rho (ρ) into the text—I looked it up once and then copied it into register r so I didn’t have to keeping going through the ucs-insert routine.

If you give the 【Ctrl+x r s ρ】 command a prefix argument, it will delete the original region after copying it into the register.

There are two other less frequently used commands to store text to registers: 【Meta+xappend-to-registerReturnρ and 【Meta+xprepend-to-registerReturnρ. These will append or prepend the region to the text already in register ρ. If you specify a prefix argument, the region will be erased after it is copied into the register.

You can copy a rectangle to register ρ with 【Ctrl+x r r ρ】 and insert it with 【Ctrl+x r i ρ】 as before. Just as with regions, specifying a prefix with the copy command will delete the original rectangle.

If you have a particular window configuration in the current frame your can save that configuration in register ρ with 【Ctrl+x r w ρ】 and you can later restore that configuration by jumping to it with 【Ctrl+x r j ρ】.

If you want to save the configuration of all frames and their windows in register ρ, use 【Ctrl+x r f ρ】.

Registers can also contain numbers. These numbers can be incremented, which make them useful for certain types of keyboard macros. To store N into register ρ, use 【Ctrl+u N Ctrl+x r n ρ】. To increment the number in register ρ by I use 【Ctrl+u I Ctrl+x r + ρ】.

You can insert the number in register ρ at point by using the usual insert command: 【Ctrl+x r i ρ】.

I’ve already dealt with storing file names in registers in the previous post linked above.

Summary

Key Sequence Function
Ctrl+x r Space ρ Copy position to register ρ
Ctrl+x r j ρ Jump to the position in register ρ
Ctrl+x r s ρ Copy/Move region to register ρ
Ctrl+x r i ρ Insert object in register ρ at point
Ctrl+x r r ρ Copy/Move rectangle to register ρ
Ctrl+x r w ρ Copy current frame configuration to register ρ
Ctrl+x r f ρ Copy all frame configurations to register ρ
Ctrl+u N Ctrl+x r n ρ Insert N into register ρ
Ctrl+u I Ctrl+x r + ρ Increment register ρ by I
Posted in General | Tagged | 1 Comment

Blogging With Emacs

Xah Lee asked me to write about my blog publishing process and how an article gets from Emacs to my site. I’ve written about most of the parts of the process in various posts but it might be useful to tie everything together in a single post for the benefit of any Emacs users who want to start a blog.

I write my posts with Org-mode in Emacs. As the Org Manual puts it,

“Org-mode contains an HTML (XHTML 1.0 strict) exporter with extensive
HTML formatting, in ways similar to John Gruber’s markdown language,
but with additional support for tables.”

The Org-mode markup language makes it easy to insert formatting—such as bold, italics, and code—and hyperlinks to other documents. Even someone with no knowledge of HTML could produce very nice Web pages.

During the writing of the post, and afterward as a final check, I can send it to my browser to see what it will look like. That won’t be exactly what you see on Irreal, of course, because I’m really just exporting the post to HTML and displaying in my browser without the benefit of the WordPress style sheet.

As I explain below, it’s possible to write a post, export it to HTML, and then paste it directly into your site’s editing window but I have a (much) better way. Once I’m satisfied with the post I export it directly to my site using org2blog. Making one call to org2blog takes care of everything in a single step:

  • The post is converted to HTML
  • The HTML is uploaded to the WordPress process on my site
  • Any pictures or other images in the post are uploaded to the site and their links are adjusted to point to the site’s machine rather than my workstation
  • The date and Post ID are added to the Emacs buffer containing the post
  • Information about the post is recorded in .org2blog.org so that any updates to the post will result in the original post being updated rather than a new post being added.

By doing all these things, org2blog takes care of the majority of the bookkeeping chores associated with making a post.

When org2blog finishes with the upload, I save the file again (to save the date and Post ID that org2blog added), and call Magit to put it in Git. Then I call dired for my blog directory, type 【* .html to mark any HTML files and then 【D】 to delete the HTML files and any associated buffers. At this point, I’m done. The post has been published, the source for it filed away in Git, and extraneous files and buffers have been deleted.

My old blog, also called Irreal, was hosted on Blogger. Although there is a version of org2blog (by a different author) for Blogger I didn’t use it. Instead, I used this function

(defun blog-post ()
  "Export an org buffer as HTML but only export the body."
  (interactive)
  (org-export-as-html 3 nil nil "*blog-post*" t))

to convert the post to HTML and export the body. Then I would copy the *blog-post* buffer to the clipboard and paste it into Blogger’s HTML editor. That worked fairly painlessly unless there was an image involved. Blogger stores the images in Picasa instead of with the post so doing things by hand can be a bit involved. I wrote about that here. I don’t know if the Blogger version of org2blog handles pictures automatically but if it did, that would be reason enough to use it. If it is anywhere close to as convenient as the WordPress version it would be worth using. If you use org2blog on Blogger, leave a comment telling us about your experiences with it.

Posted in Blogging | Tagged , | 6 Comments

Applying and And or In Emacs

Zach Beane has a nice Common Lisp tip about applying and. The problem that the tip addresses is how to apply and to a list of values to test that they are all true. One might think that you could simply use apply in the normal way

(apply #'and list)

but and is a macro so this doesn’t work. The solution is to use the every function like this

(every #'identity list)

This will return t if every element of list is t. All this is also true of Emacs Lisp so it’s worth mentioning in an Elisp context too.

Although Beane doesn’t mention it, the same problem exists for or. The way to handle or is with the some function

(some #'identity list)

The some function will return the first true element in the list or nil if there is none.

Longtime readers will remember that we’ve talked about some before. Both some and every are a bit more general than I’ve indicated here. Their first argument can be any predicate so that

(some 'pred list)

will return the first element of the list for which pred evaluates to t. Similarly for every. Also note that for Emacs Lisp it suffices to just quote the predicate function rather than using the #' that Common Lisp requires.

Posted in Programming | Tagged , | 3 Comments

John McCarthy

It’s been a sad month for the computer community. First Steve Jobs and Dennis Ritchie and now John McCarthy has died. McCarthy was the creator of Lisp and an important researcher in—some say the father of—artificial intelligence.

Posted in General | Leave a comment

More Bad News For The Publishing Industry

I’ve written before on The Future Of Books and how the publishing industry is in peril. The latest move from Amazon is apparently terrorizing the publishers and with good reason. According to articles in the New York Times and TechFlash, Amazon is recruiting authors—including established authors—directly and cutting out the traditional publishing houses. In some cases even agents are getting cut out of the loop. Talk about disintermediation.

Amazon appears to be serious about this. They’ve hired former agent and publisher Laurence J. Kirshbaum to head their publishing division. The Times reports that they paid Penny Marshall $800,000 for a memoir, which they will publish both as an ebook and a traditional dead tree book. If you Google amazon imprints you’ll see that Amazon is regularly adding imprints.

It’s often been said that the only necessary players in the publishing game are the writers and the readers. With this move, Amazon has reduced the chain to only 3 links. Cory Doctorow has already demonstrated that it’s possible to reduce that chain to just the two necessary links but most authors won’t have the skills or desire to do everything themselves and even Doctorow uses Amazon’s print-on-demand service to help with distribution. If Amazon offers authors more than the typical 15% of sale price, they could cut into the publisher’s business in a serious way.

What can the traditional publishers do? I don’t know but they are certainly going to have to change their business models and their relationships with their authors. They could—finally—learn from the music industry and get rid of DRM on ebooks. They could stop pretending that printing and shipping is essentially free and sell ebooks directly to consumers at a decent price. They could cut deals with Apple and other Amazon competitors to offer their entire catalogs in ebook format. Most of all, they must come to grips with the reality that printing press is rapidly becoming a thing of the past. The threat to their traditional business model is no longer theoretical; Amazon is storming the ramparts in a very real way.

Posted in General | 2 Comments

Making The Emacs Minibuffer Recursive

Mickey, over at Mastering Emacs, has a great post on Executing Shell Commands in Emacs and does his usual excellent job of explaining the fine points of his subject matter. I’ve written about some of this material here, but there’s lot of stuff I haven’t covered so you should definitely go read the post.

One of the things that was new to me was recursive minibuffers. What that means is that you can interrupt what you’re doing in the minibuffer to run some other command and then use it’s output in the original command. The need to do this doesn’t come up often—at least for me—but when it does it’s frustrating not to be able to do it. By default, the recursion is turned off but all you need do to enable it is to add

(setq enable-recursive-minibuffers t)

to your .emacs or init.el file.

Here’s a (slightly contrived) example of how you might use the capability. Suppose you’re one of those annoying bloggers who, unlike me, has a backlog of posts ready to publish and that you keep their file names in a file called scheduled. You want to load the top file into Emacs so that you can publish it with org2blog. You type 【Ctrl+x Ctrl+f】 to call find-file but realize you don’t know the first file on the list. You can load its name into the minibuffer for find-file (or ido-find-file) by typing 【Ctrl+u Meta+!】 and then head -1 scheduled. As Mickey explains, the output of most shell commands will have a newline at the end so you’ll need to delete it before pressing 【Return】.

Mickey gives another example of its use but I don’t want to step on his post by reiterating it here so, again, you should go read his post. If you have an interesting use case for this capability, leave a comment.

Posted in General | Tagged | 2 Comments