Emacs Window Navigation

There’s been a spate of posts lately about navigating among windows in Emacs and The Emacs Cat decided to jump in with a description of their own procedures. I like those procedures because they are essentially the same as mine.

Like The Emacs Cat, I use abo-abo’s ace-window to switch between windows and I don’t understand why anyone would use anything else. The idea is that when it’s invoked, ace-window will label each window with a number and you can then switch to any of the windows by typing requisite number. It’s easy and fast and after several years I haven’t found anything better.

Unlike The Cat, I just bind ace-window to Ctrl+x o. Most of the time it acts exactly like other-window because I typically have two windows open and in that case, ace-winodw simply gives focus to the other window. On those occasions when I have more than two windows open, moving to the correct window is only one additional keystroke. At one time, I also bound F8 to ace-window so I could switch windows even faster but I found I never used it.

I also use

:config (custom-set-faces
     '(aw-leading-char-face
       ((t (:inherit ace-jump-face-foreground :height 3.0)))))

in my use-package definition for ace-window so that the numbers on the windows are bigger.

Take it from The Emacs Cat and me. You really should be using ace-window to handle window navigation. It’s the best there is.

Posted in General | Tagged | Leave a comment

Journelly 1.1

After the official release of Journelly 1.0, Álvaro Ramírez has not been sitting on his laurels. He has a long list of feature requests from his beta testers and new users and has already released Journelly 1.1 that implements many of them. You can check his announcement for the full list but they’re mostly quality of life enhancements. For example, there’s now a hashtag picker that comes up when you push the # button. He’s also added support for 10 additional languages. There’s more—take a look at his post for the details.

One interesting aspect of his announcement is that he writes about a post from Ellane telling of her experience with Journelly. She makes two very interesting points. The first is that if you sync your Journelly files to the iCloud, you can control click on the directory to keep it always downloaded. That means you always have access to it even if you are offline.

Her second point is more important. I, and many others commenting on Journelly, have stressed that one of its strengths is its integration with Org mode. Ellane says that even if you don’t know what Org is, Journelly is an extraordinarily useful app and well worth having. I made the same point while commenting on someone else’s post but haven’t stressed it enough. My use of Journelly as a memo book would work just as well even if I weren’t an Org/Emacs user. Of course, the fact that I am an Org user makes it even better.

Let me say again that I really like this app. I’ve been using it all day, every day and its ease of use and flexibility have improved my note taking. The other day I was on a web page that I wanted to save to Journelly. I was about to capture the URL and paste it into Journelly when I noticed that Journelly was in the share menu. I just clicked on it and the entry was automatically stored into Journelly for me. What could be easier? And did I mention that I can read and edit the file in Emacs?

Update [2025-05-20 Tue 19:35]: Ramírez reminds me that when you use the share button to add a web page to Journelly, you can highlight text on the web page and that will be added to the Journelly entry along with the page’s URL.

Posted in General | Tagged | Leave a comment

A Bespoke Emacs Keyboard In Software

In response to my post on the best emacs keyboards, Paul Jorgensen has a very interesting post of how he leverages software to turn the standard Apple keyboards into Emacs specific keyboards and make them better suited to his needs outside of Emacs as well.

Oddly, he doesn’t have RSI problems so his changes are simply for keyboard efficiency. His post is interesting because it shows how far you can get with a standard, builtin keyboard through software.

Jorgensen uses a combination of Emacs configuration and Karabiner-Elements to customize his keyboard layout. It’s nowhere near what I’d want but that’s not the point. You can use his strategy to configure your keyboard to your requirements.

The lesson from all this is that you don’t (necessarily) need a special keyboard to make it amenable to Emacs or whatever else you’re using. Happily, I don’t require much more than mapping caps lock to Ctrl, choosing a key for Hyper, and choosing a key for Super. All that’s easily done from within Emacs and standard macOS.

All of this is significant because although there are now plenty of excellent third party keyboards available, many—or most—of us are using laptops as our main computers and often don’t have the option of using third party keyboards. Being able to use software to reconfigure our standard keyboards to our liking is a huge win.

If this sort of thing interests you, take a look at Jorgensen’s post. As I said, you don’t have to make the same choices that he did. His process will allow you to make just about any configuration possible.

Posted in General | Tagged | Leave a comment

Emacs 30.2 Pretest 1

Eli Zaretskii has announced that the first pretest for Emacs 30.2 is now available for testing. That’s great news. It’s nice to see that development is proceeding apace with the planned bug releases between the—more or less—yearly major releases.

As I always say, if you don’t mind living on the edge a tiny bit, download and test this new release. And as I also always say, thanks to Eli and all the other developers who give so much to our community. They’re real heroes and deserve the gratitude of us all.

Posted in General | Tagged | Leave a comment

An Org Mode Capture Template For Journelly

One of the killer features of Journelly for many of us is that Journelly’s data is stored as Org Mode markup and that this data is easily synced to the iCloud so that it can be shared among all your devices, including a Mac. That means that you can display and edit the Journelly data just like any other Org file.

It also means that you can make an Org Mode template to add entries to the file right from your Mac. When you do, the entries will show up in the Journelly app just as you’d expect. That’s significant because it means you can take Journelly notes from any of your devices.

Early on, while the app was still in beta, Jack Baty wrote about a template he was using for just this purpose. Ramírez, of course, had his own version. A limitation of both versions was that they didn’t capture the location and weather information. Baty remarked that it shouldn’t be too hard to add that and I remember thinking it was something I should do as soon as I got a chance.

It turns out that it’s a bit harder than I thought. Ramírez has a new post that shows how to do it. Part of the problem is that access to the weather APIs on the Mac require an API key and there’s apparently no easily accessible API for location so Ramírez had to use third party apps for both of these. Even so, it didn’t take much code and now he has a template that captures data and displays it in Journelly just as if it had been entered there in the first place.

If you’d like to try this out, the code is available on GitHub here.

Posted in General | Tagged | Leave a comment

Checking For A Leap Year

Wait! What? I’ve been programming most of my life and have a PhD in Mathematics but I’ve never seen this before. It’s about checking for a leap year. The first thing we all learn is that it’s a leap year if it’s divisible by 4 but that’s not quite right. It’s a bit more complicated. The usual check is something like

int is_a_leap_year( int y )
{
    if ( ( y % 4 ) != 0 ) return 0;
    if ( ( y % 100 ) != 0 ) return 1;
    if ( ( y % 400 ) == 0 ) return 1;
    return 0;
}    

Code like that has been written thousands (millions?) of times in just about every language there is.

What to make of this, then?

int is_a_leap_year( int y )
{
    return ( ( y * 1073750999 ) & 3221352463 ) <= 126976;
}

According to the link, you can make this check in 3 CPU instructions. It seems like magic but there’s a pretty good explanation of how it works at the link. Oddly enough, it’s a pretty direct translation of the normal check. Again, see the link for the details.

Checking for a leap year is not something you usually do in a loop—although it’s easy enough to imagine cases where you would—so it’s probably not a worthwhile project to replace your leap year checks with this code. Nonetheless, you have to love it if only as a curiosity.

Of course, if you’re one of those people who obsess about squeezing every cycle out of your code—I was like that when I was younger—this may seem like gold to you. If nothing else, it will confound and amaze your colleagues.

Posted in Programming | Tagged | Leave a comment

A Garbage Collection Strategy

One of the strengths—or weaknesses, depending on your point of view—of Lisp is garbage collection. That means that memory no longer in use is automatically collected and made available to the system without depending on the programmer to release it the way we do in, say, C. Of course, that comes at a cost. Garbage collection can block other operations while it’s running. That’s especially true in the single threaded Emacs.

One often sees complaints about this in the various forums. There’s all sort of advice about what to do. Some say you should set the garbage collection threshold (the amount of collectible memory) high so that garbage collection isn’t triggered as often. Of course, that means that it takes longer to collect the unused memory.

Another suggestion is to set the threshold low so that unused memory can be collected quickly. That means, though, that garbage collection is run more often. Depending on your workflow, either—or possibly both—of these strategies may work well for you.

There’s a third, arguably better, strategy: only garbage collect when the system is idle. That’s facile advice, of course, because it begs the question of how you know when the system is idle. There’s a useful heuristic. If the system has been idle for x seconds it will probably continue being idle long enough for a garbage collection cycle. The question then boils down to the proper value for x.

Jack Jamison believes x should be small and uses 1.2 seconds in his implementation of this strategy. He says that he’s had excellent results with that value. The older GCMH system uses 15 seconds.

I’ve been using GCMH was several years and can’t remember having any garbage collection issues since I started. GCHH lets you configure the idle time but the 15 second setting has been working well for me so I’m not inclined to mess with it.

In any event, if your Emacs is experiencing garbage collection delays it’s worth trying this strategy. If you want a simple prepackaged solution, GCMH is for you. If you want to keep everything in your init.el and avoid external packages, take a look at Jamison’s post to get started.

Posted in General | Tagged | Leave a comment

Unsetting Keybindings

Back before I became an Emacser, a friend who was an Emacser said that I shouldn’t worry about the Emacs keybindings because I could configure them to be whatever I want. I remember thinking that that would be disaster. After all, what would I do if I were using Emacs on someone else’s computer or even setting up a new computer.

Now, of course, I have a very individualistic configuration that makes working on someone else’s computer uncomfortable. Uncomfortable but not impossible. That’s because although I have all sorts of specialized editing commands, I’ve left the “vanilla” editing commands—cursor movements, file visiting and saving, and other standard operations—alone. That means that if I use someone else’s Emacs I can edit successfully, if not optimally, as long as the guest Emacs also didn’t mess with the standard bindings.

That’s why I’m not entirely sympathetic to The MKat’s post on how to unset default key bindings. She’s got a lot of great advice on how to delete keybindings and I agree that it’s useful information to have. My objection is to the notion that you should delete bindings that you don’t like.

Just yesterday, I discussed how modern keyboards aren’t optmal for Emacs so it’s natural to want to fix that somehow. Yesterday’s post suggests some ways of doing that but none of them involve changing default keybindings.

Sure, some folks have special needs that make one binding or another difficult but in general, I think it’s a bad idea to be messing with them. Of course, this is Emacs and everyone can adjust it to their liking. I’m not arguing with that. I’m only saying that if you stay with the defaults it will be easier for you to use an alien Emacs.

Posted in General | Tagged | Leave a comment

The Best Emacs Keyboards

Over at the Emacs subreddit, surveypoodle asks a perennial question: what are the best keyboards for Emacs? He points out that Emacs pinky seems to have appeared rather late in the editor’s history and speculates that that’s because the keyboards originally used with Emacs were better suited for it than modern keyboards that make many of the bindings awkward. He’s asking what modern keyboards are best for dealing with RSI.

If you’re interested in an answer to the question, see the comments to surveypoodle’s post. There are all sorts of suggestions. Reading through them, I realized that I didn’t care.

I used to yearn for a reincarnation of the Space Cadet keyboard—okay, I still have some vestigial urges—but I realized that these days I do virtually all my work on my laptop. I’m guessing the same is true many of us. Regardless, the use of a laptop pretty much makes the choice of a keyboard for you. Sure, you can use a third party keyboard but unless you’re always working at (the same) desk it’s just too much trouble. As I’ve said before, I do a lot of my work on the couch so an external keyboard isn’t a practical choice for me.

What to do? As much as it has become a cliche, Emacs pinky—or more generally Emacs induced RSI—is a real thing.The best solution I’ve found is some simple keyboard modifications. I’m using a MacBook Pro so keyboard firmware modifications aren’t an option. What I can do, though, is arrange for the modifier keys I use the most to be easy to reach. Two of those, Ctrl and Hyper are, configurable from within Emacs or macOS. The Meta key is bound to Alt by default so there’s nothing to do there. What all this means is that binding Ctrl to caps lock and Hyper to ⌘ Right Cmd, I can use my thumbs for Meta and Hyper and that Ctrl is an easy reach for my pinky.

I know that a lot of you are doing the same or similar things. If you’ve got a better solution, leave a comment.

Posted in General | Tagged | Leave a comment

F1 Pit Stops And Pediatic Heart Surgeons

Synergy. It’s an amazing thing. We usually view it a narrow context: synergy among members of a development team, for example but here’s a story about synergy between two very diverse groups.

The first group is a team performing pediatric heart surgery. It turns out that the journey from the OR to the ICU was itself dangerous despite the best efforts of the surgery team. One day after a two-day sprint of operations the surgeons collapsed exhausted in front of a TV and watched a Formula 1 race. One of the surgeons, Martin Elliott, was struck by the precision and teamwork of the pit crews.

That precision is something to behold. I wrote about it 11 years ago. Watch the video and be amazed. A car comes in and the car goes out two seconds later with four new tires. The action is so fast that it’s hard to follow.

Elliot wondered if those pit crews might have something to teach his team so he approached Ferrari. The Ferrari team tried to be polite but basically laughed at the hospital’s procedures. They were doing everything wrong. One example from the story is that if a critical wire came loose while transporting the baby to the ICU, the whole team would react and try to fix the problem. In contrast, each member of a pit stop crew has a well defined area of responsibility and doesn’t concern himself with anything else. The team members trust the responsible person to take care of any problem in his purview.

Together, the two teams were able to refine the surgical team’s procedures to greatly reduce the number of serious problems. Since then other hospitals have also adopted those procedures. Apparently, they always approach Ferrari skeptically but come away convinced. Read the story. It’s really interesting and inspiring. And if you haven’t seen it, watch that video of a pit crew at work. You’ll be awestruck.

Posted in General | Tagged , | Leave a comment