Martin Fowler On Completion And Ivy

If you’ve been around Irreal for a while, you know that I’m a hug fan of abo-abo’s Swiper/Ivy/Counsel package. Its minibuffer completion system means that if I can get anywhere near the name of a command I’m trying to run or a file I’m trying to open, Ivy will find it, usually with just a couple of keystrokes. Even for complicated names, its builtin easy regular expression engine can easily filter a huge list of candidates to just a few close matches.

It turns out that I’m not the only fan. Martin Fowler is a well known software engineer and author who is also a long time Emacs user. Among his favorite Emacs tools is the same Swiper/Ivy/Counsel package much beloved at Irreal.

He has a post describing his Ivy use and how it makes his work much easier. He does a good job of describing the regular expression engine that will translate a space into .* so that foo bar will match any (sub)string beginning will foo and ending with bar. Two spaces are mapped to a space so it’s really easy to write a regular expression that usually does the job without resorting to the full Kleene notation.

Another nice (optional) feature of Ivy is that it can ignore order so that foo bar will match both foo comes before bar and bar comes after foo. You can turn that on for a single instance or configure Ivy to always use it. Check out the post for the details if you’re interested.

If you want to see how Ivy can meet your completion needs, take a look at Fowler’s post.

Update [2024-02-07 Wed 15:43]: Consult → Counsel

Posted in General | Tagged | Leave a comment

Building Emacs On macOS

I often see posts on reddit and similar venues from people asking for help in building Emacs on Macs. On the one hand, it could hardly be simpler: you just download the code and call make. On the other hand, there are some wrinkles. Those wrinkles amount to installing the required libraries.

For a long time I did this by hand but then you have to worry about keeping them up to date for each new Emacs installation. I can’t even remember what those prerequisites are so keeping them up to date probably isn’t happening.

The right way to do this, it seems to me, is with Homebrew. It will take care of installing them and it’s easy to update them whenever you want to build a new Emacs or other application that depend on them. That still leaves knowing what prerequisites to install. You can try building Emacs and add them one by one when the builds fail but, happily, Lars Ingebrigtsen has come to our rescue with some step-by-step instructions for building Emacs on macOS with Homebrew.

His instructions are really how to do it via SSH from a Linux machine but the same process works if you do it directly on an macOS terminal. The one thing he doesn’t cover is moving the Emacs app into /Applications. I do that with a recursive copy but there are probably other ways. The important thing is to get Emacs.app into /Applications. Before I do the copy, I generally rename my current Emacs.app to something else and leave it in /Applications so I have a backup. The only other issue is getting macOS to open the new app the first time. The way to do this seems to change with each new OS release so you should ask DuckDuckGo for the current method.

Posted in General | Tagged , | Leave a comment

Remote Work Won

Adam Singer has a splendid rant about those who refuse to acknowledge that remote work has won out over the return-to-workers. The holdouts, he says, are bad managers and those with holdings in commercial real estate (CRE).

You can understand the concern of those holding CRE assets. Even in New York City, office space usage is at 46%. These people think it’s incumbent on workers to endure long commutes and degraded family life so that they can maintain their rental income. They’re not getting a lot of sympathy from those workers.

Then there are the managers. Like the CRE folks, one can understand why the middle managers are desperate for their works to return to the office. Without workers to micromanage and drag into endless meetings, there’s nothing for them to do, which makes them a prime target for the next layoff.

Harder to understand is the resistance from senior management. One explanation is that they have no skin in the game. There’s an old joke that the first thing a new CEO will do is move the company headquarters close to where he or she lives. Regardless of the truth of that joke, most senior executives are not going to spend hours on their commute. What commute they do have is eased by a limousine and driver that makes getting to work more like a coffee break.

All that aside, their stated reasons for wanting workers to return to the office are laughable. They mostly boil down to “that’s what other CEOs are doing” and “gut feelings” that worker presence is required for the company to grow and succeed. The fact that those gut feelings are contradicted by research (which shows the opposite) is ignored as an inconvenient fact.

To be sure, there are those who argue against Singer’s position—here’s a link to a particularly articulate demurral. In any event, Singer’s post is entertaining and thought provoking. I think that all-in-all he’s correct but time will tell.

Posted in General | Tagged | Leave a comment

Which Function Mode

Ruslan Bekenev has an interesting post that discusses which-function-mode. I was vaguely familiar with it before I read Bekenev’s post but never thought much about it. Bekenev, however, makes a good case for it. His use case is that he has long functions and deep Org trees and it’s nice to be able to see at a glance where he is.

Wait. What? Org trees? What do they have to do with functions? Probably nothing but the thing is that when which-function-mode is on, it does an excellent job of telling you were you are regardless of what object it’s dealing with. If you’re in an Org tree, it will tell you what subheading you’re in. If you’re in a code buffer it does a similarly good job. I tried it out in my init.el and besides functions, it identified setq, devar, define-key, use=package, and, doubtless, many other objects.

Bekenev says that it worked on most of the files he tried except for files containing HTML. Still, it seems pretty complete.

If you’re a good doobie and keep your functions short it may not do much for you and in any event, if you’re working in a function you’d better know what function it is. On the other hand, it’s easy to imagine searching for a variable and landing in the middle of a function and having no idea what function it is. It may, ironically, be more useful in Org files. Of course, that’s just my take and you may have a very different opinion.

In any event, which-function-mode is a handy thing to know about. Bekenev’s post is short and well worth a minute or two of your time. Check it out.

Update [2024-02-04 Sun]: Fixed link.

Posted in General | Tagged | Leave a comment

Emacs Elements On Iedit

Emacs Elements has a very short video on a relatively unknown but extraordinarily useful command: iedit. It does basically the same job as multiple cursors but is builtin and a bit simpler. It’s less powerful than multiple cursors but is usually more than powerful enough for the job at hand. I use it all the time, usually in preference to commands like query-replace and its siblings.

The video is less than two minutes long so it doesn’t cover many of the nuances involved with iedit. The most important such nuance is what text is selected for editing. If you just place the cursor on some text, the selected text is basically what’s returned by thing-at-point. I often find that that is not what I want so I highlight the word (or extended text) that I’m interested in instead. Then, that text is selected as if by a substring match. On the other hand, that may not always do the right thing either so you should be familiar with both methods. You can also edit the regular expression by hand to get exactly what you want.

Another obscure but useful nuance is restricting the range of selection to the current function. You do that by by specifying a prefix of 0 to the command. There’s a fairly long description of how the command works in its document string so ts worthwhile calling Help for iedit to get the full story.

As I said, the video is very short—only 1 minute, 55 seconds—so it’s easy to fit in. Take a look at the video to get the general idea but you should definitely read the Doc entry too.

Posted in General | Tagged | Leave a comment

Red Meat Friday: Transparent Windows: Just Say No

As you all know, the Minions are in a never ending death match with dark Emacs themes. To them, there is no worse UI choice. I submit, though, that they haven’t considered all the possibilities and that there are, in fact, worse ways to abuse your eyes.

Case in point. I know that there’s a certain cohort that thinks such things are nifty but I doubt they get much work done. How could they? You can’t read what’s on the blasted screen without squinting and really focusing on the text. Just look at those screen shots. Why would anyone subject themselves to that?

Sure, it looks kind of cool (for the first few seconds) but after you finish with the oohs and aahs you’re going to have to actually read the text on that screen and if your eyes are over 17 years old, it’s not going to be easy.

I know, I know. I’m old and crotchety and definitely not with it but really, why do this to yourself? It’s really just another example of the desire for bling that some folks are addicted to. As Vivek Haldar says

What I don’t understand is: why should you ever care how your editor looks, unless you’re trying to win a screenshot competition? The primary factor in looking good should be the choice of a good font at a comfortable size, and a syntax coloring theme that you like.

What it should definitely should not include are glitzy features that make it harder to read the text you’re editing. It’s a text editor not a text obscurer.

As the title says, just say no to transparent windows.

Posted in General | Tagged , | Leave a comment

Nested Key Maps

Protesilaos Stavrou (Prot) has a great video on nesting key maps. A nested key map is just what it sounds like: a key map inside another key map. What that means practically is that one key shortcut will lead to another key map of additional choices.

In theory it works just as you think it should but there are some nuances and it’s nice to have the whole thing explained in one place. Prot’s video uses keymap-set and defvar-keymap, which assume you’re using Emacs 29 or later but even if you aren’t the process is the same except that you have to use the older commands such as define-key and make-sparse-keymap.

You can watch the video to see how to set up nested key-maps but, as I say, it works just like you think it would. One of the non obvious things that the video explains is how to deal with describing the key maps in which-key. To see why this matters, type Ctrl+x and wait until which-key pops up. You’ll see a lot of entries that say +prefix but there’s no indication of what the resulting key map does. Prot shows how to configure which-key to give the key map a meaningful name. That alone is worth watching the video for.

The video is 23 minutes, 17 seconds long so plan accordingly but you really should find some time to watch this video. If you hate watching videos, at least take a look at the sample code at the link. It’s a nice précis of how to set up nested key maps and configure which-key.

Posted in General | Tagged | Leave a comment

Directory Local Variables

Recently, someone posted a link to Artur Malabarba’s old blog. Sadly, Malabarba no longer posts to it but it still has a lot of good and relevant information. The link was to a Malabarba post about directory local variables.

The idea is that you can place various variables controlling Emacs in a file in a directory and those variables will apply only to other files in that directory (and its subdirectories). It’s ideal, for example, if you have a project directory and would like to apply some Emacs customizations to the project’s files. You can specify that variables should apply only to file having a specific major mode or to all files.

The file format is a tiny bit fussy but fortunately you can simply call add-dir-local-variable and it will prompt you for the necessary information and write it to the local variables file, creating it if necessary.

I really like the idea but it never seems to work for me. That’s mainly because almost all the customizations I want to make involve running some code—invoking a minor mode, for example. File local variables support this (see Malabarba’s post or the documentation for the details) but every time I try to use it I get error messages about exceeding maximum evaluation depth. I wrote about this back in October.

Malabarba’s post is short and well worth a read if you’re not familiar with directory local variables or have mostly forgotten the details.

Posted in General | Tagged | Leave a comment

A Factory For Ideas

The title of this post was coined by Arthur C. Clarke to describe the famed Bell Laboratories facility at Murray Hill, New Jersey. If you’re in the software industry and like me, you probably think of Bell Labs as the birthplace of Unix and everything that went with it but the Labs were much, much more. The Computing Science Research Center was actually a small part of the labs.

Most Irreal readers will remember that the transistor was invented at the Labs but there were many other important breakthroughs including the Laser, radio astronomy, cellular and satellite communications, and that thing called Unix. During its heyday, lab researchers earned 10 Nobel Prizes, 5 Turing awards, and more than 20,000 patents.

I have always felt that the Labs would be the ideal place to work. Take a look at this Computerphile video with Brian Kernighan to see what I mean. It’s hard to imagine a better work environment. At least for me.

In a real sense the Labs have been dead for some time and now, in a bittersweet moment, they are abandoning their Murray Hill facility. They’re currently owned by Nokia who is moving the Labs to a new headquarters, called The HELIX Innovation Center, in New Brunswick. NJ.com has a nice article about the Labs and their history. It even has the iconic picture of Thompson and Ritchie working at their PDP-11, although Unix is barely mentioned in the article.

If your heart warms at the idea of Bell Labs and all it meant, be sure to give the article a look. It’s worth a few minutes of your time.

Posted in General | Tagged | Leave a comment

Two Org Mode Tips

Nicolas Martyanoff has a nifty post that discusses some tips for dealing with Org headlines. There are actually three tips but I adopted only two of them. The first involves what happens when you type Ctrl+Return on a headline. By default, it will start a new headline wherever the point is. By setting org-insert-heading-respect-content to t the new headline will be inserted after the current headline and its associated content. It seems to me that this is what you’d always want but it’s not the default.

In the past, I’ve avoided using Ctrl+Return to open a new headline because it messed up my current content. With this change it does the right thing so it’s definitely worth knowing.

The second tip involves another feature I’ve never really understood and never used: org-goto (bound to Ctrl+c Ctrl+j by default). The default action is to open another buffer with some confusing instructions but if you set org-goto-interface to 'outline-path-completion you just get a nice completing list providing you’re using some sort of completion framework. You’ll also need to disable org-outline-path-complete-in-steps, which you’ve probably already done if you’re using a completion package.

Once those changes are in place, org-goto will get you a list of your headlines with the usual fuzzy search capabilities. This make org-goto really useful, especially for big files with lots of headlines such as my list of blog posts and notes.

The third tip involves not highlighting the entire line of TODO headings. I use org-fontify-done-headline to set DONE headlines to a different color so I don’t need this tip. Even before I discovered org-fontify-done-headline, I was never bothered by having the entire headline the same color as the TODO keyword but your mileage may vary so do what works for you. As usual, Emacs lets you have it your way.

This is a short post but it has a lot of good information in it. Definitely worth a few minutes of your time.

Posted in General | Tagged , | Leave a comment