Calling External Programs

One of the rules specific to EmacsGolf, as opposed to VimGolf, is that you’re allowed to call external programs to operate on a region of the buffer using something like 【Ctrl+u Meta+|】. You can do the same thing from an Elisp program, of course, and Xah Lee has a useful post showing how to call external programs.

This functionality is more flexible than many beginners realize. You can call shell scripts, a scripting language such as Perl or Python, or a compiled program such as sort—anything that reads from stdin and writes to stdout. There nothing hard about doing any of this, of course, but you do need to know the proper incantation. See Lee’s post for the details. Also take a look at shell-command. It can be useful when you want to run an external program and optionally capture its output to a buffer—see this post for an example of its use.

Posted in Programming | Tagged | Leave a comment

Is Emacs an IDE?

Is Emacs an IDE? Here’s one answer. Here’s another: who knows, who cares? You might as well ask if Emacs is a fingdop. Emacs is what it is regardless of whether or not we call it an IDE (or fingdop, for that matter). It’s hard to see how a decisive answer to the question would make the slightest bit of difference in anyone’s life. I don’t understand why people keep obsessing about this.

Here’s what Emacs is: an editor that provides a user programmable editing environment unmatched by any other editing tool. Sometimes it looks like an IDE, sometimes it looks like an operating system, sometimes it just looks like an editor. If you simply must feel like you’re using an IDE, fire up Eclipse; then there’ll be no doubt. Just don’t blame me if you still aren’t happy.

Posted in General | Tagged | 2 Comments

EmacsGolf Challenge 2

Xah Lee sent me another suggestion for an EmacsGolf challenge. While in a whimsical mood, Lee decided to write some Elisp to convert Latin text to Fraktur (Gothic font). That’s an interesting Elisp challenge in its own right but Lee decided to use a simple table lookup and to provide the facility to go back from Fraktur to Latin. His table, as you can see at the link, is a vector of vectors and a bit of a pain to construct. Having built the first table, Lee wants to make the second as easily as possible. Given the starting table

(setq latin-to-gothic [ ["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" "𝔷"]])

we want to make a second table to map Fraktur to Latin.

(setq latin-to-gothic [ ["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" "𝔷"] ])

(setq gothic-to-latin [ ["𝔄" "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"] ])

Lee says he did this with a simple replace-regexp. Can you do better? Since this is EmacsGolf, you can use anything in stock Emacs, ELPA, or an external tool called from Emacs.

Posted in General | Tagged , | 14 Comments

SBCL 1.1.4

Somehow I missed the fact that SBCL 1.1.4 was released at the end of January. I just compiled and installed it and as usual everything is fine. The new release is mainly bug fixes and an optimization to the LOOP macro.

I love SBCL. It’s a world-class Lisp system that compiles to native code. If you’d like to get started with Lisp, I can’t recommend SBCL and Emacs/SLIME enough. Together they make an outstanding development system.

Posted in Programming | Tagged , | Leave a comment

Password Horror

This isn’t the usual post about some nincompoop making yet another foolish security mistake. It’s about a guy who does (almost) everything right and almost loses it all. Over at the White Hat Security Blog, Jeremiah Grossman tells a chilling tale about the day he forgot a password.

Grossman works in security and deals with a lot of sensitive material, much of which he keeps on his MacBook Pro. As a result, he’s extremely paranoid about his data protection protocols. His protocol involves two layers. First, his entire hard drive is encrypted with FileVault, the OS X full disk encryption utility that provides 128 bit AES encryption. This is already more security than most users have but he has a second layer that creates encrypted disk images (another OS X feature) each of which is encrypted with 256 bit AES. Thus, even if an attacker is able to breach the full disk encryption, there are still encrypted disk images that contain especially sensitive information. The images are mounted while needed and then unmounted so that their data is rarely available in plane text. Grossman also changes all his passwords on a regular basis. All those passwords are kept in one of the disk images and are protected by a master password.

This is doing security right. The data is always secure because of the full disk encryption and especially sensitive data is hidden away in virtual disks images that look like normal files and are easy for an attacker (or government agent, for that matter) to overlook. There’s only one thing missing: a backup for the master password. Some people will tell you to never write your password down. Grossman’s story is about what happens when you take that advice and then forget your password.

Follow the link for how he recovered and how hard it was. He only succeeded because he remembered most of the password. His story is interesting and enlightening but the post is valuable for another reason: it lays out a way to secure your data against most attackers (those that don’t come with 3 letter initials or a $5 wrench). If you’ve wondered how to secure your laptop against loss or other breach, this is a post you need to read. If you have a Mac and want to know how to set up encrypted virtual disks, Scott Jordan has a post that gives you the full explanation. If you’re working on another platform (or want another option on the OS X) take a look at TrueCrypt. It’s portable and can do everything described here.

Finally, I should mention that Jordan’s post on setting up virtual disk images shows you how to use it with Dropbox in a transparent and flexible way. If you use Dropbox and store sensitive information you need this because, as I’ve written many many times, if you store sensitive information in the cloud you better be encrypting it.

Posted in General | Tagged | Leave a comment

Elisp

No wonder it’s so hard to learn.

Posted in General | Tagged , , | Leave a comment

Remarks on EmacsGolf Challenge 1

Apparently I was a bit sloppy with my wording because everyone missed the fact that there was a second part to this challenge. Every line that started with an “open figure” was supposed to be deleted. That was just a matter of deleting every other line and is easily done with a macro in 5 keystrokes.

My original solution was

F3 start macro
Ctrl+f move to “puthash”
Meta+Shift+f select “puthash”
xmsi-add-cycle replace
Ctrl+f move after space
[
Ctrl+7 Ctrl+f move after strings
]
Meta+d Meta+d delete “xmsi-abrvs”
Ctrl+n move to next line
Ctrl+Shift+Delete delete entire line
Meta+0 F4 end macro and execute

That’s 28 keystrokes (not 29; I think I shaved off another by combining the end macro and execute). Notice that deleting the extra lines takes only two additional keystrokes. If you don’t worry about deleting the lines, you can do a bit better with multiple-cursors but then you have to use a macro to get rid of those lines. At least I couldn’t figure out a way to do it from within multiple-cursors.

Magnar Sveen had a nice trick to shave off two more keystrokes by using hippie-expand. I tried to integrate that into my solution but after the first time it picked up xmsi-add-cycle instead of xmsi-abrvs which resulted in cascading -adds on subsequent lines. Magnar uses a custom function that looks for the nearest match so his hippie-expand trick might have worked with a macro for him.

Fuco had a nice approach using his smartparens package. If anyone else has some good tricks it’s not too late to leave a comment.

If you want to contribute a challenge (please do!) you can mail it to challenges at the domain of this blog.

Posted in General | Tagged , | 5 Comments

Emacs Batch Text Processing

Xah Lee has a page up on batch text processing with Emacs. The page is a recapitulation of several tips that Lee has published before. These tips were very helpful to me when I was trying to learn the Elisp environment. Anyone with some Common Lisp or Scheme experience will have no problem with the Elisp language; it’s the library of Elisp functions specific to Emacs that will be unfamiliar. Lee’s tips helped me understand and learn the Elisp idioms.

If you are trying the learn Elisp, it’s worthwhile taking a look at this page and some of the other in Lee’s Elisp Tutorial.

Posted in General | Tagged , | Leave a comment

Replace Emacs?

Lord I get tired of reading this sort of thing. The tl;dr is that:

  1. N00bs don’t like Emacs because it’s not like Notepad and thus has a steep learning curve.
  2. Most Lispers use Emacs.
  3. Because of 1. and 2. n00bs won’t learn Lisp
  4. Therefore, we should stop using Emacs and replace it with something that won’t cause n00bs to whine.

I don’t know about you but this makes me want to slap those n00bs and suggest they grow up. Even if we stipulate that I’m crotchety and intolerant the post is still wrong on its own terms.

The fact is there are already plenty of alternatives to Emacs for Lisp. Many Lispers (Paul Graham comes to mind) use Vim. Oops. That’s not Notepad either. How about the LispWorks IDE? Edi Weitz, a world class Lisper, uses it. Want open source? How about MCLIDE or Clozure CL IDE for OS X? What’s that? You use Windows? How about LispIDE? It supports a large number of Lisp implementations. With the exception of the LispWorks IDE these all come with source code so you can fix any deviations from the Notepad key sequences.

And at the risk of becoming a poster boy for what’s wrong with the Lisp Community, I have to ask if we really want to recruit prospective Lispers who are too lazy to learn Emacs. Because if we do, I promise you that the next thing we’ll hear is whining about all those parentheses and an endless onslaught of proposals to use Python-like indentation instead.

Posted in General | Tagged , , | 1 Comment

More Multiple-Cursors Functionality

On his Emacs Rocks twitter feed, Magnor Sveen announced some useful additions to his multiple-cursors package. If you active regions with multiple-cursors you can now perform the following operations on them

  1. Reverse the lines in the regions
  2. Sort the regions
  3. Insert line numbers

He maps these to

Ctrl+~ Reverse regions
Meta+~ Sort regions
Hyper+~ Insert numbers

These additions bring to multiple-cursors functionality that exists in other Emacs packages such as CUA-rectangle-mode and thus makes it even more of a go to package for efficient text manipulation.

I’m still experimenting with it but so far I really like it. If you’re using the multiple-cursors package (and if you aren’t you really should be) you’ll get the new functions the next time you update but you’ll need to set key sequences for them. I like the ones that Sveen is using but, of course, you can choose your own.

Posted in General | Tagged | Leave a comment