1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 18:40:39 -08:00

(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.
This commit is contained in:
Stefan Monnier 2007-06-23 20:31:33 +00:00
parent 917c567261
commit 3b9795200f
2 changed files with 43 additions and 26 deletions

View file

@ -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> 2007-06-23 Thien-Thi Nguyen <ttn@gnuvola.org>
* simple.el (next-error-recenter): Accept `(4)' as well; * simple.el (next-error-recenter): Accept `(4)' as well;

View file

@ -41,15 +41,18 @@
A `.el' file can set this in its local variables section to make its 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 autoloads go somewhere else. The autoload file is assumed to contain a
trailer starting with a FormFeed character.") 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. "Magic comment indicating the following form should be autoloaded.
Used by \\[update-file-autoloads]. This string should be Used by \\[update-file-autoloads]. This string should be
meaningless to Lisp (e.g., a comment). meaningless to Lisp (e.g., a comment).
This string is used: This string is used:
;;;###autoload \;;;###autoload
\(defun function-to-be-autoloaded () ...) \(defun function-to-be-autoloaded () ...)
If this string appears alone on a line, the following form will be If this string appears alone on a line, the following form will be
@ -149,6 +152,10 @@ or macro definition or a defcustom)."
;; the doc-string in FORM. ;; the doc-string in FORM.
;; Those properties are now set in lisp-mode.el. ;; 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) (defun autoload-trim-file-name (file)
;; Returns a relative file path for FILE ;; Returns a relative file path for FILE
@ -272,12 +279,14 @@ which lists the file name and which functions are in it, etc."
(defun autoload-find-file (file) (defun autoload-find-file (file)
"Fetch file and put it in a temp buffer. Return the buffer." "Fetch file and put it in a temp buffer. Return the buffer."
;; It is faster to avoid visiting the file. ;; It is faster to avoid visiting the file.
(setq file (expand-file-name file))
(with-current-buffer (get-buffer-create " *autoload-file*") (with-current-buffer (get-buffer-create " *autoload-file*")
(kill-all-local-variables) (kill-all-local-variables)
(erase-buffer) (erase-buffer)
(setq buffer-undo-list t (setq buffer-undo-list t
buffer-read-only nil) buffer-read-only nil)
(emacs-lisp-mode) (emacs-lisp-mode)
(setq default-directory (file-name-directory file))
(insert-file-contents file nil) (insert-file-contents file nil)
(let ((enable-local-variables :safe)) (let ((enable-local-variables :safe))
(hack-local-variables)) (hack-local-variables))
@ -286,6 +295,12 @@ which lists the file name and which functions are in it, etc."
(defvar no-update-autoloads nil (defvar no-update-autoloads nil
"File local variable to prevent scanning this file for autoload cookies.") "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) (defun generate-file-autoloads (file)
"Insert at point a loaddefs autoload section for FILE. "Insert at point a loaddefs autoload section for FILE.
Autoloads are generated for defuns and defmacros in FILE 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."
(interactive "fGenerate autoloads for file: ") (interactive "fGenerate autoloads for file: ")
(let ((outbuf (current-buffer)) (let ((outbuf (current-buffer))
(autoloads-done '()) (autoloads-done '())
(load-name (let ((name (file-name-nondirectory file))) (load-name (autoload-file-load-name file))
(if (string-match "\\.elc?\\(\\.\\|$\\)" name)
(substring name 0 (match-beginning 0))
name)))
(print-length nil) (print-length nil)
(print-readably t) ; This does something in Lucid Emacs. (print-readably t) ; This does something in Lucid Emacs.
(float-output-format nil) (float-output-format nil)
@ -342,6 +354,7 @@ Return non-nil in the case where no autoloads were added at point."
(skip-chars-forward " \t") (skip-chars-forward " \t")
(setq done-any t) (setq done-any t)
(if (eolp) (if (eolp)
(condition-case err
;; Read the next form and make an autoload. ;; Read the next form and make an autoload.
(let* ((form (prog1 (read (current-buffer)) (let* ((form (prog1 (read (current-buffer))
(or (bolp) (forward-line 1)))) (or (bolp) (forward-line 1))))
@ -351,6 +364,8 @@ Return non-nil in the case where no autoloads were added at point."
(setq autoload form)) (setq autoload form))
(let ((autoload-print-form-outbuf outbuf)) (let ((autoload-print-form-outbuf outbuf))
(autoload-print-form autoload))) (autoload-print-form autoload)))
(error
(message "Error in %s: %S" file err)))
;; Copy the rest of the line to the output. ;; Copy the rest of the line to the output.
(princ (buffer-substring (princ (buffer-substring
@ -397,10 +412,7 @@ save the buffer too.
Return FILE if there was no autoload cookie in it, else nil." Return FILE if there was no autoload cookie in it, else nil."
(interactive "fUpdate autoloads for file: \np") (interactive "fUpdate autoloads for file: \np")
(let ((load-name (let ((name (file-name-nondirectory file))) (let ((load-name (autoload-file-load-name file))
(if (string-match "\\.elc?\\(\\.\\|$\\)" name)
(substring name 0 (match-beginning 0))
name)))
(found nil) (found nil)
(existing-buffer (get-file-buffer file)) (existing-buffer (get-file-buffer file))
(no-autoloads nil)) (no-autoloads nil))
@ -413,10 +425,7 @@ Return FILE if there was no autoload cookie in it, else nil."
;; but still decode EOLs. ;; but still decode EOLs.
(let ((coding-system-for-read 'raw-text)) (let ((coding-system-for-read 'raw-text))
(set-buffer (find-file-noselect (set-buffer (find-file-noselect
(autoload-ensure-default-file (autoload-ensure-default-file (autoload-generated-file))))
(expand-file-name generated-autoload-file
(expand-file-name "lisp"
source-directory)))))
;; This is to make generated-autoload-file have Unix EOLs, so ;; This is to make generated-autoload-file have Unix EOLs, so
;; that it is portable to all platforms. ;; that it is portable to all platforms.
(setq buffer-file-coding-system 'raw-text-unix)) (setq buffer-file-coding-system 'raw-text-unix))
@ -500,9 +509,7 @@ directory or directories specified."
dirs))) dirs)))
(this-time (current-time)) (this-time (current-time))
(no-autoloads nil) ;files with no autoload cookies. (no-autoloads nil) ;files with no autoload cookies.
(autoloads-file (autoloads-file (autoload-generated-file))
(expand-file-name generated-autoload-file
(expand-file-name "lisp" source-directory)))
(top-dir (file-name-directory autoloads-file))) (top-dir (file-name-directory autoloads-file)))
(with-current-buffer (with-current-buffer