Using Pcase and Name-let for Pattern Matching and Tail Recursion

Erik L. Arneson has an interesting post about using functional programming constructs with Elisp. In particular, he considers pattern matching and tail recursion.

Tail recursion is, in my estimation, one of the most useful properties a programming language can have. Scheme famously has it in its specification and many Lisps have it de facto if not de jure. If you’re not used to using recursion in your programming, that may seem like hyperbole but once you’ve internalized the method, other paradigms seem clumsy. Tail recursion is not really built into Elisp but it’s still possible using the named-let construct. It’s basically the same as Scheme’s named-let so if you’re a Schemer you’ll feel right at home.

Sadly, I haven’t internalized the pattern matching paradigm although I keep promising myself to do so. It’s a powerful idea that extends things like C’s switch statement or Lisp’s cond and case constructs. In Elisp, you use the pcase construct for this. Once you get used to the pattern syntax, it’s a powerful generalization of the common “if-else” constructs most programming languages have.

Arneson’s examples don’t begin to capture the power of these methods. They’re powerful tools that are well worth learning and internalizing. If you’re an Emacser, Elisp provides you an easy way of experimenting with these techniques. Believe me, mastering them will make you a better programmer.

Posted in General | Tagged , | Leave a comment

Viewing Exotic Image Files

As you know, Emacs can display most of the common image formats such as SVG, JPEG, PNG, and GIF but what about formats, such as webp, that aren’t handled natively by Emacs? Álvaro Ramírez has another quickie that tells us how to do it.

It turns out to be simple, especially if you already have ImageMagick or one of a couple of other external image converters already on your system, it’s just a matter of telling Emacs to use the external image converter. Here’s the magic spell:

(setq image-use-external-converter t)

If you don’t already have ImageMagick installed, you might find it a worthwhile addition to your system. Previously, Ramírez considered the problem of combining a series of JPEGs into a single PDF and told us how to do that. His solution was in the context of his dwim-shell-command framework but it’s just a simple call to ImageMagick’s convert command. Many of his simple DWIM Emacs shell functions make use of ImageMagick so you might also want to consider adding dwim-shell-command to your Emacs configuration.

Ramírez has been blogging up a storm lately. Many of his posts offer actionable suggestions for solving the small but annoying problems that we all run into. If you haven’t already, you may want to add his feed to your RSS reader.

Posted in General | Tagged | Leave a comment

Red Meat Friday: eMacs

You guys always jump on me and accuse me of being cantankerous when I go off on a rant like this but, really, it’s too much to bear. I’ve noticed lately that some people are referring to Emacs as “eMacs” as if Emacs stood for “electronic macs”, or “electronic macros”, or something. It doesn’t. Emacs is widely understood to stand for “Editing MACroS”, although Irreal’s go to guy for Emacs history, Lars Brinkhoff, says he can find no evidence for that. Regardless, the E certainly does not stand for “electronic” so if you’re going to write about Emacs, can you please name it correctly and not make it look like a marketing term?

Yes, yes. I know it’s a small thing and hardly worth commenting on but names do matter and it’s important to get them right. Otherwise, as with the word “hacker”, the ignorant will kidnap the term and change its meaning. Don’t let that happen to our beloved editor. Fight this abomination whenever and wherever it raises its ugly head.

Added before publication: Perhaps this explains it.

Posted in General | Tagged , | Leave a comment

macOS As A Unix Workstation

Torstein K. Johansen has an interesting post on configuring a Mac to be comfortable for a Linux user. Johansen is a self described “die hard Linux user” but recently had to work on a Mac. Macs are Unix machines but they’re based on FreeBSD and are certainly not Linux so if you’re a Linux user it’s useful to know how to configure a Mac to be as much like a Linux workstation as possible.

The most important thing, of course, is getting a decent Emacs installed. It used to be that Apple included Emacs in their distributions but it was a very old version and not one that any modern day user would want to use. They’ve since stopped including it so you’ve no choice but to install your own. I do that by compiling from source but Johansen chose to load his from Homebrew.

Once Emacs is installed, most of the rest of Johansen’s configuration involves replacing the default, older, BSD Unix utilities with their more up to date GNU versions. His post shows how to do all that.

We here at Irreal are, as most of you know, a Mac shop so we don’t have that problem but Johansen’s post is still worthwhile. For example, I learned about btop, a top replacement and used his recipe to install it. I’m content with the BSD versions of the Unix utilities but if you prefer the GNU versions, he shows you how to install them.

All in all, its a really useful post for anyone who wants to make their Mac the best possible workstation. Macs are famously Unix based but the default install hides a lot of that from you. Johansen shows you how to fix that.

Posted in General | Tagged , , | Leave a comment

Org Tree Slide

Everybody hates slide decks. Jeff Bezos even famously banned them from Amazon. Still, most of us who are called upon to give a presentation will make slides the center of that presentation. There are, of course, dedicated programs like PowerPoint, Keynote, and the various clones that come with packages like LibreOffice but few Emacs users are going to want to wade into that swamp.

Happily there are several Emacs packages that let you prepare slides from the comfort of your editor. David Wilson over at System Crafters has an informative video that explores one of those packages: org-tree-slide.

Based on Wilson’s video, I’d judge that the application doesn’t produce slides as nice looking as some of the other packages but it does have the advantage of not needing any other packages. You just load the org-tree-slide package and you’re good to go. The input is very simple: you just make an Org file and the headers become the slides. On the plus side, you can have images and code blocks and these get exported to the slides. Wilson shows how to control things like the font and image sizes and simple animation effects.

The video is 31 minutes, 38 seconds long so you’ll need to schedule some time. If you’re looking for a simple package to generate simple slides, this package is certainly worth taking a look at.

Posted in General | Tagged , | Leave a comment

Using Icons with Mu4e

Just a quickie from Álvaro Ramírez. If you’re a Mu4e user and would like to have an email’s status shown as one or more icons instead of a series of comparatively opaque letters but don’t want to deal with all-the-icons, Ramírez has the answer for you.

It’s pretty simple. You choose the icons you want for each status indication—or simply copy Ramírez’s—and add a series of configuration items to your init.el. Those items are listed in Ramírez’s post so take a look if your interested in adding your own.

Posted in General | Tagged | Leave a comment

A Conversation with Mickey

Syntopikon has an interesting interview with Mickey Petersen, the proprietor of Mastering Emacs and all around Emacs expert and expositor. He’s no stranger to Irreal readers so it’s always nice to see him discuss matters. The last time I remember seeing an interview with him was in 2014 in an on-line chat with Sacha Chua.

Like many of us, Mickey abandoned his first attempt to use Emacs. That was in his pre-college days when he was just discovering and learning Linux. Later, when he got to the university, he adopted Emacs party in reaction to the noisy voices insisting that all real hackers used Vim. When you read Mickey now, it’s easy to believe that he’s always had a thorough knowledge of Emacs and didn’t struggle like the rest of us. Of course, that’s wrong. He used it for some time before, as he says, the light came on and he realized the true potential of Emacs.

He also has an interesting exchange with the interviewer on the use of Emacs for non-technical or technical-adjacent users. The interviewer is an Emacs user too but he uses it for writing. I’ve long felt that all writers should at least try Emacs. After all, it’s all about wrangling text whether you’re a developer or a writer and Emacs excels at that. If you learn enough Elisp to make minor customization’s you can mold Emacs into a your ideal writing environment. Mickey believes that more could be done to make learning Emacs easier for the non-developer and he explores a few of those in the interview.

Like most things that Mickey’s involved with, the interview is interesting and worth reading. A few minutes of your time would be well spent.

Posted in Programming | Tagged | Leave a comment

Replying to a Sender Specific Email Address

Sebastian Schulze has an interesting post on handling email To and From addresses. His procedure when supplying an Email address to, say, a Website such as some-site.com is to specify some-site.com@his-domain.com where his-domain.com is his domain. That allows him to apply appropriate filters and discover the source of spam.

In order for this to work, he needs two things:

  1. His email provider must pass all email to him regardless of the user name.
  2. He has to set the From address on any replies to some-site.com@his-domain.com.

The first item is generally doable if you have control of your domain, especially if you run your own email server. The second is a lot harder with almost every email client. Fortunately Schulze uses mu4e so it’s relatively easy with a bit of Elisp.

Actually, mu4e can almost handle this out-of-the-box. You can specify your email addresses and mu4e will respond with the appropriate From address. Schulze’s situation is a little more complicated. You could do it with vanilla mu4e but you’d have to constantly housekeep your mu4e configuration. Schulze’s solution takes care of everything automatically.

The Elisp required is minimal so it’s an easy solution providing you have your own domain and are using mu4e. My own—not as good—solution is to add specific “possibly spam” addresses to my mail server and use that for sites that are possible sources of spam. Schulze’s solution is clearly superior and worth emulating if you can.

Posted in General | Tagged | Leave a comment

Fred Brooks

Fred Brooks was a computer scientist who, among other things, worked on the development of OS/360. He’s probably best known for his influential book The Mythical Man-Month, which has itself obtained a mythical status within our industry. The TL;DR of the book is that adding more engineers to a late project makes it later. Brooks speculated that the reasons for this are that adding engineers quadratically increases the amount of required communication and bringing the new engineers up to speed actually slows things down.

Sadly, Brooks died on Thursday at the age of 91. Steve Bellovin tweeted the news:

Even people who haven’t heard of The Mythical Man-Month are familiar Brooks’ Law, which distills the central lesson of the book. Of course, Brooks’ Law is honored more in its breach than in its observance, especially by managers who “just know” that a few more staff will solve all a project’s problems. Still, it’s worth reminding those who are inclined to add more manpower to a project that 9 women can’t make a baby in a month.

Posted in General | Tagged | Leave a comment

Red Meat Friday: JavaScript

With all the Sturm und Drang about Twitter, it’s time for Irreal to provide a little red meat—not about Twitter but about JavaScript:

Folks may disagree about Twitter but virtually everybody is united in their hatred of JavaScript even if it’s their main programming language. Or maybe especially if it’s their main programming language.

Posted in General | Tagged | Leave a comment