Red Meat Friday: The Law of Unintended Consequences

When I added this item to my blog queue, I marked it as a Red Meat Friday post but now that I’m actually writing it, I’m having second thoughts. That’s because there’s nothing really controversial here. Everyone agrees—or should agree—with the conclusion: Before embarking on an endeavor, you should ask yourself, “What could go wrong?”

That’s because of the law of unintended consequences. Even though your intentions are pure and good, there’s always the possibility that something could go wrong and it pays to consider what that something might be.

Here’s an amusing example. Amusing at least if you aren’t Australian:

What could go wrong? We’ll import a couple dozen rabbits and have a nice hunting excursion. Billions of bunnies later, they’re asking, “Who could have imagined?” Well, anyone who knows anything about rabbits or the Fibonacci Sequence could easily have imagined what could go wrong if only they’d stopped to ask the question.

Here in the United States, we have the examples of Kudzu and opossums as rat control among many others. And, of course, the French had their infamous wealth tax. At no point did anyone stop to ask, “What could go wrong?” The answers, in retrospect, are all too obvious.

Posted in General | Tagged | Leave a comment

Org Footnote Assistant

Andrea Lazzarini has an interesting, small package to help with footnote creation and editing in Org buffers. The package offers some amenities such as easily moving between footnotes but, to me, the major win is displaying or editing a footnote in a cloned indirect window similar to the way editing a code block works after invoking org-edit-special to call org-edit-src-code.

That doesn’t matter too much for short texts such as a blog post but for longer-form texts where you can’t see the whole buffer, it makes it easier to create and edit footnotes because you can see the context of the footnote. If you’ve edited the contents of a code block using this paradigm, you know how powerful and convenient it is.

My only complaint is that the package doesn’t define or override keybindings to find or edit a footnote. That’s easy enough to do yourself, of course, but I’m a bit surprised it isn’t already there.

As far as I can tell, org-footnote-assistant is not in MELPA and Lazzarini doesn’t mention any plans one way or the other. Still, it’s a single file so it would be easy to install it manually. The project is less than a week old so I’m sure issues with an ELPA repository and keybindings will be addressed as the project matures.

Posted in General | Tagged , | Leave a comment

A Slight Isearch Improvement

Today’s post is a quick and simple tip from Zachary Kanfer on improving isearch. He likes the way isearch finds its results incrementally but is unhappy with the lack of context concerning the number of results found at each step.

It turns out that it’s easy to fix this. There is a configuration item, isearch-lazy-count, that when set to t will cause the count of prospective matches to be displayed in the minibuffer. There are a couple more configuration items that control the placement and format of the count. See Kanfer’s post for the details.

An alternative, that I use, is swiper-isearch. It also provides a count and displays the line containing each match in the minibuffer. I like it better and remapped Ctrl+s to it instead of isearch. Nonetheless, I have Super+s mapped to isearch so I can use it when I like. It’s worthwhile adding the prospective match count to isearch and it’s easy to do so I will probably add it to my configuration.

Posted in General | Tagged | Leave a comment

Devil Mode

Lots of people recommend Evil mode or switching to a Dvorak keyboard because it allows for more efficient editing. Evil mode is probably more efficient and, more importantly, helps with RSI problems. As a long term Vi/Vim user, those bindings were burned into my muscle memory and when I switched to Emacs and decided to use the vanilla keybindings, it was hard to give them up. Still, the default Emacs binding are also pretty efficient and the ability to easily implement my own editing commands more than makes for the loss of composability. The bottom line is that I’m pretty much agnostic concerning Evil mode.

Then there’s Dvorak and similar keyboard layouts. After suffering the pain of learning to touch type with QWERTY, I have no desire to start again for a possible gain of a few words a minute. I’m pretty efficient with QWERTY and if I needed to up my speed, there are plenty of videos and tutorials to help with that. The bottom line is that I’m not going to adopt some new keyboard layout and the associated pain for a small, putative increase in typing speed.

That brings us to Devil Mode. The idea is to get rid of the modifier keys while avoiding modal editing. To do that, the comma key is used instead of the Ctrl key so that you would open a file with , x , f. There are, of course, ways of dealing with the Meta modifier as well.

Your first question is, undoubtedly, how do you type a comma? The common cases of a comma followed by a Space or Return work normally but you can use , , for the edge cases. Follow the link for all the details.

If you really really want to eliminate the modifier keys without embracing modal editing, Devil Mode may be worth checking out. For me, it seems more like moving to Dvorak: whatever gain you might get isn’t worth the pain.

Posted in General | Tagged | Leave a comment

The Second Emacs 29.1 Pretest

Eli Zaretskii writes to say that the second pretest of Emacs 29.1 is available for testing. If you don’t mind living a bit on the edge, Zaretskii would be grateful for your testing and letting the developers know of any problems you find.

As always, thanks to Eli and the other developers for their hard work in readying this latest release for our use. They are truly heroes and we owe them all our gratitude and, should the opportunity arise, a beer.

Posted in General | Tagged | Leave a comment

Adding C-DEL To The macOS Keybindings

One of the little known but great features of macOS is their support of Emacs keybindings. Although most people don’t know it, this support comes in two parts. The first is that some of the common Emacs bindings such as Ctrl+a, Meta+b, and similar motion commands are defined by default and work in all macOS apps.

Less well known is that macOS allows you to install your own bindings for all their editing commands. In particular, you can install many of the common Emacs editing commands so that you can leverage your Emacs muscle memory with all the apps on your Mac.

I write about this periodically—last time here—when I see an Emacs user discover macOS’s rudimentary support for Emacs motion commands. But this post is not one of my periodic reminders. Rather, it about a missing binding and how easy it is to edit the extended bindings.

For as long as I can remember, I have used both Ctrl+Delete and Meta+Delete to delete the previous word in the manner recommended by Steve Yegge. Most of the time, it’s more convenient to use Ctrl+Delete for this but, sadly, that’s not supported by the DefaultKeyBinding.dict that I recommended.

Happily, it’s easy to add the desired binding. Here’s the new entry:

"^\U007F"   = "deleteWordBackward:";            /* C-DEL        Delete word backward */

Just add it to DefaultKeyBinding.dict and restart macOS to have it take effect. Pay particular attention to the punctuation after deleteWordBackward. It’s fussy and easy to get wrong.

This is a small thing and maybe nobody but me cares but it has made my life a little bit easier. As usual with these things, I wonder why it took me so long.

Posted in General | Tagged , | Leave a comment

Why Blog?

Since you’re reading this, you know that I blog. I blog a lot: everyday for several years now. You might wonder why. Anyone who’s tried it knows that blogging is hard and involves a lot of work. Irreal isn’t monetized but even if it were, it’s unlikely that it would pay me more than a nickel and hour. So why do it?

Every blogger, I’m sure, has their own reasons. Danny Guo certainly does and he’s chosen to share his. It’s an interesting read and if you’re looking for reasons to get started blogging, you may find his post useful.

Writing is a skill and like any other skill the only way to get good at it is to practice. Blogging is ideal for this. Blogging is hardly ever long-form writing so writing posts is a good way to practice in bite-sized chunks. A side benefit of writing is that it’s a necessary component to being a good thinker and writing, as Paul Graham says, is a precursor to thinking. Guo agrees with this and also notes that writing helps him clarify his thinking.

He gives several other reasons to blog including

  • Sharing knowledge
  • Learning things
  • Learning how he’s wrong

and many others.

He also gives some minimal advice on how to get started and mentions some of the various blogging platforms. Unlike Irreal, he doesn’t publish everyday demonstrating the commitment can be as large or as small as you like. If you’re interested in blogging the important thing is to get started. Irreal’s first year or so had only a few (sometimes no) posts per month. Guo says he works on some posts for a year or more.

My advice is to try it. You might find you like it.

Posted in Blogging | Leave a comment

Generating Documents Directly From Elisp

I’ve had this in my blog queue since April but it’s too good to let it fall into the bit bucket. Álvaro Ramírez has a problem with his chatgpt-shell package. He has some documentation in the form of tables, which are easy enough to generate but the package is still under development and the documentation is always changing.

Ramírez realized that Emacs is the self-documenting editor so it should be possible to generate the documentation directly from the Elisp. That way, every time he updates the code, the documentation can be automatically regenerated. He had no idea how to do that but the nice thing about Emacs is that there are no secrets. He checked how the apropos commands gathered this information.

It turned out not to be too hard. The secret is to use the mapatoms command to cycle through the obarray that contains all the symbols in the current Emacs instance. Then it’s just a matter of checking if the symbol is for chatgpt-shell and is a custom variable. Grabbing the documentation for functions is similar. You can check out the code for both in Ramírez’s post.

There’s nothing specific to chatgpt-shell in any of this. You can use the same code, mutatis mutandis, for any package so it’s a worthwhile technique to know. If you’re maintaining a package and have even minimal documentation, you should definitely take a look at Ramírez’s post.

UPDATE [2023-05-12 Fri]: Just noticed that I forgot the link to Ramírez’s post. Fixed.

Posted in Programming | Tagged , | Leave a comment

Diffing With Emacs and Vim

Franco Pasut has an instructive post on how to diff files with Vim and Emacs. Both editors have very nice built-in functions to make diffing files easy. I’ve used them both and can attest to their utility.

Pasut’s post, Notes on resolving differences between two documents with the built-in resources of Vim and Emacs, isn’t a comparison and doesn’t make any value judgments. Rather, it merely shows how to use the two systems. I haven’t used Vimdiff in years but my memory is that it was easier to use than Emacs’ Ediff system.

Regardless of their relative merits, both are easy to use and very powerful. To see this, think about how you would reconcile two files with just the standard Diff program and some random editor. With Vimdiff and Ediff, you see the differences one by one and can choose which variant to keep. With Ediff, you can even edit the file directly.

If you’re not familiar with the two systems, take a look at Pasut’s post. It’s short and tells you more than enough to use either efficiently.

Posted in General | Tagged | Leave a comment

Converting an Excel Spreadsheet to an Org Table

I no longer use spreadsheets and haven’t for a long time. I don’t think there are any spreadsheet instances on any of my computers and if there are, they are relics from the mists of time. Any spreadsheet operations that I need to do are done with Org tables.

Of course, I’m not doing financial forecasting or other complicated calculations which may—I don’t know for sure—be easier with a spread sheet. Still, even for those of us who rely entirely on Org tables, it’s sometimes convenient to import a spreadsheet in the sense of converting it to an org table.

Over at the YouTube Emacs Elements channel there’s a nice video on importing an Excel spreadsheet into an Org table. It’s an elementary operation that just captures the data but not the formulas used to calculate the cells. The TL;DR is that you just highlight the spreadsheet data, copy it to the clipboard, paste it into an Org buffer, and call org-table-create-or-convert-from-region to make it into an Org table.

The video shows how to add a line under the headings, delete some columns, and add a new column with some calculated data from the other columns. It might seem like this is a bit restricted but if you’re importing a spreadsheet, you’re almost certainly just interested in the data and not the formulas used to calculate it. Even so, it’s possible to calculate new data from what you import as the video shows.

My main takeaway from the video is how easy it is to grab the data from a spreadsheet and turn it into an Org table in the obvious way.

Posted in General | Tagged , | Leave a comment