changeset 81590:ffabac9ec014

(autoload-generated-file): New function. (update-file-autoloads, update-directory-autoloads): Use it. (autoload-file-load-name): New function. (generate-file-autoloads, update-file-autoloads): Use it. (autoload-find-file): Accept non-absolute argument. Set default-dir. (generate-file-autoloads): If the autoloaded form is malformed, indicate the problem with a warning instead of aborting.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 23 Jun 2007 20:31:33 +0000
parents cf8be6c6e026
children 33952a25e52a
files lisp/ChangeLog lisp/emacs-lisp/autoload.el
diffstat 2 files changed, 43 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Jun 23 12:38:20 2007 +0000
+++ b/lisp/ChangeLog	Sat Jun 23 20:31:33 2007 +0000
@@ -1,3 +1,13 @@
+2007-06-23  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* emacs-lisp/autoload.el (autoload-generated-file): New function.
+	(update-file-autoloads, update-directory-autoloads): Use it.
+	(autoload-file-load-name): New function.
+	(generate-file-autoloads, update-file-autoloads): Use it.
+	(autoload-find-file): Accept non-absolute argument.  Set default-dir.
+	(generate-file-autoloads): If the autoloaded form is malformed,
+	indicate the problem with a warning instead of aborting.
+
 2007-06-23  Thien-Thi Nguyen  <ttn@gnuvola.org>
 
 	* simple.el (next-error-recenter): Accept `(4)' as well;
--- a/lisp/emacs-lisp/autoload.el	Sat Jun 23 12:38:20 2007 +0000
+++ b/lisp/emacs-lisp/autoload.el	Sat Jun 23 20:31:33 2007 +0000
@@ -41,15 +41,18 @@
 A `.el' file can set this in its local variables section to make its
 autoloads go somewhere else.  The autoload file is assumed to contain a
 trailer starting with a FormFeed character.")
+(put 'generated-autoload-file 'safe-local-variable 'stringp)
 
-(defconst generate-autoload-cookie ";;;###autoload"
+;; This feels like it should be a defconst, but MH-E sets it to
+;; ";;;###mh-autoload" for the autoloads that are to go into mh-loaddefs.el.
+(defvar generate-autoload-cookie ";;;###autoload"
   "Magic comment indicating the following form should be autoloaded.
 Used by \\[update-file-autoloads].  This string should be
 meaningless to Lisp (e.g., a comment).
 
 This string is used:
 
-;;;###autoload
+\;;;###autoload
 \(defun function-to-be-autoloaded () ...)
 
 If this string appears alone on a line, the following form will be
@@ -149,6 +152,10 @@
 ;; the doc-string in FORM.
 ;; Those properties are now set in lisp-mode.el.
 
+(defun autoload-generated-file ()
+  (expand-file-name generated-autoload-file
+                    (expand-file-name "lisp"
+                                      source-directory)))
 
 (defun autoload-trim-file-name (file)
   ;; Returns a relative file path for FILE
@@ -272,12 +279,14 @@
 (defun autoload-find-file (file)
   "Fetch file and put it in a temp buffer.  Return the buffer."
   ;; It is faster to avoid visiting the file.
+  (setq file (expand-file-name file))
   (with-current-buffer (get-buffer-create " *autoload-file*")
     (kill-all-local-variables)
     (erase-buffer)
     (setq buffer-undo-list t
           buffer-read-only nil)
     (emacs-lisp-mode)
+    (setq default-directory (file-name-directory file))
     (insert-file-contents file nil)
     (let ((enable-local-variables :safe))
       (hack-local-variables))
@@ -286,6 +295,12 @@
 (defvar no-update-autoloads nil
   "File local variable to prevent scanning this file for autoload cookies.")
 
+(defun autoload-file-load-name (file)
+  (let ((name (file-name-nondirectory file)))
+    (if (string-match "\\.elc?\\(\\.\\|\\'\\)" name)
+        (substring name 0 (match-beginning 0))
+      name)))
+
 (defun generate-file-autoloads (file)
   "Insert at point a loaddefs autoload section for FILE.
 Autoloads are generated for defuns and defmacros in FILE
@@ -296,10 +311,7 @@
   (interactive "fGenerate autoloads for file: ")
   (let ((outbuf (current-buffer))
 	(autoloads-done '())
-	(load-name (let ((name (file-name-nondirectory file)))
-		     (if (string-match "\\.elc?\\(\\.\\|$\\)" name)
-			 (substring name 0 (match-beginning 0))
-		       name)))
+	(load-name (autoload-file-load-name file))
 	(print-length nil)
 	(print-readably t)		; This does something in Lucid Emacs.
 	(float-output-format nil)
@@ -342,15 +354,18 @@
                 (skip-chars-forward " \t")
                 (setq done-any t)
                 (if (eolp)
-                    ;; Read the next form and make an autoload.
-                    (let* ((form (prog1 (read (current-buffer))
-                                   (or (bolp) (forward-line 1))))
-                           (autoload (make-autoload form load-name)))
-                      (if autoload
-                          (push (nth 1 form) autoloads-done)
-                        (setq autoload form))
-                      (let ((autoload-print-form-outbuf outbuf))
-                        (autoload-print-form autoload)))
+                    (condition-case err
+                        ;; Read the next form and make an autoload.
+                        (let* ((form (prog1 (read (current-buffer))
+                                       (or (bolp) (forward-line 1))))
+                               (autoload (make-autoload form load-name)))
+                          (if autoload
+                              (push (nth 1 form) autoloads-done)
+                            (setq autoload form))
+                          (let ((autoload-print-form-outbuf outbuf))
+                            (autoload-print-form autoload)))
+                      (error
+                       (message "Error in %s: %S" file err)))
 
                   ;; Copy the rest of the line to the output.
                   (princ (buffer-substring
@@ -397,10 +412,7 @@
 
 Return FILE if there was no autoload cookie in it, else nil."
   (interactive "fUpdate autoloads for file: \np")
-  (let ((load-name (let ((name (file-name-nondirectory file)))
-		     (if (string-match "\\.elc?\\(\\.\\|$\\)" name)
-			 (substring name 0 (match-beginning 0))
-		       name)))
+  (let ((load-name (autoload-file-load-name file))
 	(found nil)
 	(existing-buffer (get-file-buffer file))
 	(no-autoloads nil))
@@ -413,10 +425,7 @@
       ;; but still decode EOLs.
       (let ((coding-system-for-read 'raw-text))
 	(set-buffer (find-file-noselect
-		     (autoload-ensure-default-file
-		      (expand-file-name generated-autoload-file
-					(expand-file-name "lisp"
-							  source-directory)))))
+		     (autoload-ensure-default-file (autoload-generated-file))))
 	;; This is to make generated-autoload-file have Unix EOLs, so
 	;; that it is portable to all platforms.
 	(setq buffer-file-coding-system 'raw-text-unix))
@@ -500,9 +509,7 @@
 			       dirs)))
 	 (this-time (current-time))
 	 (no-autoloads nil)		;files with no autoload cookies.
-	 (autoloads-file
-	  (expand-file-name generated-autoload-file
-			    (expand-file-name "lisp" source-directory)))
+	 (autoloads-file (autoload-generated-file))
 	 (top-dir (file-name-directory autoloads-file)))
 
     (with-current-buffer