And The Winner Is…

password. SplashID has a list of 2011’s 25 most popular passwords as culled from the various exploits of LulzSec, Anonymous, and others. As expected, the runner up is 123456. Readers of this blog will find none of this surprising but it sure is depressing.

Follow the link and see for yourself. Sadly, I’m sure these people think they’re being clever in their choices. I suppose in a way it makes them low hanging fruit and therefore makes sensible folks marginally safer but that’s small comfort when you look at the list. It’s not as if this was some esoteric subject known only to experts. It doesn’t seem to matter how often the sermon is preached, people just aren’t going to be sensible about their password choices.

Posted in General | Tagged | Leave a comment

Another Emacs Cheat Sheet

Artur Hefczyc has an nice table of the Emacs keybindings. They are listed alphabetically by command name, not by action, so you need to know a good approximation to the name of the command you’re trying to run. It’s a nice table and worth bookmarking or even printing out if you’re inclined to use paper cheat sheets.

Of course, you can always get a complete list of the current keybindings for your Emacs with 【Ctrl+h b】 but I find it difficult to locate the command I’m looking for with it.

Posted in General | Tagged | 1 Comment

Text Replacement In Several Files With Emacs

Just a quickie. I was browsing around in Aaron Hawley’s Giant Emacs Reference Sheet when I came across this little ditty:

C-x d *.c RET Q int RET long    

It was described as “replace ‘long’ for ‘int’ in .c files.” I thought, “Boy, that’s really handy” and then I realized that it’s just

  1. Enter dired and list all the .c files
  2. Do a query replace substituting long for int

something that I’ve probably blogged about in the past.

Still, it does seem to gain power when you think of it as one command. And, if for only a moment, I thought I’d found something new and wonderful.

Posted in General | Tagged | 5 Comments

Administrivia

The scum spammers, who doubtless describe themselves as SEO consultants, have discovered a new way to get links into forum comments: trackbacks and pingbacks. Irreal does have the occasional legitimate trackback and I enjoy them as they give me a sense of who’s reading the blog and what they have to say about the topics we consider here. Lately, though, they’ve all been phony trackbacks designed to get Google to notice a link to some site or another that has nothing to do with Irreal or the things we talk about here.

Therefore, I’ve turned off trackbacks/pingbacks. Comments will remain as they were: unmoderated but requiring a CAPTCHA or registration.

Posted in Blogging | 1 Comment

Comment Boxes In Emacs

Here’s a neat little hack that can save a bit of time. Emacs has the comment-box command that will put a mode-specific comment box around a region. For example, suppose you have the Elisp

A function to do something very profound.
It is called from the top level.
(defun be-profound ()
...)

and that you select the first two lines and call comment-box. You get

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; A function to do something very profound. ;
; It is called from the top level.          ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun be-profound ()
...)

Similarly if you have some C code like

Here is the the main function
that does something or another

int main ( int argc, char **argv)

and select the first two lines and call comment-box you get

/**********************************/
/* Here is the the main function  */
/* that does something or another */
/**********************************/

int main ( int argc, char **argv)

Back when I was writing a lot of C code I used to put a comment box like that in front of every function. I did it by hand so it was sort of pain. I wish I’d had, or known about, something like comment-box to help me out (that was when I was using Vim).

Posted in Programming | Tagged | 3 Comments

It’s Time For Publishers To Get A Clue

Those of you who have been dropping by this blog for a while know that I’ve written several posts about the publishing industry and its consistent failure to accept that things are changing (see The Future Of Books, More Bad News For The Publishing Industry, and More Amazon Disruption). Now, Jon Evans over at Tech Crunch takes up the same theme with Dog Bites Man; Pope Condemns Violence; Publishing Still Doesn’t Get It.

Evans mostly discusses the publishers’ and Authors Guild’s reactions to Amazon’s introduction of the Kindle Owners’ Lending Library but also touches on the publishers’ treatment of ebooks in general. The picture he paints isn’t pretty. It’s a picture of ignoring what their customers want, of refusing to acknowledge that the future is coming, of lost opportunities, and, in general, of behaving stupidly.

He notes all the usual problems: failure to deliver a subscription model desired by their customers, inflated ebook prices, petty behavior when an author shows “disloyalty” by signing a deal with another publisher, and a general failure to deal with the reality of ebooks.

The failure to take ebooks seriously is, to my mind, one of their worst shortcomings. Just as Borders failed to take Internet sales seriously and paid the ultimate price, publishers treat ebooks as a slightly disreputable stepchild, not to be taken as seriously as “real” books; as a problem to be dealt with rather than an opportunity to be seized.

Case in point: the deplorable production values in ebooks. It’s hard to understand how they could do so poorly. The ebook process starts with the same files as a dead tree book but somehow comes out the other end with missing words and letters, poor spacing, fouled up typography, and inconsistent capitalization. Neal Stephenson’s Reamde was so poorly done that it was withdrawn from the Kindle store. Sadly, Stephenson’s book is not a fluke. Thomas Rhiel has a blog post that recounts other examples. (Be sure to follow the ebook typography is terrible link in Rhiel’s post for some graphic examples.)

Rhiel’s post makes a telling point about the publishers’ failure to leverage the opportunities afforded by the ebook format. Historically, publishers print photographs on glossy paper and bind them in the middle of the book because it’s too expensive to bind the individual glossy pages in the proper place. But there’s no excuse for doing the same thing in an ebook. The photo should appear in the logical place in the book or, as Rhiel says, at least at the end of the book in its own section instead of the middle of a chapter to which they bear no relationship.

Clearly, these books are not receiving proper editorial scrutiny. Meanwhile, the publishers are telling us that they have to charge high prices for ebooks because, after all, it’s not the printing and shipping that costs the money but the editorial effort. Please. Produce a competent product that shows some of that editorial effort and we’ll talk. In the mean time you’re just looking clueless and indifferent.

Publishers can continue to pretend that everything is the same as it’s always been, that customers have nowhere else to go, and that there’s no reason—no reason at all—to change their business model but the truth is that things are changing. Amazon is not just threatening to eat their lunch but to steal the crown jewels. Tired of dealing with publishers who don’t want to do anything new or different, they are now offering authors direct deals as I recounted in the More Bad News For The Publishing Industry post. Among the defectors, by the way, is Neal Stephenson. Perhaps he’ll finally get a clean ebook out of the deal.

Posted in General | Leave a comment

Highlighting Regexps, Phrases, And Lines In Emacs

I mostly use isearch-forward, 【Ctrl+s】, and isearch-backward, 【Ctrl+r】, to search for words or phrases in a buffer. Sometimes, though, it’s convenient to see all the matches at once. Emacs has a set of commands that make this easy.

The easiest to use is highlight-phrase, which is bound to the 【Meta+s h p】 sequence. It will ask you for a phrase and highlighting color and then highlight all the matching phrases in the buffer. The nice thing about highlight-phrase is that any whitespace is automatically converted to arbitrary whitespace and initial lower-case letters are made case insensitive so it’s pretty much a “do what I mean” command.

The next command, highlight-regexp, is a little more general. It’s bound to 【Meta+s h r】 and lets you highlight anything that matches an arbitrary regexp.

The command highlight-lines-matching-regexp is similar to highlight-regexp except that it highlights the entire line that contains the match to the regular expression. It is bound to 【Meta+s h l】.

Finally, you can un-highlight the matches with unhighlight-regexp, bound to 【Meta+s h u】.

Summary

Key Sequence Command
Meta+s h p highlight-phrase
Meta+s h r highlight-regexp
Meta+s h l highlight-lines-matching-regexp
Meta+s h u unhighlight-regexp

Update: let → set.

Posted in General | Tagged | 1 Comment

Property Lists In Emacs

Xah Lee has a nice post up with a function that fixes what he sees as some problems with the default Emacs case-changing commands. Apparently, our use cases are different because I’m not bothered by the default behavior. Still, the function is a nice one and you may find that it meets your needs.

One of the techniques that Lee uses is to maintain a bit of state in a property list. Property lists are a feature of many Lisps and although they aren’t used a lot, they are often just what you need. One way of thinking about property lists is that they are very much like association lists (alists) that are attached to a symbol. (You can have more general, free-standing property lists too but we won’t consider them here). They are a list of property-value pairs that can be set with the put command or read with the get command.

So what are property lists used for? One common use is to control disabled commands. For example, in my post on Using The Emacs save-restriction Special Form, I mentioned that narrow-to-region is disabled by default and that you should add

(put 'narrow-to-region 'disabled nil)

in your .emacs or init.el file to enable it. The narrow-to-region symbol has a set of properties, one of which is disabled. The result of the put is to set that property to nil. By default, the property is t. Before narrow-to-region is executed, Emacs checks its property list to see if the disabled property is t. If it is, Emacs tells you that the command is disabled and gives you some choices in how to proceed.

Another example, which I use a lot, is to control indentation. For example, I have a Scheme implementation of the Common Lisp dolist macro that we’ve discussed before. The problem is that Emacs doesn’t know how to indent the macro correctly because it’s not part of standard Scheme. Fortunately, I can tell Emacs what to do by adding the scheme-indent-function property and setting it to 1. I do that by adding

(put 'dotimes 'scheme-indent-function 1)

to my init.el file.

You might think that properties are restricted by Elisp to just those used by Emacs itself but that is not the case. You can attach any property you like to any symbol. That brings us to Lee’s function. Because he wants to be able to step through 3 possibilities (all lower, initial cap, all upper) he needs to remember what the last state was. He does that by adding a state property to his function, toggle-letter-case. Take a look at his post to see the details—the code is pretty easy to follow.

Summary

Command Action
(put 'symbol 'prop val) Set the prop property of symbol to val
(get 'symbol 'prop) Get the value of symbol‘s property prop
(symbol-plist 'symbol) Return the property list of symbol
Posted in Programming | Tagged | Leave a comment

Installing Emacs 24

As I mentioned in my Emacs 24 Features post, Bozhidar Batsov over at (think) has been using Emacs 24 with great success. He has a new post up that describes how to get Emacs 24 installed on OS X, Linux, and Windows.

For OS X, he recommends just getting the pretest from Emacs for OSX, but I like to compile it from sources. I tried that but had a problem with the libcurses-dev not being found. I haven’t had that problem before but this is the first time I’ve compiled Emacs since I installed Lion so I probably just need to download the sources and compile the library. Leave a comment if you’ve run into this problem and tell us what you did to resolve it.

In any event, after you’ve installed Emacs 24 you may want to look at Batsov’s Emacs Prelude. It’s “an advanced Emacs setup specifically for Emacs 24.” It works with OS X, Linux, and Windows.

Batsov notes that although Emacs 24 is not scheduled for release until Spring 2012, he has been using it for several months and found it to be rock solid. He concludes by saying that there really is no excuse not to switch to Emacs 24 now so if you’re inclined, see Batsov’s post that I linked above to get the details on how to get it installed.

Posted in General | Tagged | 2 Comments

Beautifying JSON In Emacs

I really like JSON. It’s the perfect mechanism for serializing data; much better, in my opinion, than the typical XML solution. That said, I don’t use it enough to justify installing one of the really nice packages that deal with it such as Steve Yegge’s js2-mode or Edward O’Connor’s json.el. Still, I thought it would be nice to have an Emacs utility that could transform JSON into a standard, readable format.

The other day I came across a post in Richard Ketteierij’s richardlog blog about pretty-printing JSON and XML on Mac OSX. His post had nothing to do with Emacs; it was merely a way of writing reformatted JSON to a file. It occurred to me that this was just what I needed for the occasional lightweight reformatting of JSON. It should work for any system with Python 2.6 or greater installed.

It turns out that the Python distribution comes with a json.tool module that does the work of reformating JSON. For example, here

{"father":{"name":"John Smith", "age":45, "employer":"YoYodyne, inc."},
"mother":{"name":"Wilma Smith", "age":42},
"children":[{"name":"William Smith", "age":15},
         {"name":"Sally Smith","age":17}]}

is some JSON that I used when I first wrote about JSON back in 2009 on my old blog. It’s easy to run this through json.tool by selecting the code and typing 【Ctrl+u Meta+|python -m json.tool. Doing that yields

{
    "children": [
        {
            "age": 15, 
            "name": "William Smith"
        }, 
        {
            "age": 17, 
            "name": "Sally Smith"
        }
    ], 
    "father": {
        "age": 45, 
        "employer": "YoYodyne, inc.", 
        "name": "John Smith"
    }, 
    "mother": {
        "age": 42, 
        "name": "Wilma Smith"
    }
}

which is more readable and standardized in the sense that the items are in alphabetical order. As I said, it’s a simple and lightweight solution but quite handy if you deal with JSON only occasionally. If you use JSON a lot you probably have one of the packages mentioned above installed already (or should have).

Update: an example of to get rid of redundant “example.”

Posted in General | Tagged | 5 Comments