Ibuffer Filters

Ruslan Bekenev has a post on filtering the results of buffer listings that reminded me of something I’ve known since I started using Emacs but keep forgetting. Bekenev writes that he often lists the open buffers with Ctrl+x Ctrl+b mostly so that he clean up his Emacs environment by deleting no longer needed buffers. I used to do the same thing so I can sympathize with the urge.

One day, though, he wanted to filter the listing so that only buffers from his current project were listed. Sadly, list-buffers is pretty bare bones and doesn’t support filtering. Ibuffer does, though, and produces essentially the same output as list-buffers. My first thought was, “that’s neat” but I also felt that it seemed familiar.

It was, of course. Long ago when I first started using Emacs, I learned that I should use ibuffer instead of list-buffers. I last wrote about this only a year and a half ago but I’d already mostly forgotten how powerful ibuffer is. Every time I rediscover the filtering capability, I promise myself I’ll internalize and make regular use of it but the truth is I just don’t need filtering often enough for the habit to set.

In any event, ibuffer is a better version of list-buffers and well worth trying. As Mickey says in the above link, “You should switch to it right now.”

Posted in General | Tagged | Leave a comment

Prot On Ediff

Protesilaos Stavrou (Prot) has a really excellent video on Ediff. I’ve always had a difficult relationship with Ediff. It seemed really complicated with lots of obscure commands and, by default, a control panel that resides in a different frame, which didn’t play well with running Emacs full screen as I do. I’d already resolved that last problem but for those of you who haven’t, Prot shows you the secret spell.

More importantly, he demonstrates that using Ediff is actually simple if you ignore all the obscure stuff. With his configuration, the two (or three) diffed files or buffers are shown side by side and a short buffer at the bottom serves as the control panel. By default, the full panel with all the commands aren’t listed—although you can use ? to toggle it—but prot says that doesn’t matter because you hardly ever have to use that other stuff. All you really need to know is n for the next diff, p for the previous diff, and a, b, or c to move the A, B, or C diff to the other buffer(s). That’s it. It covers almost everything you ever really want to do in Ediff.

Prot also demonstrates the Magit Ediff (dwim) command that lets you see how a particular file has changed over a series of commits. It’s easy to use and invoked right from Magit.

Finally, for those who want to configure their Emacs like Prot does for Ediff, here are the two commands you need for side by side buffers and the control panel in the same frame at the bottom:

(setq ediff-window-setup-function 'ediff-setup-windows-plain)
(setq ediff-split-window-function 'split-window-horizontally)

I found this video to be really helpful. Perhaps you will too. The video is 15 minutes, 48 seconds long so you may have to schedule some time.

Posted in General | Tagged | Leave a comment

Macros Instead Of Elisp

Mario Jason Braganza has an interesting post that opened my eyes to another way of adapting Emacs to your workflow. I’m a programmer so my first impulse when I have a problem to solve with my workflow is to write a program. That works well for me. It works especially well with Emacs where it’s easy to write a quick function to sand down any friction with in my workflow.

The first thing Braganza did every morning was to manually configure Emacs to show his notes and agenda in a single frame but he wished there was a way to make this happen automatically. He realized that the easiest way to do that was to write a bit of Elisp but he had neither the the time nor the inclination to learn Elisp so he looked around for another way.

His solution was to do it by hand but record his steps as a keyboard macro. Then he could save the macro and simply replay it every morning to get his desired Emacs windows configuration. He had a couple of problems but eventually got everything working.

Like most experienced Emacs users, I often use keyboard macros to automate a one-off task but I never considered using them as a substitute for Elisp. Why would I? I can write Elisp but for those who can’t—and sometimes even for those who can—macros are a really nice way of automating some frequent task. It’s yet another way that Emacs adapts itself to its users rather than insisting those users adapt themselves to Emacs.

Posted in General | Tagged | Leave a comment

Coloring Camel Case

Marcin Borkowski (mbork) has a cute post that addresses the abomination known as camel case. I use the term camel case to cover actual camel case as well as any of its illegitimate siblings such as studly caps. As I’ve said before, it makes text hard to type and hard to read with no discernible benefit.

Someone on the Emacs mailing list suggested coloring camel case identifiers so that all the odd subwords are in one color and all the even subwords in another. Borkowski took the idea and ran with it producing a proof-of-concept mode based on glasses mode. It turned out to be easy, at least for the simple cases. One thing I learned from his post is that of version 29.1, the overlay implementation was rewritten making it faster.

For me, the takeaway from Borkowski’s post is not a way of making the horror of camel case marginally more legible. It’s about how easy Emacs makes it to implement even a seemingly difficult feature. Or for that matter, to implement it at all. As I said, I have no interest in tinkering with camel case but I love how Emacs makes it relatively simple to tinker with even the seemingly low level display features. Zamanky’s ongoing project to replace certain words with an emoji is another example of this. The emojis are displayed instead of the keywords but the underlying text is unchanged.

Overlays are a powerful technique built into Emacs that can be used in all sorts of projects as Borkowski and Zamanky demonstrate.

Posted in General | Tagged | Leave a comment

Massmapper

Martin Edström has announced a new package: massmapper. The idea is to make it easy to—for example—copy all the Ctrl– bindings to Super-. That’s a real pain if you try to do it piecemeal by hand but massmapper makes it easy.

The above is pretty much the TL;DR. To get a better idea of what it does and how it works, take a look at the README from the GitHub repository. That lists all the commands, which gives you a good idea of what’s possible.

There’s a lot of dark corners in this enterprise and judging from the README, Edström has considered them and either made allowances or documented the ones that can’t be fixed. An example of that is Ctrl+g, which is hard coded in Emacs and can’t be changed. There are a few other things like that but mostly it “just works”.

I’ve never felt the need for mass rebindings: indeed, I don’t think I rebind any keys but lots of people appear to consider it an important part of making Emacs work for them. As usual, Emacs lets you have it your way. In this case, not directly, but by making it possible to write a package to do it for you.

Posted in General | Tagged | Leave a comment

Regexp Replacers

Sandra Snan over at Idiomdrottning has posted a link to some very idiosyncratic functions that seem at first to be useless or even silly but may, on second thought, actually be useful for some applications. The idea is that they’re like replace-regexp but have the regexp predetermined. The functions are:

  • replace-word
  • replace-line
  • replace-paragraph
  • replace-var
  • replace-sentence

and they replace every instance of their target. For example, replace-word will replace every word in the target area with the substitution value. That doesn’t sound very useful but you can use & to substitute the match in the replacement. Snan has some examples in her post.

Again, these are low use functions but certain workflows may find them and the saving of entering a regexp useful.

Posted in General | Tagged | Leave a comment

Eat: A Preliminary Report

I’m running a little experiment. Even though I recently realized that I hardly ever use a terminal emulator, I was intrigued by this shoutout to the eat terminal emulator package. Except for the usual ankle biters, who don’t appear to have even used the package, the comments were all very supportive, some even saying that it significantly enhanced the commenter’s workflow.

I checked the README at the project’s GitHub repository and I was again impressed. It’s pretty speedy considering that it’s implemented in Elisp. It has several modes. One of those modes lets you move around the buffer and use the usual Emacs editing commands. That’s something that’s missing in vterm so it seems an improvement.

Installing eat is a simple one step process using the package manager. After that, you simply invoke it with Meta+x eat to start a terminal.

As I said, I don’t use terminal emulators very much anymore but I am going to try to use it as much as I can. I still have to refer to the README for the keybindings but I’m sure they’ll soon be absorbed into my muscle memory. There is, in any event, a manual (also available in Info) that covers everything. I’ll report back later with my impressions after I gain a bit more experience with it.

Posted in General | Tagged | Leave a comment

The History of Vi, Vim, and Other Vi Clones

Those of you who have been around Irreal for a while know that I never enlisted in the Vi/Emacs wars. Indeed, I have decades of experience with both and hold each in the highest regard. For a long time now, when people say “Vi”, they probably mean “Vim” so the Vi story necessarily includes that of Vim as well.

Gustavo Pezzi has a nice post on the history of Vi and Vim. Most Vi users probably know that Bill Joy extended the ex editor by giving it a “VIsual” mode but far fewer of those users know the history of Vim. It was, in fact, originally written as a port of Vi to the Commodore Amiga and “Vim” originally stood for “Vi IMitation”.

Pezzi’s post also takes a look at STEVIE and Elvis, two other Vi clones. The reason for all the clones was that Vi shared its code with ex, which was, in turn, an extension of ed, the Unix standard editor that was, technically, available only to those with an AT&T license.

Another interesting story is that Steve Kirkendall started writing Elvis after STEVIE crashed causing him to lose several hours of work. That reminded me of the old days when crashes were frequent and one of the editor mantras was “Save early and often.” Happily those days are long gone and not even the gray beards bother saving their files frequently anymore.

If you’re a Vi/Vim user or have any interest in the history of such things, take a look at Pezzi’s post. It’s an interesting trip into the past.

Posted in General | Tagged | Leave a comment

Converting UltiSnips to Yasnippet

I just ran across this reddit post about Ultyas, a utility to convert UltiSnips to YASnippet format. I was about to move on but UltiSnips stirred a distant memory so I searched Irreal and found a couple of posts that talked about it. The TL;DR is that it’s a Vim package that serves the same purpose as Emacs’ YASnippet.

The reason I wrote about it was Gilles Castel’s astounding post in which he describes taking lecture notes live in the classroom using LaTeX. His secret sauce was a series of UltiSnips snippets that expanded into the appropriate LaTeX. At the time I speculated on using his system with Emacs and YASnippet, perhaps with AUCTeX or Org.

Some of Castel’s snippets were complicated and used regular expressions as the key, which YASnippet didn’t support so a 1-to-1 translation wasn’t possible. Still, various Emacs users—Karthink in particular [1, 2]—were able to do the same thing.

If you’re a student in Mathematics or one of the hard sciences or even a professional who has to write a lot of mathematics, being able to get it into your computer as quickly as Castel or Karthink do is a real win. If you’re interested in trying this yourself and you’re an Emacs user you might want to convert Castel’s snippets to YASnippet. If so, you may find the Ultyas utility useful.

Posted in General | Tagged | Leave a comment

A Blast From The Past: Making Gnupg Work With Emacs

I was a little bored today so I thought, “I know, I’ll upgrade all the programs I’ve installed with homebrew.” There were 58 of them that were out of date so it was probably time. I fired off

brew upgade

and sat back to wait for it to complete. I was watching the results fly by and I saw gnupg being upgraded and I thought, “Damn. Now gnupg is broken again when invoked from Emacs.” That’s because Gnupg versions after 2.4.1 have a conflict with Emacs.

The solution is to downgrade to version 2.4.0 but that can be a pain if you use brew to install Gnupg. Happily Álvaro Ramírez has a quick and easy solution that I wrote about here. I searched Irreal for the post and re-downgraded Gnupg. It would be nice if there was some way of telling brew not to upgrade certain packages but in the meantime it’s pretty easy to downgrade it1.

Michael Alan Dorman commented to my original post with another, easier way of solving the problem. I haven’t tried it but if you’re experiencing the problem (on any OS) it may be worth giving it a try.

In any event, consider this a PSA for when you encounter the problem initially or subsequently like I did.

Footnotes:

1

After I wrote this I discovered that you can pin packages but I couldn’t get it to pin any version but the latest (2.4.3), which I don’t even have installed.

Posted in General | Tagged | Leave a comment