Some Common Lisp Resources

Here’s a collection of some useful Common Lisp resources that I’ve come across recently.

Posted in Programming | Tagged , | 2 Comments

A First Emacs Challenge

Xah Lee has contributed a challenge that serves as an excellent example of one of the types of problems I think we should concentrate on if we start an EmacsGolf site. I like this problem because it is a real problem of the type that Emacs users encounter every day.

Lee has a minor mode, xmsi-mode, that is useful for mathematical input (it’s very handy if you do that sort of thing; check it out). Recently, he was refactoring the code and wanted to change lines like

(puthash "■" "□" xmsi-abrvs)
(puthash "□" "■" xmsi-abrvs)
(puthash "●" "○" xmsi-abrvs)
(puthash "○" "●" xmsi-abrvs)
(puthash "◆" "◇" xmsi-abrvs)
(puthash "◇" "◆" xmsi-abrvs)
(puthash "▲" "△" xmsi-abrvs)
(puthash "△" "▲" xmsi-abrvs)
(puthash "◀" "◁" xmsi-abrvs)
(puthash "◁" "◀" xmsi-abrvs)
(puthash "▶" "▷" xmsi-abrvs)
(puthash "▷" "▶" xmsi-abrvs)
(puthash "▼" "▽" xmsi-abrvs)
(puthash "▽" "▼" xmsi-abrvs)
(puthash "★" "☆" xmsi-abrvs)
(puthash "☆" "★" xmsi-abrvs)
(puthash "♠" "♤" xmsi-abrvs)
(puthash "♤" "♠" xmsi-abrvs)
(puthash "♣" "♧" xmsi-abrvs)
(puthash "♧" "♣" xmsi-abrvs)
(puthash "♥" "♡" xmsi-abrvs)
(puthash "♡" "♥" xmsi-abrvs)
(puthash "♦" "♢" xmsi-abrvs)
(puthash "♢" "♦" xmsi-abrvs)

into lines like this

(xmsi-add-cycle ["■" "□"])
(xmsi-add-cycle ["●" "○"])
(xmsi-add-cycle ["◆" "◇"])
(xmsi-add-cycle ["▲" "△"])
(xmsi-add-cycle ["◀" "◁"])
(xmsi-add-cycle ["▶" "▷"])
(xmsi-add-cycle ["▼" "▽"])
(xmsi-add-cycle ["★" "☆"])
(xmsi-add-cycle ["♠" "♤"])
(xmsi-add-cycle ["♣" "♧"])
(xmsi-add-cycle ["♥" "♡"])
(xmsi-add-cycle ["♦" "♢"])

This isn’t a hard problem but how efficiently (in terms of keystrokes) can you solve it? You can use anything in core Emacs, ELPA, or any external tool accessed in the usual way from Emacs. As a baseline, I did it in 29 keystrokes without trying too hard. I’m sure many of you can do better. I’ll be trying too.

Thanks to Xah Lee for generously donating this challenge rather than posting it himself.

Posted in General | Tagged , | 8 Comments

An Emacs Minor Mode Tutorial

Over at the Google G+ Emacs Community, Agu Monkey has a pointer to an excellent tutorial on writing Emacs minor modes by Christopher Wellons. Most of us probably have no interest in writing a full-fledged minor mode (although Wellons’ tutorial is complete enough for that) but it’s often an easy way to provide some custom key bindings for a major mode or otherwise provide additional functionality.

Wellons takes us through the development of a trivial minor mode that merely inserts the word “foo” when called with a 【Ctrl+c f】 key sequence and keeps a count of how many foos are inserted. He shows how to make a buffer-local variable to count the insertions, how to instantiate a hook-function variable that users can insert hook functions into to run their own code when the minor mode is toggled, how to define a keymap for the minor mode, and how to activate the minor mode when a major mode is activated.

This is a really useful tutorial that you should read and then bookmark for the day that you want to add a little extra functionality to some mode or when you want to write a full blown minor mode. Highly recommended.

Posted in Programming | Tagged | 2 Comments

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