diff options
| author | Stefan Monnier | 2007-06-23 20:31:33 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-06-23 20:31:33 +0000 |
| commit | 3b9795200fbc11c5b136b62b9ac1a70b2565da18 (patch) | |
| tree | 8f550a4e6bb6396983d52b3c60cf39f191917b07 | |
| parent | 917c567261779a3505e8ddc4c995ff2d2fd72574 (diff) | |
| download | emacs-3b9795200fbc11c5b136b62b9ac1a70b2565da18.tar.gz emacs-3b9795200fbc11c5b136b62b9ac1a70b2565da18.zip | |
(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.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/emacs-lisp/autoload.el | 59 |
2 files changed, 43 insertions, 26 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9b00e749452..75e593c1e95 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2007-06-23 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/autoload.el (autoload-generated-file): New function. | ||
| 4 | (update-file-autoloads, update-directory-autoloads): Use it. | ||
| 5 | (autoload-file-load-name): New function. | ||
| 6 | (generate-file-autoloads, update-file-autoloads): Use it. | ||
| 7 | (autoload-find-file): Accept non-absolute argument. Set default-dir. | ||
| 8 | (generate-file-autoloads): If the autoloaded form is malformed, | ||
| 9 | indicate the problem with a warning instead of aborting. | ||
| 10 | |||
| 1 | 2007-06-23 Thien-Thi Nguyen <ttn@gnuvola.org> | 11 | 2007-06-23 Thien-Thi Nguyen <ttn@gnuvola.org> |
| 2 | 12 | ||
| 3 | * simple.el (next-error-recenter): Accept `(4)' as well; | 13 | * simple.el (next-error-recenter): Accept `(4)' as well; |
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el index 5e37e275632..47d167eeecc 100644 --- a/lisp/emacs-lisp/autoload.el +++ b/lisp/emacs-lisp/autoload.el | |||
| @@ -41,15 +41,18 @@ | |||
| 41 | A `.el' file can set this in its local variables section to make its | 41 | A `.el' file can set this in its local variables section to make its |
| 42 | autoloads go somewhere else. The autoload file is assumed to contain a | 42 | autoloads go somewhere else. The autoload file is assumed to contain a |
| 43 | trailer starting with a FormFeed character.") | 43 | trailer starting with a FormFeed character.") |
| 44 | (put 'generated-autoload-file 'safe-local-variable 'stringp) | ||
| 44 | 45 | ||
| 45 | (defconst generate-autoload-cookie ";;;###autoload" | 46 | ;; This feels like it should be a defconst, but MH-E sets it to |
| 47 | ;; ";;;###mh-autoload" for the autoloads that are to go into mh-loaddefs.el. | ||
| 48 | (defvar generate-autoload-cookie ";;;###autoload" | ||
| 46 | "Magic comment indicating the following form should be autoloaded. | 49 | "Magic comment indicating the following form should be autoloaded. |
| 47 | Used by \\[update-file-autoloads]. This string should be | 50 | Used by \\[update-file-autoloads]. This string should be |
| 48 | meaningless to Lisp (e.g., a comment). | 51 | meaningless to Lisp (e.g., a comment). |
| 49 | 52 | ||
| 50 | This string is used: | 53 | This string is used: |
| 51 | 54 | ||
| 52 | ;;;###autoload | 55 | \;;;###autoload |
| 53 | \(defun function-to-be-autoloaded () ...) | 56 | \(defun function-to-be-autoloaded () ...) |
| 54 | 57 | ||
| 55 | If this string appears alone on a line, the following form will be | 58 | If this string appears alone on a line, the following form will be |
| @@ -149,6 +152,10 @@ or macro definition or a defcustom)." | |||
| 149 | ;; the doc-string in FORM. | 152 | ;; the doc-string in FORM. |
| 150 | ;; Those properties are now set in lisp-mode.el. | 153 | ;; Those properties are now set in lisp-mode.el. |
| 151 | 154 | ||
| 155 | (defun autoload-generated-file () | ||
| 156 | (expand-file-name generated-autoload-file | ||
| 157 | (expand-file-name "lisp" | ||
| 158 | source-directory))) | ||
| 152 | 159 | ||
| 153 | (defun autoload-trim-file-name (file) | 160 | (defun autoload-trim-file-name (file) |
| 154 | ;; Returns a relative file path for FILE | 161 | ;; Returns a relative file path for FILE |
| @@ -272,12 +279,14 @@ which lists the file name and which functions are in it, etc." | |||
| 272 | (defun autoload-find-file (file) | 279 | (defun autoload-find-file (file) |
| 273 | "Fetch file and put it in a temp buffer. Return the buffer." | 280 | "Fetch file and put it in a temp buffer. Return the buffer." |
| 274 | ;; It is faster to avoid visiting the file. | 281 | ;; It is faster to avoid visiting the file. |
| 282 | (setq file (expand-file-name file)) | ||
| 275 | (with-current-buffer (get-buffer-create " *autoload-file*") | 283 | (with-current-buffer (get-buffer-create " *autoload-file*") |
| 276 | (kill-all-local-variables) | 284 | (kill-all-local-variables) |
| 277 | (erase-buffer) | 285 | (erase-buffer) |
| 278 | (setq buffer-undo-list t | 286 | (setq buffer-undo-list t |
| 279 | buffer-read-only nil) | 287 | buffer-read-only nil) |
| 280 | (emacs-lisp-mode) | 288 | (emacs-lisp-mode) |
| 289 | (setq default-directory (file-name-directory file)) | ||
| 281 | (insert-file-contents file nil) | 290 | (insert-file-contents file nil) |
| 282 | (let ((enable-local-variables :safe)) | 291 | (let ((enable-local-variables :safe)) |
| 283 | (hack-local-variables)) | 292 | (hack-local-variables)) |
| @@ -286,6 +295,12 @@ which lists the file name and which functions are in it, etc." | |||
| 286 | (defvar no-update-autoloads nil | 295 | (defvar no-update-autoloads nil |
| 287 | "File local variable to prevent scanning this file for autoload cookies.") | 296 | "File local variable to prevent scanning this file for autoload cookies.") |
| 288 | 297 | ||
| 298 | (defun autoload-file-load-name (file) | ||
| 299 | (let ((name (file-name-nondirectory file))) | ||
| 300 | (if (string-match "\\.elc?\\(\\.\\|\\'\\)" name) | ||
| 301 | (substring name 0 (match-beginning 0)) | ||
| 302 | name))) | ||
| 303 | |||
| 289 | (defun generate-file-autoloads (file) | 304 | (defun generate-file-autoloads (file) |
| 290 | "Insert at point a loaddefs autoload section for FILE. | 305 | "Insert at point a loaddefs autoload section for FILE. |
| 291 | Autoloads are generated for defuns and defmacros in FILE | 306 | Autoloads are generated for defuns and defmacros in FILE |
| @@ -296,10 +311,7 @@ Return non-nil in the case where no autoloads were added at point." | |||
| 296 | (interactive "fGenerate autoloads for file: ") | 311 | (interactive "fGenerate autoloads for file: ") |
| 297 | (let ((outbuf (current-buffer)) | 312 | (let ((outbuf (current-buffer)) |
| 298 | (autoloads-done '()) | 313 | (autoloads-done '()) |
| 299 | (load-name (let ((name (file-name-nondirectory file))) | 314 | (load-name (autoload-file-load-name file)) |
| 300 | (if (string-match "\\.elc?\\(\\.\\|$\\)" name) | ||
| 301 | (substring name 0 (match-beginning 0)) | ||
| 302 | name))) | ||
| 303 | (print-length nil) | 315 | (print-length nil) |
| 304 | (print-readably t) ; This does something in Lucid Emacs. | 316 | (print-readably t) ; This does something in Lucid Emacs. |
| 305 | (float-output-format nil) | 317 | (float-output-format nil) |
| @@ -342,15 +354,18 @@ Return non-nil in the case where no autoloads were added at point." | |||
| 342 | (skip-chars-forward " \t") | 354 | (skip-chars-forward " \t") |
| 343 | (setq done-any t) | 355 | (setq done-any t) |
| 344 | (if (eolp) | 356 | (if (eolp) |
| 345 | ;; Read the next form and make an autoload. | 357 | (condition-case err |
| 346 | (let* ((form (prog1 (read (current-buffer)) | 358 | ;; Read the next form and make an autoload. |
| 347 | (or (bolp) (forward-line 1)))) | 359 | (let* ((form (prog1 (read (current-buffer)) |
| 348 | (autoload (make-autoload form load-name))) | 360 | (or (bolp) (forward-line 1)))) |
| 349 | (if autoload | 361 | (autoload (make-autoload form load-name))) |
| 350 | (push (nth 1 form) autoloads-done) | 362 | (if autoload |
| 351 | (setq autoload form)) | 363 | (push (nth 1 form) autoloads-done) |
| 352 | (let ((autoload-print-form-outbuf outbuf)) | 364 | (setq autoload form)) |
| 353 | (autoload-print-form autoload))) | 365 | (let ((autoload-print-form-outbuf outbuf)) |
| 366 | (autoload-print-form autoload))) | ||
| 367 | (error | ||
| 368 | (message "Error in %s: %S" file err))) | ||
| 354 | 369 | ||
| 355 | ;; Copy the rest of the line to the output. | 370 | ;; Copy the rest of the line to the output. |
| 356 | (princ (buffer-substring | 371 | (princ (buffer-substring |
| @@ -397,10 +412,7 @@ save the buffer too. | |||
| 397 | 412 | ||
| 398 | Return FILE if there was no autoload cookie in it, else nil." | 413 | Return FILE if there was no autoload cookie in it, else nil." |
| 399 | (interactive "fUpdate autoloads for file: \np") | 414 | (interactive "fUpdate autoloads for file: \np") |
| 400 | (let ((load-name (let ((name (file-name-nondirectory file))) | 415 | (let ((load-name (autoload-file-load-name file)) |
| 401 | (if (string-match "\\.elc?\\(\\.\\|$\\)" name) | ||
| 402 | (substring name 0 (match-beginning 0)) | ||
| 403 | name))) | ||
| 404 | (found nil) | 416 | (found nil) |
| 405 | (existing-buffer (get-file-buffer file)) | 417 | (existing-buffer (get-file-buffer file)) |
| 406 | (no-autoloads nil)) | 418 | (no-autoloads nil)) |
| @@ -413,10 +425,7 @@ Return FILE if there was no autoload cookie in it, else nil." | |||
| 413 | ;; but still decode EOLs. | 425 | ;; but still decode EOLs. |
| 414 | (let ((coding-system-for-read 'raw-text)) | 426 | (let ((coding-system-for-read 'raw-text)) |
| 415 | (set-buffer (find-file-noselect | 427 | (set-buffer (find-file-noselect |
| 416 | (autoload-ensure-default-file | 428 | (autoload-ensure-default-file (autoload-generated-file)))) |
| 417 | (expand-file-name generated-autoload-file | ||
| 418 | (expand-file-name "lisp" | ||
| 419 | source-directory))))) | ||
| 420 | ;; This is to make generated-autoload-file have Unix EOLs, so | 429 | ;; This is to make generated-autoload-file have Unix EOLs, so |
| 421 | ;; that it is portable to all platforms. | 430 | ;; that it is portable to all platforms. |
| 422 | (setq buffer-file-coding-system 'raw-text-unix)) | 431 | (setq buffer-file-coding-system 'raw-text-unix)) |
| @@ -500,9 +509,7 @@ directory or directories specified." | |||
| 500 | dirs))) | 509 | dirs))) |
| 501 | (this-time (current-time)) | 510 | (this-time (current-time)) |
| 502 | (no-autoloads nil) ;files with no autoload cookies. | 511 | (no-autoloads nil) ;files with no autoload cookies. |
| 503 | (autoloads-file | 512 | (autoloads-file (autoload-generated-file)) |
| 504 | (expand-file-name generated-autoload-file | ||
| 505 | (expand-file-name "lisp" source-directory))) | ||
| 506 | (top-dir (file-name-directory autoloads-file))) | 513 | (top-dir (file-name-directory autoloads-file))) |
| 507 | 514 | ||
| 508 | (with-current-buffer | 515 | (with-current-buffer |