Stross on Ebooks

Charlie Stross has a very interesting post on the history of ebooks. Stross, of course, is a well known Science Fiction author who earns his living writing books so he’s very familiar with the publishing industry and its history. The post is mainly the text of a speech he gave at the CREATe conference, a UK research council made up of academics from 7 universities intended to help the UK “creative” industries adapt and thrive in the digital age.

Stross traces the history of ebooks, the reaction to them by the publishing industry, and their effect on authors. Most Irreal readers will be familiar with some of the story but Stross fills in the gaps and brings all the pieces together. It’s an informative post and well worth a read.

Posted in General | Leave a comment

Emacs Challenge?

Some of the most popular posts here at Irreal are those in which I attempt bring the power of Emacs to bear on VimGolf problems. I like those posts too because I always learn some new tricks both by working on the problem myself and from the (usually better) solutions that readers contribute. Commenters on other blogs have lamented that there’s no EmacsGolf to challenge and entertain users of the one true editor. I’ve been wondering if there’s really any interest in that.

To me the value of such a site would be the opportunity to try some challenges working the way the typical Emacs user works and thus learn new techniques both self-discovered and from others. That means that the rules should be a bit different from VimGolf. Here’s some ideas off the top of my head

  • Any ELPA package from the standard sites could be used because, after all, that’s how we actually do our work.
  • External tools accessed through mechanisms such as 【Ctrl+u Meta+|】 are allowed for the same reason.
  • Solutions would be held for a week, say, and then posted all at once.
  • Maybe favor real-world problems so that the solutions are more generally applicable.

Is there any interest in such a thing? If so, we can start off easy by posting the challenges and solutions here at Irreal. If there’s enough participation, it would probably be worth moving it to its own site. I am definitely not a front-end person so if I do all the heavy lifting, even the new site would be WordPress (or something) based. If someone with the requisite skills wants to get involved we could make it more like the VimGolf site or whatever seems best.

If you would be interested in this leave a comment. Feel free to suggest additional or alternative rules. If enough people respond positively, I’ll make up some challenges (and solicit them from readers) and start posting them here at Irreal. If we get enough traction, I’ll mount a separate site.

I thought about calling this thing EmacsGolf or something similar but that seems a bit derivative so I’m thinking along the lines of The Emacs Challenge or something like that. Suggestions welcome.

Update: 【Ctrl+|】 → 【Meta+|

Posted in Blogging | Tagged | 9 Comments

VimGolf in Emacs: Enumerate Words

Here’s a pretty hard challenge—at least I found it challenging. Given this Lorem Ipsum

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.

list the unique, capitalized words in alphabetical order:

Accusam
Aliquyam
Amet
At
Clita
Consetetur
Diam
Dolor
Dolore
Dolores
Duo
Ea
Eirmod
Elitr
Eos
Erat
Est
Et
Gubergren
Invidunt
Ipsum
Justo
Kasd
Labore
Lorem
Magna
No
Nonumy
Rebum
Sadipscing
Sanctus
Sea
Sed
Sit
Stet
Takimata
Tempor
Ut
Vero
Voluptua

The winning Vim solutions use 23 keystrokes but the best I can do is 32. My solution:

Ctrl+Meta+% Invoke query-replace-regexp
space Return Replace spaces
Ctrl+q Ctrl+j Return With carriage returns
! In the entire buffer
Meta+< Back to top-of-buffer
Ctrl+Meta+% Invoke query-replace-regexp
[.,]Return Replace periods and commas
Return With nothing
! In the entire buffer
Return Down one line
Ctrl+Return Invoke rectangle mode
Meta+< Extend rectangle to top-of-buffer
Meta+u Upcase rectangle
Ctrl+x h Mark buffer
Ctrl+u Meta+| Pipe to shell and replace
sort -uReturn Sort and delete duplicates

Most of the work involved the two query-replace-regexp calls but I couldn’t figure out a way to do it in one without causing other problems. The call to the external sort may be a technical violation but I’m claiming that we’re grandfathered in by Tim on that.

I think the Vimers did so well because Vim has an internal sort that’s easy to invoke. I’m sure many of you can beat my pathetic 32 so leave a comment with your better solutions.

Posted in General | Tagged | 14 Comments

Xah’s Emacs Tutorial

I’ve commented many times on Xah Lee’s Emacs and Emacs Lisp tutorials. I’ve learned a lot from them and the Elisp tutorials helped me transfer my Common Lisp and Scheme knowledge to Emacs.

The tutorials are on the Web and available for free at the links above but Lee also makes them available as ad-free zip files for those who’d like a local copy. Lee charges $5 for the files but makes updates available for free. Lee has just released another archive of the tutorials so this is a good time to get a copy if you’re interested. Buying the tutorials is a good way to support Lee’s effort so if, like me, you find them useful contribute the $5 if you can.

Posted in General | Tagged | 1 Comment

Sony: The Bill So Far

Back in 2011 I wrote about the Sony break in and subsequent disclosure of 100 million log on credentials. At the time I remarked that it would be years before the final cost of the exploit would be known. Now we know that the answer—at least for monetary costs—is $172,000,000. It’s almost enough to make you feel sorry for Sony until you remember the details.

One would think that this object lesson would get other high profile sites to clean up their act but of course it hasn’t. We still have sites storing passwords in plain text, not keeping their systems patched, misusing SSL and all manners of other transgressions. The article at the link says that the average attack costs a company $5,500,000. You’d think that would be enough to get their attention but apparently not. At least it provides a never ending source of blog posts.

Posted in General | Tagged | Leave a comment

Another Emacs Quote

Vivkek Haldar appears to be the go to guy for Emacs quotes. Magnar Sveen’s excellent What the Emacs.d!? begins and end with a Haldar quote. Now Haldar brings us a quote from Kieran Healy on the enduring excellence of Emacs. Take a look. If you’re an Emacasien1, it will resonate.

Footnotes:

1 Hey, it’s my blog; I get to make up words.

Posted in General | Tagged | Leave a comment

Another Take on Emacs Configuration

I’ve mentioned before that Emacs configuration is a black hole that can easily swallow any spare cycles that wander into its event horizon. Part of that for me is reading how other people do it. Over at MetaSandwich, Selah has an interesting take on how to do it correctly. One of the things that makes it interesting for me is that he is one of the few people I’ve read who do essentially what I do.

He writes about what he considers the two main problems in Emacs configuration:

  1. How you should arrange the configuration file to make Emacs startup as fast as possible.
  2. Where should you put things.

Selah says he used to spend a lot of time worrying about how to minimize his startup time. Then one day he realized that, hey, it doesn’t really matter. It doesn’t matter because he, like most of us, doesn’t restart Emacs very often. He starts his once or twice a week; I keep mine going for weeks at a time. I usually start Emacs only at boot time and I reboot only for an OS upgrade or, in the case of my laptop, if I’m traveling. So startup time doesn’t matter very much. As Selah points out, even if it took 30 seconds that’s less than a minute a week (for him) and maybe 5 seconds for me.

As it turns out, emacs-init-time tells me that my current startup time on my iMac is 4.8 seconds without me spending a single second trying to optimize it. Why should I worry about it? I feel confident that that’s true for most of us.

The second problem is a little more controversial. Most of the Emacs hackers that I respect tend to have a complicated configuration architecture with several files and even subdirectories. Look at Steve Purcell’s or Magnar Sveen’s configurations for examples of that strategy. I on the other hand keep pretty much everything in init.el. Recently, I boldly struck out for uncharted territory and moved machine and platform specific configurations into their own small files that get loaded automatically based on the system-name and system-type variables but mostly everything lives in a single file.

I’ve often felt like the Maytag repairman because of my preference for a single file but now Selah joins the party and makes a pretty good case for having a single file. He even gives a little code that arranges a handy index of your init.el for use with imenu. That’s nice but I don’t need even that. I pretty much know where things are in my init.el and I have headers for the various sections so I can go right to them with incremental search.

In the end, of course, there’s no right or wrong way, just personal preferences. Still, I seem to be endlessly fascinated by how people do their configurations (and what’s in them, of course) so if you want to share your methods, leave a comment.

Posted in General | Tagged | 3 Comments

Swapping with replace-regexp

Most Irreal readers have probably already seen Mickey’s post on Evaluating Lisp Forms in Regular Expressions, but he mentions one trick that is too good to miss so I’m going to repeat it.

Not too long ago I was trying to find a way to swap several occurrences of two words in a buffer (I think it was for the VimGolf lamb had a little Mary challenge). I did find a way but I wasn’t very happy with it. In his post, Mickey shows a way that is, in retrospect, obvious but which didn’t occur to me. Suppose you have

Jill and Jack went up the hill to fetch a pail of water.
Jill fell down and broke his crown and Jack came tumbling after.

and you want to switch Jill and Jack so that you have the traditional rhyme. Here’s Mickey’s trick: do a replace-regexp (or query-replace-regexp) with a FROM string of

\(Jill\)\|Jack

and a TO string of

\,(if \1 "Jack" "Jill")

Notice that we capture only one subgroup and use it to determine which replacement word to use. If \1 is nil then we didn’t match Jill so we must have matched Jack and we want to use Jill as the replacement. On the other hand, if \1 is not nil then we matched Jill and want to replace it with Jack. Very nice.

Mickey’s got some other nice tricks you can do with the form-based TO string in replace-regexp so be sure to read his post if you haven’t already.

Posted in General | Tagged | 2 Comments

A Word Frequency VimGolf in Emacs Challenge

Here’s an interesting VimGolf challenge that nicely demonstrates the power of CUA selection mode. Given the word frequency chart

     align here
the        56271872
of        33950064
and        29944184
to        25956096
in        17420636
I        11764797
that        11073318
was        10078245
his        8799755
he        8397205
it        8058110

align the frequency counts so that it looks like

     align here
the  56271872
of   33950064
and  29944184
to   25956096
in   17420636
I    11764797
that 11073318
was  10078245
his  8799755
he   8397205
it   8058110

My first thought was to use align-regexp but that command doesn’t have a shortcut key sequence and the best regular expression I could find was [1-9]. A pretty nice solution but it certainly won’t win on keystrokes.

After messing around a bit, I came up with a solution of 4 keystrokes using the CUA rectangle functionality.

Meta+m Move to the a in align
Ctrl+Return Invoke rectangle mode
Meta+} Move to end of buffer
Meta+a Align the rectangle

Notice that the trailing digits of a few of the frequency counts aren’t in the rectangle but they get dragged along anyway. I’ve only been using CUA rectangle mode for a short while but I am continually amazed at how powerful it is. Certainly this problem doesn’t look like a rectangle problem but CUA rectangle mode solves it very handily anyway.

Sadly, those darn Vim people were able to solve this in 3 keystrokes so if you can shave off a stroke or two be sure to leave a comment. I don’t think you can squeeze any more keystrokes out of the rectangle strategy so you’ll probably need something entirely different.

Posted in General | Tagged | 3 Comments

Living the Lisp Machine Environment

A little while ago I wrote about Martin Fowler’s post on InternalReprogrammability that celebrated Emacs reprogrammability and its recapitulation of the Lisp Machine environment. That capability is of more than theoretical importance as I, once again, discovered.

Long time readers know that the fancy 【Key】display on this blog is produced by a combination of CSS for the <kbd> tag and some Elisp that converts text such as ctrl+x b into 【@‍<kbd>Ctrl@‍</kbd>+@‍<kbd>x@‍</kbd> @‍<kbd>b@‍</kbd>】 (the @ in front of the tags is an Org mode thing that tells Org mode to export the tag that follows as raw HTML) which gets displayed as【Ctrl+x b】. The Elisp has some regular expression-based combining rules that handle minimally complex expressions such as ctrl+x b or ctrl+x ctrl+s. Recently—probably as a result of all the VimGolf in Emacs posts I’ve been doing—I’ve run into cases that the Elisp didn’t handle correctly. That’s not a big deal because I can just go in and fix the markup by hand. Indeed, I even have a chord, <>, that inserts @‍<> into the buffer so that I can easily insert the @‍<kbd> and @‍</kbd> tags.

The other day I was busy doing a bunch of those fix ups when, just as Fowler, I realized that I’d been dealing with this problem by doing more work than necessary. So I wrote a little Elisp

(defun enkey ()
  "Wrap the next word with (org-mode) <kbd> tags."
  (interactive)
  (insert "@<kbd>")
  (forward-word)
  (insert "@</kbd>"))

to do the wrapping of words (or singleton characters) in the <kbd> tags automatically. Now I just put the point before any word or character that didn’t get handled correctly by the conversion code, call enkey, and move on to the next problem.

It’s easy to forget—even when you write about it occasionally—how simple it is to fix minor editing annoyances with Emacs. A little bit of Elisp and the problem is solved.

Afterward

Another small annoyance that I hadn’t gotten around to dealing with is the inability to join the current line with the next one; you must move down and then combine the two lines with 【Meta+^】. Happily, that was an itch that also bothered Magnar Sveen so he fixed it. It’s another example of how Emacs lets you have it your way.

UpdateMeta+v】 → 【Meta+^

Posted in Programming | Tagged | 3 Comments