When I use Emacs for my work, I usually have dozens of buffers open: every file I edited, plus different consoles, process outputs etc. Emacs allows to handle this volume easily because it doesn’t have stupid tabs which I need to scroll and click, but instead every buffer is accessible by entering a couple of chars from its name.
The main problem I encountered is that when I’m working simultaneously on several versions of the same project, I’m starting to have many similarly named buffers. I already set up uniquify plugin to have file names prepended with directory names, but the risk of changing a file from other version of project is still high.
The obvious solution to get rid of unneeded buffers is to close Emacs and open again, but for Emacs this is analogous to OS reboot—ideally, you don’t need this. The better solution is to close all files that were opened from a specific directory. What is the easiest way to do this? As I’ve learned from Emacs wiki, the Ibuffer plugin offers a great interface for such operations.
So, how I delete all buffers that has files opened from a particular location? First, I’m opening Ibuffer:
A fancy colored table of buffers is shown. Now I’m marking buffers having a filename to satisfy a specified regular expression criteria: % f and then pressing D to delete them. That’s all!