Buffer-associated window layouts in Emacs

October 17th, 2021

I’ve recently spent some time configuring Emacs. It is a pastime of sorts in which I occasionally get really invested and then eventually lose interest again. Each time, though, I start my configuration afresh, and I always learn something new.

This time, my interest has been split between two packages. On the one hand EXWM, a fully working X window manager within Emacs, and on the other Wanderlust, an e-mail client for Emacs with built-in IMAP support. The two packages are obviously quite different from one another, but they do have one thing in common: they require a lot of manual window management.

In Emacs, there are two common window layouts: the single-window layout, which is what it normally starts in, and the two-window layout, with a file in the upper window and a help buffer in the lower window. Usually, when I’m editing a file, I use a two-window layout.

However, when using EXWM, I’ve often found myself wanting to go from editing a file in a two-window layout to viewing an X program in a one-window layout. The obvious solution is to close the second window and switch to the buffer containing the X program. The problem with this solution is that I lose the original two-window layout. When I switch back to the file I was editing, it will be displayed in a single-window layout.

This annoyed me to such a degree that I spent a lot of time thinking about how best to solve it. Eventually, I come up with the following solution, which is both very simple and very useful.

I call it buffer-associated layouts. The idea is that each buffer is associated with a certain window layout, which is restored whenever that buffer is switched to. The implementation looks like this:

(defvar *buffer-layouts* (list) "Buffer-layout associations")
(defvar *protect-buffer-layouts* nil "Temporarily protect buffer layouts")

(defun restore-buffer-layout ()
  "Restore the layout associated with the current buffer."
  (let ((conf (alist-get (current-buffer) *buffer-layouts*)))
    (if conf
	  (set-window-configuration conf)
	  (message "Restored buffer layout"))
      (setf (alist-get (current-buffer) *buffer-layouts*)
      (message "Set buffer layout"))))

(defun switch-to-buffer-with-layout ()
  "Switch to the window layout associated with a buffer. At the
same time, associate the original buffer with the original

If the new buffer has no associated layout, it is displayed as
the only window in the frame."
  (let ((*protect-buffer-layouts* t))
    (dolist (window (window-list))
      (setf (alist-get (window-buffer window) *buffer-layouts*)
    (call-interactively #'helm-multi-files)
    (let* ((buf (current-buffer))
	   (conf (alist-get buf *buffer-layouts*)))
      (when conf
	(set-window-configuration conf)
	(select-window (get-buffer-window buf))))))

(advice-add #'delete-other-windows :before
	    (lambda (&optional window)
	      (when (not *protect-buffer-layouts*)
		(dolist (window (window-list))
		  (setf (alist-get (window-buffer window) *buffer-layouts*) nil)))))
(advice-add #'delete-window :before
	    (lambda (&optional window)
	      (when (not window)
		(setq window (get-buffer-window)))
	      (when (not *protect-buffer-layouts*)
		(setf (alist-get (window-buffer window) *buffer-layouts*) nil))))
(advice-add #'quit-window :before
	    (lambda (&optional kill window)
	      (when (not window)
		(setq window (get-buffer-window)))
	      (when (not *protect-buffer-layouts*)
		(setf (alist-get (window-buffer window) *buffer-layouts*) nil))))

(set-keys "C-c b" switch-to-buffer-with-layout
	  "C-c n" restore-buffer-layout)

Basically, a global variable holds a list of all buffer–layout associations, which is updated and referred to whenever the switch-to-buffer-with-layout function is called. I’ve personally chosen to bind it to C-c b.

(Note that switch-to-buffer-with-layout manually calls helm-multi-files. If you don’t use Helm, you should replace this with switch-to-buffer.)

Here is a short demonstration of switching between a three-window file editing layout, a single-window EXWM layout and a two-window Wanderlust layout:

Video demonstration of switching between layouts by switching buffers.

As you can see, whenever I switch buffers (with C-c b), the window layout is updated too. The benefit with this approach is that you don’t need to learn and remember a separate system for keeping track of layouts. They’re automatically associated with the buffers, which you already know how to manage.

Move Thunderbird’s remote content warning to the bottom

April 18th, 2021

I have sort of a love-hate relationship with Thunderbird (and with Mozilla in general). Each version seems slower and less pleasant than the previous, but it is still hands down the most capable cross-platform e-mail/news client there is. I use it not only to read my e-mail, but to view and keep track of various newsgroups too.

While it could sure start a bit quicker, all in all, I’m fairly happy with it. But there’s one piece of poor user interface design in that has been bothering me lately: the remote content warning.

Remote content warning

“To protect your integrity, Thunderbird has blocked the remote content in this message.”

I appreciate the heads-up, as well as the fact that I’m offered a convenient way to modify my image blocking settings. The problem is that this yellow bar appears with a slight delay. Whenever I open an HTML message with remote images, the body of the message appears, but is immediately relocated to make room for the yellow bar, which pushes it down with an animation. Needless to say, this is incredibly annoying.

The saving grace of Mozilla’s programs is that they’re fairly easily customized. If you add the following code to a file named userChrome.css located within the chrome directory of your user profile directory (just create it if it doesn’t exist), then the yellow bar is shown below the message body instead:

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

#msgNotificationBar {
    -moz-box-ordinal-group: 2;
    margin-bottom: -1px;
    border-top: 1px solid rgb(145, 145, 145);

Remote content warning at bottom

Now, I’ve tested this in Thunderbird 38, and I’m not sure whether it works in recent versions of Thunderbird. The development of GUI programs tends to get worse with age, and I wouldn’t be surprised if the ability to do this has been removed. Regardless, it works in the version of Thunderbird that I’ve personally settled on. I was able to figure it out thanks to the add-on DOM Inspector Plus.

Edit Windows file types with FileTypesMan

April 7th, 2021

To keep track of which programs should open which files, Windows uses a system with three basic units: file extensions, file types and actions. File extensions like .html and .txt are associated with a single file type, which is called things like ChromeHTML and txtfile. The file type includes a number of actions, such as Open and Edit, each containing a command string, which tells Windows how to open the file.

Back in Windows XP, the Explorer included a very useful dialog window in which you could manually edit the association between file extensions and file types, as well as the actions belonging to each file type. I personally used this extensively. Specifically, I like to customize the Edit menu item for various file types. For example, I could click Open on an HTML file to open it in my web browser and click Edit to open it in my HTML editor.

Unfortunately, this feature was removed from later versions of the Explorer. Many third-party alternatives have been developed, but the most powerful and reliable one that I’ve found is FileTypesMan by NirSoft. While initially a bit confusing, it is a very capable program, and I thought I’d share some tips about it in this post.


FileTypesMan doesn’t include an installer, but I prefer to extract the archive into %ProgramFiles%\NirSoft. Then, I run the following command in a command prompt with administrative rights:

mklink /j "%AppData%\Microsoft\Windows\Start Menu\Programs\Nirsoft" "%ProgramFiles%\NirSoft"

This creates a directory junction between the NirSoft folder and a new NirSoft folder in the current user’s Programs folder. This makes FileTypesMan easily accessible from the Start menu. Furthermore, the contents of the NirSoft folder will be included when I make a search from the Start menu.


FileTypesMan’s interface is divided into two sections: at the top, the list of all registered file types, and at the bottom, the list of all actions of the currently selected file type.

Main FileTypesMan window

You can search by file extension by typing anything while having the file type list selected. To search by other fields, use Edit Find (Ctrl-F). In the screenshot above, I’ve selected the .html file extension by typing .html (including the period). As you can see, it is associated with the ChromeHTML file type, which contains three actions: EditEdit2 and open.

Open and Edit are common actions, often defined by default, but I’ve added Edit2 myself. For ChromeHTML files, I’ve defined Edit to open KompoZer, my WYSIWYG editor, and Edit2 to open Notepad2, my plain-text editor.

Editing file types and actions

You can create a new action or edit an existing one by right-clicking in the action list. This brings up a menu where you define the internal action name, the menu caption (i.e. the text displayed in the Explorer’s right-click menu) and the command string describing how to open the file. Furthermore, you can copy and paste actions between multiple file types via the Copy Selected Actions option in the right-click menu.

Edit Action

The Edit Action window.

In the file type list, you can double-click a file extension/type in order to edit its properties. You can create a completely new file extension via Edit New File Extension (Ctrl-T).

Edit File Type

The Edit File Type window.

Creating new file types

The only thing that FileTypesMan can’t do is to create new file types per se.  It can create new file extensions, to which actions can be attached as well, but not new file types. Fortunately, it’s fairly simple to create a file type manually. Just edit and apply the following .reg file:

Windows Registry Editor Version 5.00

Then, you can associate your file extension with your new file type by right-clicking on it in FileTypesMan and selecting Replace File Type For Selected Extension.

Adjust brightness and contrast on a CRT monitor

March 31st, 2021

So far, most of my posts on this blog have been software-related, but the experience of a computer is equally related to its hardware, especially to the physical interfaces through which we interact with our computers: the mouse and the keyboard, naturally, but also the monitor.

I personally have four monitors in my apartment: three CRTs (including my iMac) and one IPS. If you own a CRT monitor, you probably spend quite a bit of time adjusting the brightness and contrast. Because CRTs don’t produce as bright a picture as modern alternatives, you often need to re-adjust it depending on the brightness of the room. And to me, it’s never been obvious what the perfect setting is.

For those who recognize themselves, I recently found a page written by Charles Poynton that explains what the brightness and contrast settings actually mean. It turns out they mean the opposite to what I’ve understood them to mean!

In reality – if I’ve understood it correctly – “brightness” controls the darkness of blacks, whereas “contrast” controls the brightness of whites. Once you’ve set “brightness” to a level such that black truly looks like black, but the image isn’t too dark, then you can freely adjust “contrast” to control the overall brightness of the picture. In other words, “contrast” is brightness!

It is all explained very well on the page linked above. Personally, I found the tip immensely useful.

Two CRT monitors

Two of my CRT monitors. The left one is for my main PC, while the right one is for my server.

Automate file tasks with File Buddy droplets

March 24th, 2021

On classic Mac OS and OS X alike, AppleScript is a very useful tool for automating commonly performed tasks. I’ve previously shared a couple of ways in which AppleScript can be used to improve Finder workflow. That was mainly with respect to window management. For simple, but tedious tasks involving file metadata, I find a program called File Buddy to be a better option.

File Buddy is a Swiss army knife of file management. While the application has an incredible depth, you can fundamentally think of it as a powerful version of Finder’s Info window. If you open File Buddy, press File > Get Info… and select a file (or, after rebuilding the desktop file, just drag and drop it on File Buddy’s icon), then the following window will appear:

File Buddy Info window

In File Buddy’s Info window, you can inspect ­ and manually modify ­ the value of any given property of the file. In the screenshot, you can see that I’ve queued up a couple of changes, indicated by the red check marks, that I can apply by pressing a Save button.

But ­ and this is one of File Buddy’s selling points ­ instead of pressing Save, you can press the icon with a water drop near the top of the window. This will save the queued changes in a File Buddy droplet, which is a small program that will apply those changes to any file that is dropped on it. Optionally, if you drag a folder, then the changes will be recursively applied to all the files in that folder.

File Buddy droplet on the desktop

File Buddy droplet on the desktop

Droplets are especially useful for quickly changing something a particular file, such as its creator code. For example, an interoperability issue between classic Mac OS and OS X is that OS X gives text clippings the creator code MACS, whereas classic Mac OS expects the creator code drag. This means that text clippings created on OS X cannot be opened on OS 9! To mitigate this, I have a droplet on my desktop called “Fix Clipping”, onto which I can drag any file to change its creator code to drag.

In general, File Buddy’s droplets are great for quickly opening a file with a different program. Let’s say I want to open an HTML document in BBEdit. Instead of manually opening the file using BBEdit’s Open… menu, I simply drop it on my “Make BBEdit” droplet, which changes the creator code to R*ch. Now I can double-click the file to open it in BBEdit.

What’s so great about droplets is that they’re a graphical, Macintosh-like solution to the problem of bulk processing. While File Buddy offers a more conventional list-based bulk processing feature, droplets are what really sets the product apart. Just like the Macintosh itself, they are simple, elegant and easy to use.

File Buddy 7, the last version with support for both OS 9 and OS X, has graciously been released for free. File Buddy is still being developed for modern versions of OS X and is available for sale on Skytag Software’s web site.

Reflections on the blog

March 19th, 2021

In the late 2000s, I used to run a moderately successful Swedish blog about technology – Softtype – which no longer exists. Around 2011, I lost interest and stopped doing it. This new blog is my first real attempt at blogging in a decade.

That decade has given me some valuable perspective on blogging as a whole. I have a clearer idea of what makes for good content, and I’ve realized that you can’t write about something in the long term unless you’re really passionate about it.

That’s what I want to write about in this post. It seems early for a “state of the blog”, seeing as how I’ve just started it, so consider it more of a “state of my blogging” from 2008 until now, with special focus on my new blog.


In terms of content, I think a blog like mine has to strike a balance between more philosophical and more practical posts. While practical posts are more useful, they often feel a bit shallow. I feel like a couple of my OS X posts are like that. They’re useful information, but more tutorials than blog posts, really.

On the other hand, philosophical posts, while having the potential to be deep and interesting, are rarely very useful from a practical standpoint. Sometimes, they just serve to stir up emotion; in some sense, I think my post about using old computers is like that. It’s gotten the blog a lot of traffic, though, and I’m grateful for that!

But the perfect blog post, in my opinion, should be both philosophical and practical. It should open the mind to new ways of thinking, in a very straightforward, pragmatic way. Of all my posts so far, I think the one about AppleScripts for the OS 9 Finder has succeeded best in this regard.

To apply that idea to this blog post, I’ll include a small tip that I find helps me with the wording of post titles: use the imperative mood instead of the present participle. For example:

  • Restore Leopard-like Exposé in Snow Leopard” instead of restoring
  • Stream audio from iOS to Snow Leopard via AirPlay” instead of streaming

A lot of titles involve a verb, especially when it comes to more practical posts, and reading -ing over and over again gets old.


After experimenting with alternatives (including a short venture to build my own blog engine), I settled for WordPress as the back end for the blog. I was initially worried that the admin interface would be slow or unusable in older browsers, but it turns out that it’s still not too bad, as long as you re-enable the classic editor.

My reason for choosing WordPress is simply that, in terms of pure function, it is unparalleled. It just works, and it works very well. Looking around, there frankly doesn’t seem to any real (free) alternative. WordPress gives me so much for free. Out of the box, I can use MarsEdit to write and edit posts. I get pingbacks and trackbacks and threaded comments.

WordPress is big enough to be described as a monopoly, and a monopoly comes with monopoly benefits – most importantly, stability. I’m happy to say that the WordPress of 2021 is still pretty similar to the WordPress I learned to love in the 2000s.

As you can see, I use the old default theme for WordPress. This is a deliberate choice! Here’s how I’m thinking: Because the default theme is so recognizable, most visitors will immediately see that this is a blog. This means they will also understand that there are other posts they can read, that they can leave comments on posts and that they can subscribe to the blog via RSS. This is a big benefit, both for them and for me.


If there’s one thing I’ve learned about blogging, and really any type of content creation, it’s that it’s best to keep your plans about the future to yourself, because the majority of the plans that humans make don’t work out. That said, personal computing is a topic that is dear to my heart, and it is hard for me to imagine that I would cease to have things to say about it.

Whether anyone reads it is another question. Blogs sure seem dead, at least in comparison to the 2000s. But who knows – maybe they aren’t as dead as they seem.

Why use old computers and operating systems?

March 18th, 2021

On this blog, I write about the various computers I use and about the operating systems I use on them. Apart from Windows 7, which is relatively modern, these include Mac OS 10.6 Snow Leopard, which at this point is quite old, and Mac OS 9, which is practically ancient. I’d like to talk a bit about why I use such old systems.


I’ve mentioned before that, to me, computers are more than just a means to an end. I enjoy them or dislike them to the extent that they are a reflection of myself, to the extent that I can identify myself with them. They bring me immense joy – as well as much irritation, unfortunately…

Because I see computing as an interest, a hobby and a passion, I don’t like to use computers and operating systems that I don’t enjoy using, in the same way that somebody who enjoys literature isn’t interested in reading literature that they think is poorly written. That’s why I refuse to use Windows 10. The poor user interface just hurts my soul.

It happens to be that some of the best, most well-designed, most enjoyable user interfaces are buried in history. There is no modern equivalent to the Macintosh. If I want an enjoyable computing experience, then I am forced to look in the past.


Even from a totally pragmatic standpoint, there are good reasons not to reject old computers. To me, the most glaring example is HyperCard, a revolutionary application for the Macintosh which literally does not exist on modern operating systems. If you’ve never used it, it’s hard to appreciate just how incredible it was, but imagine if spreadsheet programs like Microsoft Excel stopped being developed and eventually just disappeared – that’s the level of significance that HyperCard had.

Quite literally, the only way to use HyperCard is to get a hold of an old Mac – or emulate it, but emulation always falls short of the real deal. That’s why HyperCard alone is a pretty clear reason to use Mac OS 9 today. It’s one of the biggest reasons why I regularly boot up my iMac G3; once you’ve discovered it, HyperCard is just too useful to give up.

Example of a HyperCard stack

I use HyperCard to keep track of the Russian literature that I read.


When it comes to retro computing, the inevitable question is how to access the web. The answer is that it isn’t always possible. My iMac G3 is technically able to browse the web, but it’s not a particularly enjoyable experience, nor a very useful one. My 2009 Mac Mini running Snow Leopard handles it relatively well, but even Snow Leopard has problems accessing a lot of modern web sites.

I think the only solution is to stop expecting every computer to be general-purpose. In the human world outside of computers, general-purpose tools are pretty rare. No one expects there to be a single screw that fits all holes.

If we applied this type of thinking to computers, I think we could have a healthier relationship to them. I’m quite happy for my iMac to be my HyperCard machine. As long as I have a way to transfer data to and from it, it works rather well.

In fact, as cell phones become more and more general-purpose, I suspect there will be more room for non-general-purpose personal computers. There is a ton of software, just like HyperCard, waiting to be discovered in the depths of computer history, and the computers needed to run them are cheap. If you like WordStar, why not get an old DOS machine? Even if WordStar is the only program you’ll run on it, it might be a worthwhile endeavor – as long as you have space for it.

Improve OS 9 Finder workflow with AppleScript

March 17th, 2021

The modern Finder, which was introduced into Mac OS X from NeXTSTEP, is a file manager, much like Microsoft’s Explorer or the countless similar programs on Linux. But the words “file manager” can hardly describe the original Finder, which accompanied the Mac from its inception until the last version of Mac OS 9. It was an interface in a much deeper sense of the word. Interacting with the file system through a file manager is akin to drawing with the mouse. It works, sort of, but there’s a degree of separation between you and the drawing. Using the classic Finder, however, is like drawing directly with your hands. To the classic Macintosh user, there was no separation between the Finder and the file system.

This is why many were unhappy to see Apple abandon the classic Finder – often called the “spatial” Finder – with the release of Mac OS X, and it is why Mac OS 9 is such a joy to use even today, twenty years after its final release.

While great by default, the Finder interface can be improved even further with the use of QuicKeys and AppleScript. QuicKeys lets you define custom shortcut keys, both global and application-specific, to run arbitrary AppleScript code. Below, I share some of my favorite AppleScripts for the Finder.

Two cascaded Finder windows

Two Finder windows arranged using the Cascade script.

Read the rest of this entry »

Change the language of a specific OS X app

March 17th, 2021

When taking screenshots for this blog, I always have to temporarily change the language of whichever application I’m writing about to English, as normally my system language is Swedish. Thankfully, this is a fairly simple task.

Update: It turns out there is an easier way to do this, posted by Yanik Magnan.

All language files are located inside the application folder > Contents > Resources. (To access the application folder of any app, right-click it and choose View Contents.) Each language is represented by a folder with the extension .lproj. For example:

  • English.lproj
  • Dutch.lproj
  • fi.lproj (Finnish)
  • sv.lproj (Swedish)

If you temporarily or permanently remove any of the non-English directories, the application will use English. It is this method that I use myself to take English-language screenshots.

If you want to use another language that is not English, then you must rename the target language’s folder to the name of your system language. For example, if your system language is Swedish and you want to the application to be in Dutch:

  1. Rename sv.lproj to sv.lproj.old
  2. Rename Dutch.lproj to sv.lproj

As you cannot rename these folders in the Finder, you have to use the mv command in Terminal.

Dutch Terminal

Terminal.app in Dutch.

Restore Leopard-like Exposé in Snow Leopard

March 17th, 2021

When I switched to Mac, Exposé was one of the features that I fell in love with particularly. Switching from Windows XP, the animation alone was incredible. And it was not only a visually appealing feature, but a very useful one too. When activated, Exposé drags all the windows out from underneath one another, letting you choose freely between all open windows.

One of the reasons why Exposé was so useful was that it arranged windows in a very similar way to the way you already had them arranged. If you had Safari on the left of the screen and Terminal on the right, then Exposé would try to place them as close to their respective original positions as possible. This made it very easy to find any given window quickly: you already knew where it was, you just used Exposé to reveal it from underneath another window.

Unfortunately, Snow Leopard (10.6) kind of ruined Exposé by modifying this window arrangement algorithm. Apple changed it to arrange windows in a neat grid, where each window was given the same size. This looked clean and organized, but the relative positions between the windows was completely disregarded. The Safari window on the left could be placed at any place, left or right, in the grid according to a completely unpredictable rule.

In Mountain Lion (10.8), an option was added to restore the old window arrangement behavior, but the damage was already done, as far as many users were concerned. Having gone two entire versions of OS X without any real useful version of Exposé, people had learned to rely on other strategies to navigate their windows. And an option is worth little compared to a default.

Fortunately for Snow Leopard users, though, there is a way to restore the old Exposé! It involves copying the Dock.app from an early beta build of Snow Leopard (10A380), in which the new behavior hadn’t yet been implemented. I’ve gone through the effort and uploaded the 10A380 version of Dock.app to several places:

You can replace your stock Dock.app with this older version via Terminal, as Finder doesn’t let you replace a running application. Further instructions, including on how to make it support other languages than English, are available in my MacRumors forum post (archived).

Classic Exposé in Snow Leopard