Happy New Year

The Irreal staff is still recovering from our virtual Bacchanalia1 last night so today we’ll just say

Happy New Year!

Footnotes:

1

Actually, it was just a matter of staying up until midnight and toasting the new year in with a bit of champagne.

Posted in General | Leave a comment

Checking A Word List

Daniel Lemire has a post that poses an interesting challenge. Suppose you have a list of words—Lemire uses “ftp”, “file”, “http”, “https”, “ws”, “wss”—and want to check if some other word is in the list.

Unless you believe in Zawinski’s law, you might choose regular expressions, especially if you’re writing in Elisp. But as Lemire points out, that’s going to be pretty slow. My first thought was to use regexp-opt to generate an optimized regular expression. For the list above, regexp-opt returns the regex "\\(?:f\\(?:ile\\|tp\\)\\|https?\\|wss?\\)", which will be faster than the obvious regexp but probably still not that fast if the check is going to be made many times.

Lemire offers some other solutions—in C++—including the obvious one of just sequentially checking the list. For a longer list, that could be sped up with a binary search but probably wouldn’t help much with the short list we have. He also offers some other solutions based on padding the input string. He has some benchmark results if you’re interested in the relative times.

One solution that he doesn’t mention is the one I would think of first: check inclusion with some sort of hashing operation. The obvious solution of that sort is to just put the list words in a hash table and check the input word by looking it up. That’s going to be very fast, especially if the list is long.

Perfect hashing seems like another good solution for a short list and will be fast to eliminate a candidate word but if you get a hit, you still have to check for a match. In any event, since the word list is known beforehand, you can adjust whatever hashing strategy you use to be as fast as possible. String comparisons are probably going to be the bottle neck is any reasonable solution so it’s important that the solution minimize those as much as possible.

It’s a nice problem and well worth thinking about.

Posted in Programming | Tagged | Leave a comment

Using RE-Builder

Tony Aldon has a nice follow on to his video on regular expression string replacement. In that first video, he mentioned the visual-regexp package as a way of building a regular expression interactively. At the time, I thought that it as pretty much what you get from the builtin re-builder command but maybe a little easier to use.

In his latest video, Aldon shows how to use re-builder to help build a function that searches with a semi-complicated regular expression and replaces parts of the matched strings. The details of the strings and their replacements don’t matter; they’re just a convenient vehicle to illustrate the process.

One of the really nice things about re-builder is that you can easily change the input method and re-builder will automatically translate the regex back to standard notation when you save it. If you get confused by multiple backslashes and when to use them, this can make working with Emacs regular expressions easier.

Likewise, it’s easy to toggle whether or not the regular expression should ignore case. It’s a simple keystroke; you don’t need to manually change the value of case-fold-search.

Aldon demonstrates all this in his video. The shortcuts he uses—other than the one to start re-builder itself—are the default ones so it’s a good way to learn the package.

The video is just shy of 32 minutes so plan accordingly.

Posted in General | Tagged | Leave a comment

Emacs From Scratch

Torstein Johansen has an interesting post on his new Emacs configuration. He’s a long time Emacs user and his old configuration was 20 years old and 1617 lines long. After he refactored his configuration it was down to 368 lines. A lot of the refactoring was simply a matter of removing packages whose functionality had been superseded by core Emacs.

One thing he does in the video is to number each section of the configuration and then add (occur "^;; [0-9]+") at the top. Executing that expression generates a table of contents for the file. That seems like a nice feature but it’s not in his final configuration, which may mean that there’s a problem when Emacs starts.

My own configuration is currently 2461 lines long so I’m sure it could also do with some refactoring. It’s a bit over 15 years old now so there’s bound to be some cruft in there. One comfort that I took away from Johansen’s video is that he keeps almost everything in a single file.

The current conventional practice is to separate discrete functionality into separate files. Johansen finds this hard to navigate and I agree. I get a lot of pushback whenever I say that but it’s still true. It’s nice to know that at least one other person agrees with me.

If you like seeing what other people are doing with their configuration, Johansen’s video is worth watching. The video is 27 minutes, 50 seconds long so you’ll need to schedule some time for it.

Posted in General | Tagged | Leave a comment

Lisp: Advantages and Myths

Lately, I do almost all my programming in Lisp. That might be Scheme, Emacs Lisp, or Common Lisp. I’ve written many times on why I prefer Lisp as a development environment. I like the syntax, and most importantly that it enables what I’ve described as experimental or incremental programming. It’s easy to try bits of code as small as an expression. My go to example of this is Kris Jenkins’ using the technique to build a Spotify client in Elisp that runs in Emacs in less than 16 minutes.

Recently, I came across an article from LispWorks about the the advantages of Lisp and the myths surrounding it. I’m pretty sure that I’ve seen the article before but I couldn’t find any date on it—or even in the HTML source—and I couldn’t find any Irreal posts about it. In any event, it’s an interesting read and should be very useful to those who aren’t familiar with Lisp and don’t know what a great tool it can be. Or even worse, have heard and believe those stale old myths about Lisp being slow, big, interpreted only, and that it needs special hardware to run well.

None of those myths are true and the article does a good job of debunking them. If you’re not a Lisper, you should take a look at the article to discover why you might want to be. Watch Jenkins’ video and discover how delightful writing in Lisp can be. If you’re an Emacs user, you can experiment with the builtin Emacs Lisp and experience the power of Lisp for yourself.

Posted in General | Tagged | Leave a comment

Regex Search and Replace in Emacs

Tony Aldon has a short video on a couple of alternate ways to do regex search and replace in Emacs. The straightforward way to do that is to use query-replace-regexp (Ctrl+Meta+%) but you can do the same operation in steps by first doing isearch-forward-regexp (Ctrl+Meta+s) to make sure you’re finding the right search object and then calling query-replace-regexp to specify the replacement. That’s not as wasteful as it seems because it will remember the search string from the isearch-forward-regexp and you need only specify the substitution.

Aldon gives an example of this in operation so you can see exactly how it works. Take a look at the video to see the details.

The second method is essentially the same except that it uses the package visual-regexp to get immediate feedback on what the regular expression will match as you type it. That can be pretty handy if Emacs regular expressions are your second choice for regex work and you don’t use them all the time. Again, take a look at the video to see the package in action.

Most of the time you’re probably better off to just use query-replace-regexp but if you’re unsure of the regex, the two step process can make sense. The first method uses functions that are all built-in so it’s always available. If you want to see what’s going to be matched as you enter the regex, the visual-regexp package may be for you.

The video is only 8 minutes so it should be easy to fit in.

Posted in General | Tagged | Leave a comment

Why Emacs Keys Are So Unergonomic

Here’s a blast from the past that I recently came across again. It’s Xah Lee’s post on Why Emacs Keys are Painful. Lee, as most of you probably know, is obsessed with keyboard ergonomics and it is fair, I think, to consider him an expert on the matter. His post considers the question of why—given how painful they can be—Emacs shortcuts are the way they are.

The answer, he says, is pretty simple. First, and probably most important, when Emacs was designed, the implementors were using various Lisp keyboards that mostly had the Ctrl key to the left of the space key and the Meta key to the left of Ctrl. Modern keyboards, of course, have those two keys reversed making Emacs shortcuts less ergonomic.

Secondly, the common shortcuts were chosen to be mnemonic rather than ergonomic. Emacs has so many shortcuts that even with the mnemonic choice they’re hard to remember so it’s not clear it was a bad tradeoff. Except for RSI.

Many Emacs users have developed cases of RSI so bad that they’ve moved to Evil mode for relief. Sometimes this was after years of using the conventional keybindings. I’ve been lucky in that respect. Even though I came from Vi(m), I’ve been using the standard shortcuts for over 15 years without ill effect. But others haven’t been as fortunate so the ergonomics of the bindings is definitely not a trivial complaint.

Of course, in this as in other things, Emacs has you covered. Lee, for example, has his
own set of bindings developed along ergonomic lines. And if reaching for the Ctrl and Meta keys is painful for you, there’s always evil mode.

Posted in General | Tagged | Leave a comment

Vivek Haldar on Emacs 29

Like mbork, Vivek Haldar a short list of some changes he likes in Emacs 29. As with mbork’s list, these aren’t the big things, they’re some small changes that he finds particularly helpful or appealing. You can follow the Twitter thread for the details but the TL;DR is

  • Changing the font size globally
  • Find sibling file
  • Rename the visited file
  • Variable pitch text
  • Pixel scroll precision mode
  • Split root window below or to the right
  • Eval region or buffer
  • Scratch buffer command to switch to or open the scratch buffer
  • Highlight undefined commands in shell buffers
  • A couple of new mouse events

Merry Christmas to everyone from me and the minions.

Posted in General | Tagged | Leave a comment

The Year of RSS

Irreal has considered RSS many times, especially since Google’s liquidation of RSS reader, There’s too many posts to cite here; just do a search for “RSS” on the Irreal site to see them. If you aren’t a silly person, you know that RSS hasn’t gone anywhere and is still helping the knowledgeable keep up with developing news, blog posts, and other interesting content.

Despite what you may have heard, Twitter has not replaced RSS. If you’re the type of person who thinks something significant can be said in 140 characters, it may have for you but the rest of us are happily using RSS daily to notify us of interesting content that we may want to examine.

Nikki Usher has a post that claims this is the year of RSS and that all we need is a new improved RSS reader or maybe RSS protocol. If you’re an Emacs user, it’s hard not to snicker. We’ve been enjoying the excellent Elfeed for years, which is, as Usher demands, open source, flexible, and extensible. Non Emacs users have Feedly, which is also an excellent RSS reader. There are plenty more, including the reincarnation of Reeder.

The problem isn’t a lack of good RSS readers, nor do we need a new protocol. What we need is for more people to realize what serious people have always known: if you have something consequential to say, you probably can’t say it in 140 (or even 280) characters and you need to either start a blog or use something like Substack.

One of Usher’s points is that sites like Substack operate by distributing their content by email and that’s not sustainable but it’s not clear her claim of unsustainability is true. Email users, like RSS users, can scan the subject lines and either read the article, delete it, or stow it for later, just like with RSS.

Even though their business model is based on subscriptions, there’s no obvious reason it couldn’t be adapted to work with RSS and I’d love to see that. But whether they do or not, RSS is here to stay. My daily feed averages about 90 articles, which I regard as suggestions. I don’t read them all but I get lots of interesting content and it all comes directly to my Emacs instance.

Posted in General | Tagged , | Leave a comment

Red Meat Friday: You Can’t Code If…

Here’s some red meat that’s sure to exercise more than a few people:

Realistically, though, Palmen may have a point. Note that he doesn’t say that you’re not a serious developer if you use an IDE. He says you’re not if you can’t code without one. In any event, enjoy this Friday’s red meat and try not to throw anything at your computer screen.

Posted in General | Tagged , | Leave a comment