Pausing Emacs Keyboard Macros

Seven or eight years ago when Tim Visher was still producing his VimGolf in Emacs videos, one of his favorite tricks was using the full power of Emacs keyboard macros. Most Emacs users know about keyboard macros and can manage straightforward applications of them to perform a repetitive task. Visher, though, was a master and knew how to use them interactively to accomplish amazing things.

One of his tricks was to place a prompt for a query in the middle of a macro that would allow the user to perform some special action specific to the current item the macro was on (see this episode for example). I learned those methods at the time but because I seldom have need to use them, I’ve mostly forgotten about them.

Happily, Marcin Borkowski (mbork) recently posted an update to his previous post on keyboard macros that I wrote about last week. In his new post, he talks about pausing a macro and also about adding a query prompt that allows you to enter a recursive edit and perform an action unique to the current item. It’s really great to be reminded of this because while I may not need it often, when I do it’s extraordinarily useful. Take a look at Borkowski’s post for details on how to add a query to a macro. As I say, you probably won’t need it too often but when you do, you’ll be glad you now how.

UPDATE [2019-07-10 Wed 13:43]: Added link to Borkowski’s post.

Posted in General | Tagged | Leave a comment

Files As Org Capture Templates

Josh Rollins has a very nice tip on a feature of Org-mode capture templates that I didn’t know about. It turns out that you can store a capture template in a file. It’s not immediately clear what that means exactly or why you’d want to do it in the first place.

The main use case appears to be a long and complicated template, possibly with formatting. In Rollins’ case, the template is a check list for setting up new computers (Rollins is an IT support technician). When a request is initiated for a new computer, he wants to capture the essential data and add the check list to his project file. I have a similar requirement that I handle by having a yasnippet expand to my desired body but that’s not as seamless as Rollins’ method.

What goes into the file is the string containing the text and substitution escape codes. That makes it easy to have a complicated body of data along with special formatting. In Rollins’ case, he wants the indentation of sublists to be correct, something he couldn’t figure out how to do with the usual method of specifying templates. The file mechanism is invoked by replacing the string containing the text and escape codes with the form

(file "file-containing-template")

where the "file-containing-template" contains the text that would normally be in the text string of the capture template. Take a look at Rollins’ post for more details. If you use the capture facility a lot, this tip will probably be useful to you.

Posted in General | Tagged , | Leave a comment

Ten Years

Ten years ago today, the first ever Irreal post appeared on Blogger. It’s amusing to read what I thought the blog was going to be about. To be sure, I do sometimes write about Lisp and Scheme—although not so much lately—but these days Irreal mostly covers Emacs, privacy, and the occasional technical subject that strikes my fancy.

After a couple of years, I moved Irreal from the Blogger platform to my own domain running WordPress on a rented virtual server. About 7 years ago, I started posting everyday. As I said at the time, that’s way harder than you’d think it would be but by now it’s become second nature. Since June 1st of 2012, I’ve posted everyday except for a very few occasions when I was sick, there were network issues, or a hurricane came calling.

Going forward, I don’t expect much to change. Doubtlessly, Irreal will continue to evolve reflecting my interests at the time but I don’t envision any sudden shifts in emphasis or content. I’ve been using Emacs for more than a decade and have learned that I still have a lot to learn so I’m pretty sure that Emacs coverage will continue at about the same level as it has now. Privacy violations by governments and corporations infuriate me as much as they ever have so expect coverage of that to continue as well.

I’ve become more interested in leveraging my digital lifestyle as a way of simplifying my life. My post on everyday carry reflects that and I expect I’ll be writing more about such things in the future. I’m far from mercurial but my interests do mutate so I’m sure I’ll be writing about entirely new things too.

I’m looking forward to Irreal’s second decade. I hope you are too.

Posted in General | Tagged | Leave a comment

VisiCalc Redux

A month ago, I wrote about Dan Bricklin’s TED talk on VisiCalc. Bricklin’s talk was in honor of the 40th anniversary of the modern spreadsheet. The spreadsheet idea was an old one but it was so labor intensive that it was used sparingly. Bricklin’s idea of implementing the spreadsheet on a low cost personal computer—the Apple II—changed everything. It’s hard to overstate how much VisiCalc, Lotus 123, and the others revolutionized business.

Happily, we don’t have to imagine. Steven Levy, famous for being a chronicler of the computer revolution has reprinted a 1984 article that explored the then new spreadsheet and how it had to a large extent turned businesses upside down. In typical Levy style, it’s a long and thorough article. It’s well worth reading whether or not you were there at the time.

David Cassel has a shorter article on the same subject. He also makes the point that VisiCalc was the first killer app. People were buying Apple IIs just so they could run VisiCalc. Steve Jobs credits VisiCalc with driving the success of the Apple II.

These days the original spreadsheets are all gone. Microsoft’s Excel and, to a lesser extent, Apple’s Numbers have almost all the mindshare. Still, it’s hard to imagine running any business (or even personal finances) without a spreadsheet. It’s interesting to see how it all started.

Posted in General | Tagged | Leave a comment

Internet Villains

This is hilarious. The UK government and a UK ISP trade group are wetting their pants because Google and Mozilla are planning to implement a more secure, privacy respecting DNS lookup in their browsers. They’ve even declared Google and Mozilla to be “Internet Villains” for having the temerity to respect the safety and privacy of their users. They give all sorts of specious reasons for their opposition to the change—including the usual shameless “protect the children” cant always favored by scoundrels trying to put something over on the rest of us—but it boils down to “we won’t be able to spy on you and control what you see anymore.”

Of course, even that’s not true. It probably is true that it will be slightly harder to filter out “undesirable” sites but at the end of the day, the final IP address must be visible to transport the traffic. Yes, sites deemed undesirable can change their IP addresses often in an effort to stay ahead of the blue noses but those addresses must be available to everyone to be useful so they can still be blocked.

I consider this change an unmitigated good thing and hope that Google and Mozilla will stand their ground but I’m not sanguine. The problem is that both organizations have a history of being hostile to those they consider guilty of BadThink and may come to agree with the censors.

I hope that doesn’t happen. It’s not, after all, up to the rest of us to make it easy for the GCHQ to spy on ordinary citizens just in case they may harbor impure thoughts of a social or political nature. Nor should our safety and privacy be degraded so ISPs can redirect bad DNS requests to their own page offering the erroneously requested domain for sale.

Posted in General | Tagged | Leave a comment

Making a Function a Command

Marcin Borkowski (mbork) has an interesting post on Emacs keyboard macros in the wild. He had a seemingly conventional repetitive editing task that he wanted to accomplish via Emacs keyboard macros but a few problems came up. It’s a nice example of solving small problems as they occur.

What really surprised me, though, was that Borkowski discovered a way of turning a function into a command without altering its source code. If you’re vague on the difference between a function and a command, it’s essentially that you can call a command with Meta+x <command-name> while a function can be called only from other Elisp code. The way to turn a function into a command is to add an interactive special form to the beginning of the function.

That means it’s easy to make an Emacs function into a command since we have access to the source code. But who wants to go mucking around with Emacs source code, especially if it’s a temporary change? It turns out that there’s an easier way. Although this is documented at the “interactive” link above, it came as a surprise to me. Indeed, the documentation notes dryly that “This feature is seldom used.”

Take a look at Borkowski’s post to see how it’s done. It’s dead simple and a nice technique to have in your Emacs toolbox even if you seldom use it.

Posted in General | Tagged | Leave a comment

Deciding What Functions To Do In Emacs

Extremeaxe5 has a question:

For me the answer is simple. If I can do it in Emacs, I do do it in Emacs. Actually, that’s not quite right. I suppose I could browse the Web from Emacs but that just doesn’t work well enough to make it worthwhile most of the time. Other than Web browsing I can’t think of anything that I could do in Emacs that I’m not doing in Emacs.

Mike Zamansky has his own answer: “If I can do it better in Emacs I use Emacs. Otherwise, I use Emacs.” Many other commenters agree.

The reasons for staying within Emacs as much as possible are well known and I’ve written about them before. The big ones for me are avoiding context switches and leveraging my Emacs muscle memory. Emacs über alles isn’t for everyone, of course, but has become a way of life for many of us. I’ve come to feel vaguely uncomfortable if I find myself entering text outside of Emacs.

Posted in General | Tagged | Leave a comment

Chrome Has Become Surveillanceware

Last year I wrote about Matthew Green’s post on why he was giving up the Chrome browser despite being a user for many years. The TL;DR was that Google’s decision to surreptitiously log the browser into Google when you used another Google app was the final straw for him. He said he could no longer trust Google to respect his privacy.

Of course, Green is a cryptographer who is knowledgeable about these matters and you might expect that he would be more sensitive to such things than a normal user. Now, though, The Washington Post has an article, Goodbye, Chrome: Google’s web browser has become spy software, that brings Green’s concerns to the rest of us.

Geoffrey Fowler writes that he monitored Chrome’s use of tracking cookies and discovered that after a week of browsing there were 11,189 requests for tracker cookies that Chrome would have passed on and installed on his machine. He recommends switching to Firefox (or Safari if you’re an Apple user). You’ll still get the same requests to set cookies, of course, since that’s controlled by the Web sites but Firefox and Safari are much more selective on which cookies they allow. Both browsers try to identify tracker cookies and block them.

You might think it doesn’t really matter because the worst that will happen is that you’ll get some annoying ads. But as Fowler says, it’s much worse than that. Even sites with no ads—such as Aetna insurance—also set tracker cookies. Google and the other data aggregators use those cookies to determine what sites you visit and to build up a profile of your habits, likes, and dislikes. Even worse, this data is being used not just to predict your behavior but to shape it as well. If you don’t mind being spied on and manipulated like that, then by all means continue to use Chrome. If you do mind, you should take Fowler’s advice and switch to Firefox or Safari. I mind so I’ve long since deleted Chrome from my machines and rely on Safari.

Posted in General | Tagged | Leave a comment

Mickey on Polymode

If you’ve been paying attention to the Emacs scene, you may have heard about Polymode, a package that lets you have two or more active major modes associated with a buffer. The first question to occur to many is, “Why would I want that?”

Not to worry, the incomparable Mickey is here to explain it all. There are, it turns out, legitimate use cases for multiple major modes in a single buffer. I’m an old-timey, backend sort of guy so I’ve been spared having to deal with those use cases but for those not so fortunate, Polymode can be a real win.

The basic idea is that you want to deal with two (or more) different languages in the same buffer—Mickey uses the example of Python and SQL. The indentation and font-locking are, of course, different for the two languages and you’d like Emacs to do the right thing automatically. That’s what Polymode does. It detects where one language leaves off and another starts and adjusts the operative major mode accordingly. A configuration that handles a given set of languages is called a “polymode.”

The bad news is that although there are, apparently, a few polymodes already written, by and large you’re going to have to write your own for most things. The good news is that writing a new polymode is pretty simple and generally takes just a few lines. Mickey’s post shows how it’s done by creating a Python/SQL polymode. Doubtlessly, more prebuilt polymodes will start to appear once the package starts getting traction.

If the need for this or the ideas behind it are unclear to you, take a look at Mickey’s post. As usual, he does an excellent job of explaining everything. As a bonus, if you’re not British, you may, like me, learn a new word: bijou. How can you lose?

Posted in General | Tagged | Leave a comment

Microsoft Ebooks: The Past Comes Due

It’s no longer news that Microsoft is closing down their ebook authentication server and those who have paid Microsoft for ebooks will shortly be unable to read them. It’s easy to say it’s their own fault and that’s not wrong but the majority of the blame lays with the book industry and their mule-like insistence on keeping their books locked up with DRM. They and their lackeys in congress enabled this situation with the execrable Digital Millennium Copyright Act. I’m sure the publishers considered all those contributions to congressional campaigns well spent but they will, I think, come to rue the day they made that bargain.

I say that for two reasons. First, Amazon leveraged their insistence on DRM to achieve domination of the ebook market—and probably the dead tree market as well—to the point where they can mandate terms to the publishers including what they pay for the books. It’s pretty much “sell your books with us or don’t sell them.” That’s all because DRM allows Amazon to lock readers into their ecosystem. If there were no DRM, the publishers could tell Amazon that if they didn’t want to buy books on their terms and prices, there are plenty of other outlets that would and users, being able to read books no matter where they bought them, wouldn’t care who sold the books to them.

Secondly, my sense is that the public’s patience is wearing thin. If I were a Microsoft ebook reader and lost my books, I wouldn’t have the slightest compunction about procuring a pirated copy to replace the copy I had already paid for. Once I did that, I would probably avoid future problems by doing away with official copies altogether. At the very least, I wouldn’t feel bad at all about procuring the easily available software that breaks the DRM to make sure these vultures could no longer steal my books.

How long will it be before people who haven’t lost their books adopt the same attitudes? Once the publishing industry comes to be perceived as thieves with no concern for their readers, those readers will no longer have a concern for them. Anything that’s left after Amazon gets done with them will have become worthless.

Posted in General | Tagged | Leave a comment