The other day I saw this Tweet
In #Emacs, type `M-! open .` to open the directory containing the file currently in the editing buffer: https://t.co/NXBj6njdCM (on UNIX-like OSs)
— Meng Lu · Computist (@lumeng) January 21, 2022
and it reminded me of problem I had the other day: I needed to find the directory containing a file in a buffer. I was pretty sure that there was a way of doing that but I couldn’t remember what it was. There’s buffer-file-name
but it’s not interactive and I couldn’t, in any event, find it in the heat of the moment.
When I saw the Tweet, I thought that was a pretty nice way of doing it but the result is less than pleasing on a Mac because it yanks focus away from Emacs and opens a finder window. After a minute’s thought I realized that a better way is to use M-! pwd
. That lists the directory part of the path in the echo area so it’s just what I needed.