Cleaning Up Garbage

Regular readers know that one of my New Year’s resolutions is to learn more LaTeX. I’ve been having a lot of fun learning and using AUCTeX to write LaTeX documents. I created a tex directory to hold my .tex files and the resulting PDFs. The problem with TeX is that it’s pretty noisy as far as creating intermediate files is concerned and those files mostly stick around. But, hey, this is Emacs so I thought, “I’ll just write some quick Elisp to clean things up.”

I hadn’t gotten around to that when I decided to scroll through some of abo-abo’s old posts to see if I’d missed anything. Good thing I did because it turns out that there’s already a way clean up garbage from directories. Here’s what to do:

  1. Bring up the target directory in dired1. 【Ctrl+x Ctrl+j】 is often a good way of doing this.
  2. Press 【%】【&】 to mark the “garbage” files.
  3. Press 【x】 to delete the files.

That’s all there is to it. Exactly what constitutes garbage is determined by the dired-garbage-files-regexp variable. It defaults to

"\\(?:\\.\\(?:aux\\|bak\\|dvi\\|log\\|orig\\|rej\\|toc\\)\\)\\'"

but you can customize it to include other types of temporary files you deal with. You can check out abo-abo’s post for one example of this. If you’re a neat-freak about your file system, this is good way to keep things spic and span.

UPDATE: See the comment by David McWilliams on how to do this from AUCTeX (for TeX detritus, of course). Very Handy.

Footnotes:

1

I’m using dired+ so I don’t know if this works in plain dired but you really should enable dired+. It’s much more powerful.

This entry was posted in General and tagged . Bookmark the permalink.