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

Exporting To Markdown

There’s a disadvantaged group of people in our industry that use Markdown to prepare their text for output to, say, PDF or HTML. I call these folks disadvantaged because Markdown, although fine for preparing simple documents for publication, has some serious deficiencies when compared to Org mode. I’m not talking the syntax, which is different from Org’s but just as good. Org is more powerful as a markup language but really shines as an embedded mode of Emacs which provides editing commands specialized to Org that aid in producing serious documents.

Another problem with Markdown is that there isn’t a Markdown but several. The original Markdown was relatively simple so users such as GitHub extended it but, of course, each in different ways. The result is that there are several dialects of Markdown. While there are ports of Org mode to other editors, there is still only one Org mode markup language.

Org mode provides a very comfortable and flexible writing environment that can easily handle complex documents. Still, sometimes you need to deliver Markdown for certain applications, Websites, or sharing with users who aren’t Emacsers. That’s not a problem because Org can export to Markdown. But there are problems.

Franco Pasut has a useful post that looks at exporting from Org to Markdown. In particular, he explains how to covert Org tables to Markdown tables. The TL;DR is to use Pandoc specifying the --to-gfm option. He also discusses some problems with exporting code blocks to Markdown. If you find yourself having to export to Markdown, you should probably take a look at Pasut’s post.

Posted in General | Tagged , | Leave a comment

Peer Review

Adam Mastroianni has a thoughtful and interesting article on peer review. The idea of having outside “experts” evaluate a prospective paper before it’s published in a journal seems to be obviously the right thing and something that has been the norm in scientific—and then all academic research—practically from the beginning.

Mastroianni begs to differ. In the first place, peer review, far from being the ancient procedure that we imagine is actually quite new. Before 1960, it was rare and none of Einstein’s papers, for instance, were peer reviewed. In fact when a journal decided to peer review one of his papers, he was so surprised and upset that he withdrew the paper and published it elsewhere.

Mastroianni’s second point is more telling. He describes peer review as a massive experiment that was flawed from the beginning and has, in fact, failed. He claims that not only is there no evidence that peer review improves science but there is plenty to suggest that it’s actually made it worse. He notes—correctly I think—that peer review makes sense only if believe science is about preventing bad ideas. But, he says, it’s not. It’s about finding the best ideas, something that peer review will never do because its raison d’être is to find and suppress bad ideas.

The subject of peer review probably seems of interest only to academics but, in fact, it affects us all. Despite this so called safeguard, about three quarters of papers in critical areas such as cancer research fail to replicate and many are outright fraudulent. That means that millions—or even billions—of dollars are being misappropriated in areas where we all have a vital interest.

I believe Mastroianni is correct but I don’t hold out much hope for the end of peer review until the university system itself finally collapses. Of course, many believe that process is already well underway so who knows?

Posted in General | Tagged | Leave a comment