An Easy VimGolf in Emacs Challenge

Here’s an interesting VimGolf challenge. As they say in the challenge, it’s a simple problem but they’re looking for interesting solutions. The challenge is to turn this

app.config['CHALLENGE_FOLDER'] = SOLUTIONS_FOLDER
app.config['SOLUTIONS_FOLDER'] = CHALLENGE_FOLDER

into this

app.config['CHALLENGE_FOLDER'] = CHALLENGE_FOLDER
app.config['SOLUTIONS_FOLDER'] = SOLUTIONS_FOLDER

The obvious solution that any Emacs user would think of does the job in 81 keystrokes.

Ctrl+s = cursor to =
Ctrl+k kill after =
Ctrl+n down one line
Ctrl+y insert ␠SOLUTION_FOLDER
Ctrl+k kill rest of line
Ctrl+p up one line
Ctrl+y insert ␠CHALLENGE_FOLDER

The best Vim solutions also do it in 8.

What I really want to do is something along the lines of

Ctrl+s = Ctrl+s Mark rectangle
Ctrl+x r k Kill rectangle
Ctrl+x Ctrl+t Swap lines
Ctrl+< Beginning of buffer
Ctrl+x r y Yank rectangle

that’s 12 keystrokes, 50% more than the obvious solution. If I use CUA Selection Mode (as I wrote about previously) I can do it in 9 with essentially the same method as above. Is there a clever way of doing this or is the obvious solution with 8 keystrokes the best we can do? If you can beat 8 keystrokes—especially if it’s something clever—be sure to leave a comment.

Update: Fuco does it in 6.

Update 2: Fuco shaves off another keystroke to a total of 5. Definitely a heavy weight contender.

Footnotes:

1 Using our usual rules of changing the text but not saving the buffer.

Posted in General | Tagged | 8 Comments

Cheswick on Passwords

Over at acmqueue William Cheswich has an interesting article on Rethinking Passwords. After listing the usual litany of problems with passwords as a security measure, Cheswick traces the historical roots of the problem. He says that we are stilling using recommendations laid down in the “Green Book” from 1985. The Green Book—formally Password Management Guideline (Technical Report CSC-STD-002-85)—was one of a series of government publications at the time. The recommendations made a lot of sense at the time and some of them are still applicable today but they were promulgated at a time when the estimated rate of trying passwords was 8.5 per minute. Cheswich says that in many respects we have failed to move on.

He has some recommendations but they are pretty much the usual fare. They all make sense but suffer from the facts that

  1. We can’t get the sites to implement reasonable password policies and even if we could,
  2. We can’t get users to give up using “password” as their password on every site they visit.

Still, Cheswich has some interesting ideas and the article is worth taking a look at.

Posted in General | Tagged | Leave a comment

Killing Sentences

Recently I’ve had several occasions where I wanted to kill to the beginning of the current sentence. No problem, I thought, I’ll just write a quick bit of Elisp like

(push-mark nil nil t)
(backward-sentence)
(kill-region)

and bind it to some convenient key. After a little investigation I discovered that Emacs already provided backward-kill-sentence and that it was bound to【Ctrl+x Delete】 so there was nothing to do—the functionality was already there.

That got me thinking about killing to the end of the current sentence. To do that I’ve just always used 【Meta+z .】 but it turns out that Emacs also has a kill-sentence to do the job. It’s bound to 【Meta+k】, which makes sense since you use 【Meta+a】 and 【Meta+e】 to move to the beginning and end of a sentence.

Emacs really is the journey that never ends. There’s always something else to learn.

Posted in General | Tagged | 2 Comments

Seriously?

Surely this is a joke. Either that or someone has way too much time on their hands. And what about the people signing it?

Posted in General | Tagged | 2 Comments

SBCL 1.1.3

The fine folks at SBCL.org have released version 1.1.3 of their Common Lisp system. One of the contributed packages (SB-SPROF) failed a test on my MacBook Pro but worked fine on my iMac. It looks like a VM problem when it ran short of memory, which would make sense since the iMac has twice as much memory as the MacBook.

In any event, it seems to be working fine on both systems. If you’re running Linux on an AMD64 or 64 bit X86 they have a pre-built binary for you to download. Otherwise, you’ll have to build it yourself. That couldn’t be easier. Assuming you have an earlier SBCL compiler it’s just

tar -xvjf sbcl-1.1.3-source.tar.bz2
cd sbcl-1.1.3
sh make.sh
sudo sh install.sh

If you have some other Lisp compiler, the build process is essentially the same but with a different build script (see the SBCL Getting Started page).

If you’re looking to get started with Lisp, the SBCL package is an excellent choice. I’ve used SBCL on OS X, Linux, and FreeBSD and have always been happy with it.

Posted in Programming | Tagged , | Leave a comment

Haldar On Editors

Vivek Haldar published a list of his most popular posts of 2012 and one that I particularly liked was My Setup. In that post, I found this quote about editors exactly right.

Editors

This is where the religious wars usually start. And rightfully so. If,
like me, your digital life mostly revolves around text, then you need
to have a religious fervor for your text editor. When I meet a geek
who does not feel strongly about their choice of text editor (or
worse, uses notepad or gedit), all my “fake geek” alarms go off. As
far as software goes, this is the centerpiece of the entire set up.

You know what’s coming–Emacs and vi–those are the only serious
contenders. I have some measure of objectivity here, because I have
used both for a number of years, and feel comfortable with either. In
the end, I fell towards the Emacs camp. What finally tipped me over
was the customizability. People keep talking about the look and the
key bindings and how many keystrokes it takes to do something. But all
that is not important. What is important is whether you can make this
editor your own. In the final analysis, Emacs is not really a text
editor, but a platform on which to build your workflows. It just
happens to be really good at text.

But–I’m not advocating a particular editor here. It really doesn’t
matter which one you end up with. What does matter though is that you
are a power user of it. It should feel like second nature to you. You
should have no trouble making it do your bidding. It should make you
feel powerful and light and frictionless. When people look over your
shoulder at you going about your work with it, it should look like an
incomprehensible buzz to them.

His experience pretty much parallels mine except that I switched from Vim to Emacs because I started programming in Lisp. Once I made the switch, though, I found the customizability to be a huge win. In any event, I agree with everything he says in the above quote.

A couple months ago I wrote about another of Haldar’s posts on editing, New frontiers in text editing, which is also interesting. If you’re a What the .emacs.d!? fan, you’ll recognize the beginning and ending quotes from that post. Haldar is generally interesting so you might want to subscribe. I do.

Posted in General | Tagged | Leave a comment

Moving Between Emacs Windows

As I mentioned in my winner-mode post, I recently configured Emacs to start with a frame-width of 162 columns. I’ve also added a call to split-window-right in my init.el to get the two columns of windows that I prefer. This introduces the problem of how to navigate between windows easily. If there’s only two windows, the usual 【Ctrl+x o】 works nicely but it quickly becomes cumbersome when there are 3 or more windows in the selected frame.

It turns out that there is a really nice solution to this although it’s a bit hard to find. If you add

(windmove-default-keybindings)

to your .emacs or init.el file, you can move between windows with the 【Shift+】/ 【Shift+】/ 【Shift+】 / 【Shift+】 key sequences. You can change the modifier by specifying a different one as the argument to windmove-default-keybindings.

If, like me, you’re a heavy org-mode user, you’ll find that these key bindings won’t work in org-mode buffers because org-mode takes them over. Happily you can solve this by adding the line

(setq org-replace-disputed-keys t)

to your .emacs or init.el. This will cause org-mode to replace the shift-arrow keys with others for its operations. You can also tell org-mode to replace the windmove keys only when the point is not at a place when org-mode would want to use them as explained in the Org Mode Manual.

All this may not sound like much but they are a huge win for me. I can have several windows open in a frame and still move among them easily. Another demonstration of the power and configurability of Emacs.

Update: windmove-default-bindingswindmove-default-keybindings

Posted in General | Tagged | 11 Comments

CUA Selection Mode

Many Emacs users like CUA mode. That makes a certain amount of sense because then copy/cut/paste work in Emacs the same way it does in almost every other application. I, however, am in the camp of the traditionalists and prefer the default Emacs way. I never get confused when I’m cutting and pasting in other applications and I spend most of my time in Emacs anyway. Not everyone agrees. Xah Lee, for example, is adamant about modernizing the Emacs interface and he always mentions turning on CUA mode first when he writes about it.

That said, one thing I do like about CUA mode is its handling of rectangles. It’s far superior to the default behavior. It’s not better enough to make me turn on CUA mode but it turns out that you can get the rectangle features without the 【Ctrl+x】/ 【Ctrl+c】/ 【Ctrl+v】/ 【Ctrl+z】 bindings. To do that just add

(cua-selection-mode 1)

to your .emacs or init.el file. Nirvana: superior rectangle handling but with the standard kill/copy/yank/undo interface.

Once you’ve enabled the mode, you set a rectangle by typing【Ctrl+Return】 and using the normal【Ctrl】 movement keys. Most of the【Meta】 movement keys are remapped to perform the various rectangle functions (you can see what they are with 【Ctrl+?】). You can cancel the rectangle with another【Ctrl+Return】. One of the nice things about this interface is that you see the actual rectangle instead of a virtual rectangle like you do with the standard interface.

You can kill and yank the rectangle with 【Ctrl+w】 and 【Ctrl+y】 as usual. In general, this interface is easier to use and requires fewer keystrokes to perform a given task. As the documentation says, the only new keystroke you need to learn is 【Ctrl+Return】.

Posted in General | Tagged | 1 Comment

Doing the Right Thing

After a year in which we’ve seen Big Media ride roughshod over their customers and do everything they could to rein in, if not destroy, the Internet, I have a ray of sunshine for you. Hollywood and the rest of big media is busy trying to strong arm Australia’s ISPs to spy on their customers so they can identify “pirates.” One ISP, iiNet, has had enough and told the Hollywood thugs to sod off.

TorrentFreak is reporting that iiNet has walked out of talks with Hollywood aimed at reaching an agreement over monitoring users for infringing activity. They make some good points

  • iiNet is not the Internet Police. It’s not appropriate for them to monitor their customers.
  • Hollywood wants the ISPs to collect and store data for Hollywood’s use but at their own expense. iiNet says this is not their responsibility.
  • ISPs have no legal or moral obligation to monitor their customers
  • (most importantly) Piracy is a problem of Hollywood’s own making. They refuse to make their content available in a timely manner at a reasonable cost to Australian citizens.

iiNets’s Chief Regulatory Officer Steve Dalby says that iiNet is happy to work with the rights holders but that they have to fix their broken business models first.

It’s great to see an ISP stand up for their customers and refuse to become spies for Hollywood. If only other ISPs would do the same.

Posted in General | Leave a comment

Winner Mode

In my Two From Phil post I mentioned that Phil had urged me to try winner-mode and that I was going to give it a try. For those who came in late, winner-mode captures the current window configuration and allows you to restore it after it gets changed by some Emacs action.

I was a little skeptical but I enabled winner-mode and 10 minutes later I was hopelessly addicted. This all comes at a good time because I have lately been setting Emacs to be 162 characters wide so that I can have two columns of “standard sized” windows1. That set up makes it really easy to mess up your window configuration. For example, if you bring up a help screen, the focus remains in the original window as usual but now it’s hard to get rid of the *Help* window. If you type 【Ctrl+x 1】 you blow away all your other windows. You can switch into the *Help* window and type 【q】 but that’s a pain. With winner-mode you simply restore the previous window configuration and you’re back to where you were before invoking help.

If you aren’t currently using winner-mode, do yourself a favor and give it a spin. It’s built-in functionality so all you have to do to try it is type 【Meta+xwinner-mode and you’re all set. Now 【Ctrl+c 】 will restore the previous window configuration and 【Ctrl+c 】 will redo the configuration you just destroyed.

Try it like this for a bit and see if you aren’t addicted too. If you are, just add

(winner-mode 1)

to your .emacs or init.el file and it will always be their for you. If you don’t like it, just turn it off with 【Meta+-1 Meta+xwinner-mode. I had intended to try it for a week or so to see how I liked it but, as I say, I enabled it permanently almost immediately. Really, you should try it out.

Footnotes:

1 I know, I know but I’m an old-timey guy and can’t get over the notion that the proper size for a (source code) screen is 80 characters. It makes no sense, I admit, but there it is.

Posted in General | Tagged | 1 Comment