Finding the Directory of the File in a Buffer

The other day I saw this Tweet

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.

This entry was posted in General. Bookmark the permalink.