;; autoload.el --- maintain autoloads in loaddefs.el
;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2001, 2002, 2003,
-;; 2004, 2005 Free Software Foundation, Inc.
+;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
;; Author: Roland McGrath <roland@gnu.org>
;; Keywords: maint
(cond
;; For complex cases, try again on the macro-expansion.
((and (memq car '(easy-mmode-define-global-mode define-global-minor-mode
+ define-globalized-minor-mode
easy-mmode-define-minor-mode define-minor-mode))
(setq expand (let ((load-file-name file)) (macroexpand form)))
(eq (car expand) 'progn)
;; For special function-like operators, use the `autoload' function.
((memq car '(defun define-skeleton defmacro define-derived-mode
- define-compilation-mode
- define-generic-mode easy-mmode-define-minor-mode
- easy-mmode-define-global-mode
- define-minor-mode defun* defmacro*))
+ define-compilation-mode define-generic-mode
+ easy-mmode-define-global-mode define-global-minor-mode
+ define-globalized-minor-mode
+ easy-mmode-define-minor-mode define-minor-mode
+ defun* defmacro*))
(let* ((macrop (memq car '(defmacro defmacro*)))
(name (nth 1 form))
(args (case car
(or (and (memq car '(define-skeleton define-derived-mode
define-generic-mode
easy-mmode-define-global-mode
+ define-global-minor-mode
+ define-globalized-minor-mode
easy-mmode-define-minor-mode
define-minor-mode)) t)
(eq (car-safe (car body)) 'interactive))
)
`(progn
(defvar ,varname ,init ,doc)
- (custom-autoload ',varname ,file)
- ;; The use of :require in a defcustom can be annoying, especially
- ;; when defcustoms are moved from one file to another between
- ;; releases because the :require arg gets placed in the user's
- ;; .emacs. In order for autoloaded minor modes not to need the
- ;; use of :require, we arrange to store their :setter.
- ,(let ((setter (condition-case nil
- (cadr (memq :set form))
- (error nil))))
- (if (equal setter ''custom-set-minor-mode)
- `(put ',varname 'custom-set 'custom-set-minor-mode))))))
+ (custom-autoload ',varname ,file
+ ,(condition-case nil
+ (null (cadr (memq :set form)))
+ (error nil))))))
+
+ ((eq car 'defgroup)
+ ;; In Emacs this is normally handled separately by cus-dep.el, but for
+ ;; third party packages, it can be convenient to explicitly autoload
+ ;; a group.
+ (let ((groupname (nth 1 form)))
+ `(let ((loads (get ',groupname 'custom-loads)))
+ (if (member ',file loads) nil
+ (put ',groupname 'custom-loads (cons ',file loads))))))
;; nil here indicates that this is not a special autoload form.
(t nil))))
(or (eolp)
(insert "\n" generate-autoload-section-continuation))))))
+(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.
+ (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)
+ (insert-file-contents file nil)
+ (let ((enable-local-variables :safe))
+ (hack-local-variables))
+ (current-buffer)))
+
+(defvar no-update-autoloads nil
+ "File local variable to prevent scanning this file for autoload cookies.")
+
(defun generate-file-autoloads (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
marked by `generate-autoload-cookie' (which see).
If FILE is being visited in a buffer, the contents of the buffer
-are used."
+are used.
+Return non-nil in the case where no autoloads were added at point."
(interactive "fGenerate autoloads for file: ")
(let ((outbuf (current-buffer))
(autoloads-done '())
(float-output-format nil)
(done-any nil)
(visited (get-file-buffer file))
- output-end)
+ output-start)
;; If the autoload section we create here uses an absolute
;; file name for FILE in its header, and then Emacs is installed
(string= dir-truename (substring source-truename 0 len)))
(setq file (substring source-truename len))))
- (message "Generating autoloads for %s..." file)
- (save-excursion
- (unwind-protect
- (progn
- (if visited
- (set-buffer visited)
- ;; It is faster to avoid visiting the file.
- (set-buffer (get-buffer-create " *generate-autoload-file*"))
- (kill-all-local-variables)
- (erase-buffer)
- (setq buffer-undo-list t
- buffer-read-only nil)
- (emacs-lisp-mode)
- (insert-file-contents file nil))
- (save-excursion
- (save-restriction
- (widen)
- (goto-char (point-min))
- (while (not (eobp))
- (skip-chars-forward " \t\n\f")
- (cond
- ((looking-at (regexp-quote generate-autoload-cookie))
- (search-forward generate-autoload-cookie)
- (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
- (setq autoloads-done (cons (nth 1 form)
- autoloads-done))
- (setq autoload form))
- (let ((autoload-print-form-outbuf outbuf))
- (autoload-print-form autoload)))
-
- ;; Copy the rest of the line to the output.
- (princ (buffer-substring
- (progn
- ;; Back up over whitespace, to preserve it.
- (skip-chars-backward " \f\t")
- (if (= (char-after (1+ (point))) ? )
- ;; Eat one space.
- (forward-char 1))
- (point))
- (progn (forward-line 1) (point)))
- outbuf)))
- ((looking-at ";")
- ;; Don't read the comment.
- (forward-line 1))
- (t
- (forward-sexp 1)
- (forward-line 1)))))))
- (or visited
- ;; We created this buffer, so we should kill it.
- (kill-buffer (current-buffer)))
- (set-buffer outbuf)
- (setq output-end (point-marker))))
- (if done-any
- (progn
- ;; Insert the section-header line
- ;; which lists the file name and which functions are in it, etc.
- (autoload-insert-section-header outbuf autoloads-done load-name file
- (nth 5 (file-attributes file)))
- (insert ";;; Generated autoloads from "
- (autoload-trim-file-name file) "\n")
- (goto-char output-end)
- (insert generate-autoload-section-trailer)))
- (message "Generating autoloads for %s...done" file)))
+ (with-current-buffer (or visited
+ ;; It is faster to avoid visiting the file.
+ (autoload-find-file file))
+ ;; Obey the no-update-autoloads file local variable.
+ (unless no-update-autoloads
+ (message "Generating autoloads for %s..." file)
+ (setq output-start (with-current-buffer outbuf (point)))
+ (save-excursion
+ (save-restriction
+ (widen)
+ (goto-char (point-min))
+ (while (not (eobp))
+ (skip-chars-forward " \t\n\f")
+ (cond
+ ((looking-at (regexp-quote generate-autoload-cookie))
+ (search-forward generate-autoload-cookie)
+ (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)))
+
+ ;; Copy the rest of the line to the output.
+ (princ (buffer-substring
+ (progn
+ ;; Back up over whitespace, to preserve it.
+ (skip-chars-backward " \f\t")
+ (if (= (char-after (1+ (point))) ? )
+ ;; Eat one space.
+ (forward-char 1))
+ (point))
+ (progn (forward-line 1) (point)))
+ outbuf)))
+ ((looking-at ";")
+ ;; Don't read the comment.
+ (forward-line 1))
+ (t
+ (forward-sexp 1)
+ (forward-line 1))))))
+
+ (when done-any
+ (with-current-buffer outbuf
+ (save-excursion
+ ;; Insert the section-header line which lists the file name
+ ;; and which functions are in it, etc.
+ (goto-char output-start)
+ (autoload-insert-section-header
+ outbuf autoloads-done load-name file
+ (nth 5 (file-attributes file)))
+ (insert ";;; Generated autoloads from "
+ (autoload-trim-file-name file) "\n"))
+ (insert generate-autoload-section-trailer)))
+ (message "Generating autoloads for %s...done" file))
+ (or visited
+ ;; We created this buffer, so we should kill it.
+ (kill-buffer (current-buffer))))
+ (not done-any)))
\f
;;;###autoload
(defun update-file-autoloads (file &optional save-after)
(goto-char (point-max))
(search-backward "\f" nil t)))
(or (eq found 'up-to-date)
- (and (eq found 'new)
- ;; Check that FILE has any cookies before generating a
- ;; new section for it.
- (save-excursion
- (if existing-buffer
- (set-buffer existing-buffer)
- ;; It is faster to avoid visiting the file.
- (set-buffer (get-buffer-create " *autoload-file*"))
- (kill-all-local-variables)
- (erase-buffer)
- (setq buffer-undo-list t
- buffer-read-only nil)
- (emacs-lisp-mode)
- (insert-file-contents file nil))
- (save-excursion
- (save-restriction
- (widen)
- (goto-char (point-min))
- (prog1
- (if (re-search-forward
- (concat "^" (regexp-quote
- generate-autoload-cookie))
- nil t)
- nil
- (if (interactive-p)
- (message "%s has no autoloads" file))
- (setq no-autoloads t)
- t)
- (or existing-buffer
- (kill-buffer (current-buffer))))))))
- (generate-file-autoloads file))))
+ (setq no-autoloads (generate-file-autoloads file)))))
(and save-after
(buffer-modified-p)
(save-buffer))
directory or directories specified."
(interactive "DUpdate autoloads from directory: ")
(let* ((files-re (let ((tmp nil))
- (dolist (suf load-suffixes
+ (dolist (suf (get-load-suffixes)
(concat "^[^=.].*" (regexp-opt tmp t) "\\'"))
(unless (string-match "\\.elc" suf) (push suf tmp)))))
(files (apply 'nconc