Another VimGolf in Emacs Challenge

Here’s another VimGolf in Emacs from a recent challenge on the VimGolf site. Your task is to replace the blanks between the letters with 4 blanks and to do it for each line. Here’s the starting file

a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z
a b c d e f g h i j k l m n o p q r s t u v w x y z

and the ending file

a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z
a    b    c    d    e    f    g    h    i    j    k    l    m    n    o    p    q    r    s    t    u    v    w    x    y    z

Disregarding the keystrokes necessary to save the buffer to a file, the best Vim solution is 13 keystrokes. I can do it in 7 with Emacs. Can you beat that? I’ll post my solution in the next day or two.

Posted in General | Tagged | 5 Comments

Exploratory Data Analysis with Unix

Seth Brown over at Dr. Bunsen has a great post on how the ordinary Unix coreutils can be used for exploratory data analysis. His first example

(head -5; tail -5) < data

to show the first and last 5 lines of a file is something that we all understand immediately but might not think of doing ourselves.

He moves on to showing how to change the shape of data using utilities like paste, and to enumerate data with wc and simple awk scripts. Then he has some examples that show how to massage data into useful forms for input to statistical analysis and plotting programs.

There are a lot of Unix utilities that many of us have forgotten or have only dim remembrances of. That’s too bad because as Brown demonstrates, they can be extraordinarily useful. As one of the commenters remarked, “…far more people need to get back to basics and learn coreutils.” I couldn’t agree more.

Posted in General | Tagged | Leave a comment

Is The TSA Finished?

I know, I know: I’m courting a comeuppance from Betteridge’s Law but this is too good to ignore. Christopher Elliot at Linked in has an interesting post in which he posits that the TSA, as we know it today, can’t continue to exist.

The central theme of the post is a hearing of the House Aviation subcommittee. A hearing which TSA head John Pistole refused to attend. The striking thing about the hearing is the hostility of the panel members to the TSA and the near universal consensus that the mission of the TSA needs to be radically revamped.

Anyone who knows anything about security realizes that what the TSA is currently engaged in is security theater. While providing no realistic protection from terrorists, the TSA is actually increasing our chances of being killed. I don’t know if Elliot is correct but I certainly hope so. The sooner the current TSA is eliminated the better off and safer we will all be. Take a look at Elliot’s post; it’s short and very interesting.

Posted in General | Tagged | Leave a comment

Let’s Play Ivmgolf

After my last VimGolf post I thought it would be fun to try another so I headed over to the VimGolf site to find a challenge. The first one I stumbled across was Let’s play some Imvgolf. The challenge is simple: starting with

Ivm is an awesome text editor based on
Iv, and is used to play a game called
Ivmgolf. A challenge, simple for many
Ivmgolfers, can still hide secrets.

transform it to

Vim is an awesome text editor based on
Vi, and is used to play a game called
Vimgolf. A challenge, simple for many
Vimgolfers, can still hide secrets.

in the smallest number of keystrokes possible.

My first thought was that it was too simple. Surely, it would hard to beat a simple query-replace: 【Meta+%ivReturnviReturn】 【!】 for a total of 8 keystrokes. Hard to see how you could do much better than that. Except that the winning VimGolf entries solved it in only 5 keystrokes1

Using Magnor Sveen’s awesome multiple-cursors package, which should and probably will be part of Emacs core, I was able to get that down to 6 keystrokes.

It’s easy to see what you need to do: switch the first two characters of each line and adjust the capitalization. I tried that using keyboard macros and even apply-macro-to-region-lines but I couldn’t do better than query-replace using core Emacs functionality. The problem is that any macro that requires typing in Vi has already used 4 keystrokes, and if you use a macro and something like 【Ctrl+t】 to switch characters you’ve used 3 keystrokes and still have to adjust the capitalization, get to the start of the next line, and run the macro on the rest of the lines. If you can do better than 8 keystrokes with stock Emacs, be sure to leave a comment.

Footnotes:

1 The VimGolf rules say you have to save the file too so that adds an extra 2 keystrokes in both Vim and Emacs but I’m ignoring them since they add nothing useful to the challenge. All scores in this post are without saving the file.

Posted in General | Tagged | 5 Comments

Autocompleting

Xah Lee has a nice post on the various methods of autocompleting in Emacs (search for 2012-12-01). Most Emacs users will be familiar with the majority of the material but it’s helpful to have it all written down in one place. For most of the methods he gives pointers to additional material that he’s written for that particular mode or package. Very helpful.

Of the minibuffer methods that he mentions, I use ido and smex and I’m experimenting with icomplete. For the general methods, I use hippie-expand, dabbrev-expand, and abbrev-mode. I couldn’t live without ido and smex and I use the others regularly. I find them all very handy so if you aren’t already using them you should give them a try.

I don’t use YASnippet but I’ve been meaning to install it. When guys like Lee and Magnar Sveen keep recommending it, that’s a pretty good indication that I’d find it useful. What do you think? If you have any strong feelings about the above packages or use something else that really works for you, leave a comment.

Update:

Lee has made the post a standalone page.

Posted in General | Tagged | 3 Comments

New Emacs Movie: Dired

Noufal Ibrahim has started “season two” of his Emacs Movies. This is the second section that will describe various Emacs modes and tools such as

  1. Dired
  2. Org-mode
  3. Eshell
  4. Diary
  5. Calc
  6. Ediff
  7. Gnus
  8. Vmail
  9. Erc
  10. BBDB
  11. Info

His latest movie is an excellent summary of Dired. He covers all the usual Dired tricks but includes a few that I didn’t know. For example, it’s possible to bring up a thumbnail of an image in Dired and then, if you like, open the image in another window The video is about 20 minutes long and well worth watching. Unless you’re already very familiar with Dired, you’re sure to learn something new. Definitely recommended.

Posted in General | Tagged | 1 Comment

More News From the Cursive Front

Yahoo News has an interesting article on the cursive wars. Should cursive handwriting be abandoned as an anachronism or should it be preserved as an important life skill? Regular Irreal readers already know where I stand on the matter but might want to see the arguments for the other side in Yahoo’s article.

Some schools are hanging onto cursive tenaciously, insisting that their students receive at least some instruction in it. All the usual reasons are given but there’s a new entrant in the article: cursive is necessary to teach fine motor skills. The same folks pushing that idea would doubtless become apoplectic if someone suggested that improving fine motor skills was a good reason to encourage video games.

By far the most interesting thing about the article was the comments. I read a couple of pages worth and didn’t see a single comment that wasn’t hostile to the idea of eliminating cursive. People feel extraordinarily threatened by the idea. I’ve suggested before that this has a lot to do with “I suffered through learning it, why shouldn’t they?” but no one admits to that. Instead they all give the usual silly arguments such as “this is dumbing down our students,” “if they don’t learn cursive they won’t be able to sign their names” and others that are just too embarrassing to repeat. Many are simply irrational and brimming with anger. If you’re interested and feel up to it, see the comments to Yahoo’s article; it has a good representation.

There’s another Yahoo article that explores these points a little further and discusses various home-based resources for parents who feel their children need instruction in cursive. It’s worth looking at these two articles if only to see what arguments can be brought to bear in favor of cursive.

Posted in General | 9 Comments

Icomplete Mode

Per Xah Lee (search for 2012-11-28), I’ve experimentally turned on icomplete-mode. I’m not sure how I like it so I haven’t included it in my init.el file yet.

According the internal documentation, icomplete-mode “implements a more fine-grained minibuffer completion feedback scheme.” You can toggle it with 【Meta+xicomplete-mode or turn it on/off unconditionally with a positive/non-positive prefix argument.

Lee says it’s part of Emacs 24.2 but the source file indicates it’s been around a lot longer. If you have an older version of Emacs and it works for you (or you get documentation for it with 【Ctrl+h ficomplete-mode) leave a comment so that others will know.

Posted in General | Tagged | 3 Comments

SBCL 1.1.2 Is Released

Christophe Rhodes is announcing that he has released Steel Banks Common Lisp 1.1.2. You can get the release at the SBCL Download Page. As always, installation is simple. I did my usual dance of

sh make.sh
cd test
sh run-tests.sh
cd ..
sudo sh install.sh

but binaries are available for Linux and Windows for those who don’t want to bother with compiling.

The Windows version features increased stability for threads and some other enhancements. You can see the complete list of changes on the NEWS page.

Posted in Programming | Tagged , | Leave a comment

C++ Craziness

If someone asked you to write a C++ program to output the squares of the numbers from 0 to 9, what would it look like? Vivek Haldar, whose work I’ve cited approvingly several times (1, 2, 3), has an answer. In fact, he has two answers. The point of his post was how the new C++11 makes better solutions possible.

But here’s the thing: the examples are ridiculous. Here’s what I’d do

#include <iostream>
using namespace std;
int main ()
{
  for ( int i = 0; i < 10; i++ )
    cout << " " << i * i;
  return 0;
}

Now look at Haldar’s solutions. To be fair, my code would look the same in old or new C++ so it doesn’t work well as an example of the new functionality that C++11 brings, which is what Haldar is trying to demonstrate. Still, examples like his could easily lead someone to conclude that C++ programmers are crazy. Ironically, Haldar notes that Python has a much more succinct solution based on list comprehensions and hopes that C++ will soon introduce list comprehensions too. But the Python example looks essentially like the code above except that it makes a list first. Why would you do that?

None of this is not to beat up on Haldar, who’s a smart guy and probably wouldn’t actually write code like his examples if he weren’t trying to make a point. It does illustrate a problem in the C++, and more generally the OOP, worlds though. Just because the language provides all those nice templates and object machinery doesn’t mean you should use them to solve simple problems where they aren’t needed. If you do, you end up with examples like the ones we lamented previously.

Posted in Programming | Tagged | Leave a comment