0

I use the following code in .emacs to clean the working directory from unwanted files.

(eval-after-load 'latex
  '(progn
     (setq LaTeX-clean-intermediate-suffixes (delete "\\.synctex\\.gz" LaTeX-clean-intermediate-suffixes))
     (setq LaTeX-clean-intermediate-suffixes (append
                          LaTeX-clean-intermediate-suffixes
                          (list "\\.bcf" "\\.synctex\\.gz(busy)" "-blx\\.bib" "\\.run\\.xml" "\\.fdb_latexmk" "\\.fls" "\\.ptc")))
     (setq LaTeX-clean-output-suffixes (append LaTeX-clean-output-suffixes (list "\\.synctex\\.gz")))
))

If my LaTeX document contains an error, the current directory contains a folder .t2d (I compile with texi2dvi -p from within Emacs/AUCTeX). I have to manually switch to the working directory to remove this folder as, otherwise, the document would not compile (in fact, compilation would stop with the same error [in most of the cases]). The idea is therefore to include \\.t2d in the above list of files being removed on C-c C-c Clean. However, if I do so, C-c C-c Clean says TeX-clean: Removing old name: is a directory: qrm.t2d. How can directories be removed on C-c C-c Clean?

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
Marius Hofert
  • 6,546
  • 10
  • 48
  • 102
  • Not sure what you are asking, but typically you need to remove any files and subdirectories in a directory before you can remove the directory itself. Similarly, for removing those subdirectories: remove their contents first, and so on. – Drew Jun 13 '14 at 02:33
  • 1
    I do not believe that cleaning normally includes removal of directories or sub-directories. I think you'll need a separate removal function. Something like a shell command or start-process that uses something like `rm -rf *` – lawlist Jun 13 '14 at 02:34

1 Answers1

2

The hint from lawlist's comment brought the solution. I first discovered that texi2dvi --mostly-clean already cleans a lot (including the unwanted directory .t2d). I then simply used a rm to remove further unwanted files -- everything wrapped so that I can call it via C-c C-c tidy:

(add-hook 'LaTeX-mode-hook
   (lambda ()
     ;; texi2dvi
     (add-to-list 'TeX-command-list
          '("texi2dvi" "PDFLATEX='pdflatex --shell-escape -synctex=1 -file-line-error' texi2dvi --max-iterations=5 -p %s.tex" TeX-run-command nil t :help "Run texi2dvi") t)
     ;; clean
     (add-to-list 'TeX-command-list
          '("tidy" "texi2dvi --mostly-clean %s.tex; rm %s.pdf \"%s.synctex.gz(busy)\"" TeX-run-command nil t :help "Run clean") t)
     ;; default
     (setq TeX-command-default "texi2dvi")))
Marius Hofert
  • 6,546
  • 10
  • 48
  • 102