Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / lisp / cus-dep.el
index 10bb1ef..23f3eac 100644 (file)
@@ -1,17 +1,17 @@
 ;;; cus-dep.el --- find customization dependencies
 ;;
-;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1997, 2001-2012  Free Software Foundation, Inc.
 ;;
 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
 ;; Keywords: internal
+;; Package: emacs
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +19,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 (require 'cus-face)
 
 (defvar generated-custom-dependencies-file "cus-load.el"
-  "Output file for \\[custom-make-dependencies].")
+  "Output file for `custom-make-dependencies'.")
+
+;; See finder-no-scan-regexp in finder.el.
+(defvar custom-dependencies-no-scan-regexp "\\(^\\.#\\|\\(loaddefs\\|\
+ldefs-boot\\|cus-load\\|finder-inf\\|esh-groups\\|subdirs\\)\\.el$\\)"
+  "Regexp matching file names not to scan for `custom-make-dependencies'.")
+
+(autoload 'autoload-rubric "autoload")
 
 (defun custom-make-dependencies ()
   "Batch function to extract custom dependencies from .el files.
 Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
-  (let ((enable-local-eval nil))
-    (set-buffer (get-buffer-create " cus-dep temp"))
-    (dolist (subdir command-line-args-left)
-      (message "Directory %s" subdir)
-      (let ((files (directory-files subdir nil "\\`[^=].*\\.el\\'"))
-           (default-directory (expand-file-name subdir))
-           (preloaded (concat "\\`"
-                              (regexp-opt (mapcar
-                                           (lambda (f)
-                                             (file-name-sans-extension
-                                              (file-name-nondirectory f)))
-                                           preloaded-file-list) t)
-                              "\\.el\\'")))
-       (dolist (file files)
-         (when (and (file-exists-p file)
-                    ;; Ignore files that are preloaded.
-                    (not (string-match preloaded file)))
-           (erase-buffer)
-           (insert-file-contents file)
-           (goto-char (point-min))
-           (string-match "\\`\\(.*\\)\\.el\\'" file)
-           (let ((name (file-name-nondirectory (match-string 1 file)))
-                 (load-file-name file))
-             (if (save-excursion
-                   (re-search-forward
+  (let ((enable-local-eval nil)
+       subdir)
+    (with-temp-buffer
+      ;; Use up command-line-args-left else Emacs can try to open
+      ;; the args as directories after we are done.
+      (while (setq subdir (pop command-line-args-left))
+        (message "Directory %s" subdir)
+        (let ((files (directory-files subdir nil "\\`[^=].*\\.el\\'"))
+              (default-directory (expand-file-name subdir))
+              (preloaded (concat "\\`"
+                                 (regexp-opt (mapcar
+                                              (lambda (f)
+                                                (file-name-sans-extension
+                                                 (file-name-nondirectory f)))
+                                              preloaded-file-list) t)
+                                 "\\.el\\'")))
+          (dolist (file files)
+            (unless (or (string-match custom-dependencies-no-scan-regexp file)
+                        (string-match preloaded file)
+                        (not (file-exists-p file)))
+              (erase-buffer)
+              (insert-file-contents file)
+              (goto-char (point-min))
+              (string-match "\\`\\(.*\\)\\.el\\'" file)
+              (let ((name (file-name-nondirectory (match-string 1 file)))
+                    (load-file-name file))
+                (if (save-excursion
+                      (re-search-forward
                     (concat "(provide[ \t\n]+\\('\\|(quote[ \t\n]\\)[ \t\n]*"
                             (regexp-quote name) "[ \t\n)]")
                     nil t))
-                 (setq name (intern name)))
-             (condition-case nil
-                 (while (re-search-forward
-                         "^(def\\(custom\\|face\\|group\\)" nil t)
-                   (beginning-of-line)
-                   (let ((expr (read (current-buffer))))
-                     (condition-case nil
-                         (let ((custom-dont-initialize t))
-                           (eval expr)
-                           (put (nth 1 expr) 'custom-where name))
-                       (error nil))))
-               (error nil))))))))
+                    (setq name (intern name)))
+                (condition-case nil
+                    (while (re-search-forward
+                            "^(def\\(custom\\|face\\|group\\)" nil t)
+                      (beginning-of-line)
+                      (let ((expr (read (current-buffer))))
+                        (condition-case nil
+                            (let ((custom-dont-initialize t))
+                              (eval expr)
+                              (put (nth 1 expr) 'custom-where name))
+                          (error nil))))
+                  (error nil)))))))))
   (message "Generating %s..." generated-custom-dependencies-file)
   (set-buffer (find-file-noselect generated-custom-dependencies-file))
+  (setq buffer-undo-list t)
   (erase-buffer)
-  (insert ";;; " (file-name-nondirectory generated-custom-dependencies-file)
-      " --- automatically extracted custom dependencies
-;;\n;;; Code:
-
-")
+  (insert (autoload-rubric generated-custom-dependencies-file
+                           "custom dependencies" t))
+  (search-backward "\f")
   (mapatoms (lambda (symbol)
              (let ((members (get symbol 'custom-group))
                     where found)
@@ -162,25 +169,9 @@ Usage: emacs -batch -l ./cus-dep.el -f custom-make-dependencies DIRS"
            (if version-alist "'" ""))
     (prin1 version-alist (current-buffer))
     (insert "\n \"For internal use by custom.\")\n"))
-
-  (insert "\
-
-\(provide '" (file-name-sans-extension
-             (file-name-nondirectory generated-custom-dependencies-file)) ")
-
-;; Local Variables:
-;; version-control: never
-;; no-byte-compile: t
-;; no-update-autoloads: t
-;; End:\n;;; "
-              (file-name-nondirectory generated-custom-dependencies-file)
-              " ends here\n")
-  (let ((kept-new-versions 10000000))
-    (save-buffer))
-  (message "Generating %s...done" generated-custom-dependencies-file)
-  (kill-emacs))
+  (save-buffer)
+  (message "Generating %s...done" generated-custom-dependencies-file))
 
 \f
 
-;; arch-tag: b7b6421a-bf7a-44fd-a382-6f44976bdf68
 ;;; cus-dep.el ends here