As mentioned on the general mailing list I had a little bit of code
for cleaning generated files I wanted to generalize.  Attached you can
find a patch showing what has become of it.

There are a few things which may be worth discussing:

I decided to use regular expressions for matching suffixes of files to
be deleted in order to be able to support stuff like makeinfo
splitting info files or texi2html splitting HTML files.  The resulting
customization options may not be easily understandable by users not
familiar with regular expressions.  Consequently we could provide the
option to use a list of suffixes instead of a regular expression and
use such a list in the "easy" cases like (La)TeX and ConTeXt modes as
default.

The word "Clean" in the command list shadows "Check" and "ConTeXt".
"Purge" would shadow "Print".  Any better suggestions?

Calling `TeX-clean' from `TeX-command-list' is accomplished with a
dedicated wrapper function `TeX-run-clean' similar to how we do it
with `TeX-run-ispell'.  I don't really like to introduce another
special case, so how about making it possible that the second element
of an item in `TeX-command-list' can be a function which will be
called by a hypothetical `TeX-run-function' function?  For example for
"Clean" you could have
("Clean" TeX-clean TeX-run-function nil t :help "Remove generated files")
and for "Spell"
("Spell" (lambda () (TeX-ispell-document "")) TeX-run-function nil t
 :help "Spell-check the document")
Note that this is just an idea, I still have to check if this will
actually work.

-- 
Ralf
Index: context.el
===================================================================
RCS file: /cvsroot/auctex/auctex/context.el,v
retrieving revision 1.53
diff -u -r1.53 context.el
--- context.el	21 Jun 2005 18:54:52 -0000	1.53
+++ context.el	5 Feb 2006 14:48:25 -0000
@@ -1406,6 +1406,14 @@
 		       ConTeXt-section-block-list ConTeXt-section-list
 		       ConTeXt-text ConTeXt-item-list))
 
+(defcustom ConTeXt-clean-suffix-regexp
+  ;; See *suffixes in texutil.pl.
+  "\\(\\.\\(tui\\|tup\\|ted\\|tes\\|top\\|log\\|tmp\\|run\\|bck\\|rlg\\|\
+mpt\\|mpx\\|mpd\\|mpo\\|dvi\\|pdf\\|ps\\|tuo\\|tub\\|top\\)\\|\
+-\\(mpgraph\\.mp[doy]?\\|mprun\\.mp[doy]?\\)\\)\\'"
+  "Regexp matching the suffixes of generated files to be cleaned."
+  :type 'regexp
+  :group 'TeX-command)
 
 (defun ConTeXt-mode-common-initialization ()
   "Initialization code that is common for all ConTeXt interfaces."
Index: latex.el
===================================================================
RCS file: /cvsroot/auctex/auctex/latex.el,v
retrieving revision 5.398
diff -u -r5.398 latex.el
--- latex.el	3 Feb 2006 15:37:14 -0000	5.398
+++ latex.el	5 Feb 2006 14:48:26 -0000
@@ -4725,6 +4725,11 @@
 ;;;###autoload
 (defalias 'TeX-doctex-mode 'docTeX-mode)
 
+(defcustom docTeX-clean-suffix-regexp TeX-clean-default-suffix-regexp
+  "Regexp matching the suffixes of generated files to be cleaned."
+  :type 'regexp
+  :group 'TeX-command)
+
 (defvar LaTeX-header-end
   (concat "^[^%\n]*" (regexp-quote TeX-esc) "begin *"
 	  TeX-grop "document" TeX-grcl)
@@ -4735,6 +4740,11 @@
 	  TeX-grop "document" TeX-grcl)
   "Default start of trailer marker for LaTeX documents.")
 
+(defcustom LaTeX-clean-suffix-regexp TeX-clean-default-suffix-regexp
+  "Regexp matching the suffixes of generated files to be cleaned."
+  :type 'regexp
+  :group 'TeX-command)
+
 (defun LaTeX-common-initialization ()
   "Common initialization for LaTeX derived modes."
   (VirTeX-common-initialization)
Index: tex-buf.el
===================================================================
RCS file: /cvsroot/auctex/auctex/tex-buf.el,v
retrieving revision 1.244
diff -u -r1.244 tex-buf.el
--- tex-buf.el	28 Jan 2006 12:50:53 -0000	1.244
+++ tex-buf.el	5 Feb 2006 14:48:26 -0000
@@ -757,6 +757,11 @@
     ;; use the sentinel-function that the major mode sets, not the LaTeX one
     (setq TeX-sentinel-function sentinel-function)))
 
+(defun TeX-run-clean (&rest ignored)
+  "Wrapper function for `TeX-clean' to be called via `TeX-command-*'."
+  (TeX-clean))
+
+
 ;;; Command Sentinels
 
 (defun TeX-synchronous-sentinel (name file result)
Index: tex-info.el
===================================================================
RCS file: /cvsroot/auctex/auctex/tex-info.el,v
retrieving revision 5.151
diff -u -r5.151 tex-info.el
--- tex-info.el	5 Dec 2005 10:51:03 -0000	5.151
+++ tex-info.el	5 Feb 2006 14:48:26 -0000
@@ -535,6 +535,14 @@
   
   (TeX-run-mode-hooks 'text-mode-hook 'Texinfo-mode-hook)
   (TeX-set-mode-name))
+
+(defcustom Texinfo-clean-suffix-regexp
+  ;; See `man texi2html' for the HTML stuff.
+  "\\(\\.\\(info\\(-[0-9]+\\)?\\|dvi\\|html\\|pdf\\|ps\\)\\|\
+_\\(\\(toc\\|fot\\|abt\\|[0-9]+\\)\\.html\\|l2h_img.+\\)\\)\\'"
+  "Regexp matching the suffixes of generated files to be cleaned."
+  :type 'regexp
+  :group 'TeX-command)
   
 (provide 'tex-info)
   
Index: tex.el
===================================================================
RCS file: /cvsroot/auctex/auctex/tex.el,v
retrieving revision 5.557
diff -u -r5.557 tex.el
--- tex.el	28 Jan 2006 12:50:35 -0000	5.557
+++ tex.el	5 Feb 2006 14:48:26 -0000
@@ -178,10 +178,6 @@
     ("ConTeXt Full" "texexec %(execopts)%t"
      TeX-run-TeX nil
      (context-mode) :help "Run ConTeXt until completion")
-    ;; --purge %s does not work on unix systems with current texutil
-    ;; check again october 2003 --pg
-    ("ConTeXt Clean" "texutil --purgeall" TeX-run-interactive nil
-     (context-mode) :help "Clean temporary ConTeXt files")
     ("BibTeX" "bibtex %s" TeX-run-BibTeX nil t :help "Run BibTeX")
     ,(if (or window-system (getenv "DISPLAY"))
 	'("View" "%V" TeX-run-discard t t :help "Run Viewer")
@@ -197,6 +193,7 @@
      :help "Check LaTeX file for correctness")
     ("Spell" "<ignored>" TeX-run-ispell-on-document nil t
      :help "Spell-check the document")
+    ("Clean" "<ignored>" TeX-run-clean nil t :help "Remove generated files")
     ("Other" "" TeX-run-command t t :help "Run an arbitrary command"))
   "List of commands to execute on the current document.
 
@@ -1182,6 +1179,29 @@
 
  (make-variable-buffer-local 'TeX-command-default)
 
+(defvar TeX-clean-default-suffix-regexp
+  "\\.\\(aux\\|bbl\\|blg\\|dvi\\|fot\\|glo\\|gls\\|lof\\|idx\\|ilg\\|ind\\|\
+log\\|lot\\|pdf\\|ps\\|toc\\|url\\)\\'"
+  "Regexp matching the suffixes of files to be cleaned.
+Used as a default in TeX, LaTeX and docTeX mode.")
+
+(defun TeX-clean ()
+  "Delete generated files associated with current master file."
+  (interactive)
+  (when (y-or-n-p "Delete generated files? ")
+    (let* ((mode-prefixes '((plain-tex-mode . "plain-TeX")
+			    (latex-mode . "LaTeX")
+			    (doctex-mode . "docTeX")
+			    (texinfo-mode . "Texinfo")
+			    (context-mode . "ConTeXt")))
+	   (regexp (symbol-value (intern (concat (cdr (assoc major-mode
+							     mode-prefixes))
+						 "-clean-suffix-regexp"))))
+	   (files (directory-files "." nil (concat (TeX-active-master nil t)
+						   regexp))))
+      (dolist (file files)
+	(delete-file file)))))
+
 
 ;;; Master File
 
_______________________________________________
auctex-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/auctex-devel

Reply via email to