Some time ago there was an interesting thread on the help-gnu-emacs mailing list. Basically, the OP wanted an equivalent of save-some-buffers
, only not for all files, but for the ones under version control. More generally, he wanted to be able to programmatically get the list of buffers which visit files under VC.
Go to the discussion to read about a few things Emacs can do. One of the things I learned from it was a very general function locate-dominating-file
. You give it a directory name first and then a file name (it can be a directory, too, of course), and it walks the filesystem upwards from the given directory looking for a file with the given name. It then returns the name of directory containing that file (or nil when it doesn’t find any). One use-case is obvious: (locate-dominating-file "." ".git")
, but I’m sure there are others. Also, you can use a predicate instead of a plain filename, so that you can e.g. search for directories containing one of .hg
, .git
, or do many other things. See its docstring for the nitty-gritty.