Controlling Buffer Placement

Protesilaos Stavrou (Prot) has a new heroic video. Heroic because it undertakes to describe the mechanism for controlling the placement of buffers. That is, where in the display environment should a buffer be displayed. That mechanism is complex so describing it usefully is a significant task.

For most of us, most of the time, the default behavior is fine but sometimes we would prefer something else to happen. This is Emacs so of course we can have it our way but even I was surprised at the level of control the user has.

The basic mechanism is an alist called display-buffer-alist. Prot describes this list as having entries of the form

;; ( BUFFER-MATCHING-RULE
;;   LIST-OF-DISPLAY-BUFFER-FUNCTIONS
;;   OPTIONAL-PARAMETERS)

The BUFFER-MATCHING-RULE is a regular expression or more complex expression that selects the buffers to which the LIST-OF-DISPLAY-BUFFER-FUNCTIONS and OPTIONAL-PARAMETERS should apply. Those functions and parameters can be selected from a very rich set and give very fine control over the buffer placement.

You’re going to have to watch Prot’s video for more details and even he doesn’t cover the full list of possibilities. He provides a link to his configuration for display-buffer-alist that demonstrate some of the advanced features but if you’re really interested in this you’ll probably have to consult the documentation.

The video is 29 minutes, 51 seconds so schedule some time. The video is a bit complex so schedule your watching for a time that you can focus on its content.

Posted in General | Tagged | Leave a comment

Red Meat Friday: Reaching New Heights In Illegibility

The other night I was enjoying a sound, dreamless sleep when at 3 AM there was pounding on my bedroom door and the minions started jumping up and down on my bed. “Mrrflx. Wha? Wha’s happening?” It turns out the Minions had seen another dark theme and were aching for a cage match.

In the morning, after coffee, I took a look at the theme and had to agree the Minions had a point. Take a look. Maybe it’s just my old eyes but those screen shots are borderline illegible. I just don’t get this obsession some folks have with low contrast dark themes. Those people will claim that they’re easier on the eyes but research says otherwise. And, if you must have a dark theme, there’s still no reason to forego legibility.

It’s almost as if there’s a secret contest, that most of us aren’t privy to, to see how close to illegible you can make your theme and still be able to get work done. Of course, the contestants are going to get wrinkles from all that squinting.

As an afterword, I should remind everyone that Red Meat Friday posts are supposed to be humorous. In particular, although I’ve made a lot of fun of the Creamsody themes, we should all thank jasonm23 for his work and for sharing it with us. It’s just another example of Emacs letting us have it our way. Even if we can’t read the result.

Posted in General | Tagged , | Leave a comment

Prot On Abrev-Mode

Protesilaos Stavrou (Prot) has posted a nifty video on abbrev-mode. It turns out that there’s a lot more to it than you might have thought. Prot says that you can think of it as a lightweight alternative for yasnippet or something similar. My view is that if you’re already familiar with YASnippet you should just use that but if you aren’t familiar with it or just want something simpler, abbrev-mode may be just what you need.

As Prot shows, it’s pretty easy to set up a simple abbreviation: you simply call the define-abbrev function specifying the abbreviation and its expansion. But even in this simple case there are some nuances. You also have to specify the major mode the abbreviation will be active in. That can be global or it can be more specific. The modes form a hierarchy with global mode at the top, more specific modes (such as text-mode) next, and then derived modes (such as org-mode). Abbreviations for lower modes override the same abbreviation at higher levels so there’s a consistent inheritance mechanism.

That’s all there is to the simple case but Prot considers two more complicated cases. First, you can replace the expansion string with a function that will return the expansion value. Prot uses the example of a function that returns an ASCII representation of the current time.

Next, he considers the case of expanding something like :emojiX to the corresponding emoji. The problem here is that abbrev-mode will not recognize :emojiX as a word because of the colon. You can tell abbrev-mode to recognize such things by adjusting the regular expression it uses to recognize abbreviations.

Prot gives all the details in his video and there’s a copy of his scratch file at the link so you don’t have to worry about copying the things he does down. The video is 26 minutes, 22 seconds long so you’ll have to schedule some time. As usual with Prot’s videos, it’s a worthwhile investment.

Posted in General | Tagged | Leave a comment

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