Function: autoload-generate-file-autoloads

autoload-generate-file-autoloads is a byte-compiled function defined in autoload.el.gz.

Signature

(autoload-generate-file-autoloads FILE &optional OUTBUF OUTFILE)

Documentation

Insert an autoload section for FILE in the appropriate buffer.

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. OUTBUF is the buffer in which the autoload statements should be inserted.

If OUTBUF is nil, the output will go to OUTFILE, unless there's a buffer-local setting of generated-autoload-file in FILE.

Return non-nil if and only if FILE adds no autoloads to OUTFILE
(or OUTBUF if OUTFILE is nil). The actual return value is
FILE's modification time.

Source Code

;; Defined in /usr/src/emacs/lisp/obsolete/autoload.el.gz
(defun autoload-generate-file-autoloads (file &optional outbuf outfile)
  "Insert an autoload section for FILE in the appropriate buffer.
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.
OUTBUF is the buffer in which the autoload statements should be inserted.

If OUTBUF is nil, the output will go to OUTFILE, unless there's a
buffer-local setting of `generated-autoload-file' in FILE.

Return non-nil if and only if FILE adds no autoloads to OUTFILE
\(or OUTBUF if OUTFILE is nil).  The actual return value is
FILE's modification time."
  ;; Include the file name in any error messages
  (condition-case err
      (let (load-name
            (print-length nil)
            (print-level nil)
            (float-output-format nil)
            (visited (get-file-buffer file))
            (otherbuf nil)
            (absfile (expand-file-name file))
          (defs '())
            ;; nil until we found a cookie.
            output-start)
        (when
            (catch 'done
              (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
                  (or noninteractive (message "Generating autoloads for %s..." file))
                  (setq load-name
                        (if (stringp generated-autoload-load-name)
                            generated-autoload-load-name
                          (autoload-file-load-name absfile outfile)))
                  ;; FIXME? Comparing file-names for equality with just equal
                  ;; is fragile, eg if one has an automounter prefix and one
                  ;; does not, but both refer to the same physical file.
                  (when (and outfile
                             (not outbuf)
                             (not
                              (if (memq system-type '(ms-dos windows-nt))
                                  (equal (downcase outfile)
                                         (downcase (autoload-generated-file
                                                    outfile)))
                                (equal outfile (autoload-generated-file
                                                outfile)))))
                    (setq otherbuf t))
                  (save-excursion
                    (save-restriction
                      (widen)
                      (when autoload-builtin-package-versions
                        (let ((version (lm-header "version"))
                              package)
                          (and version
                               (setq version (ignore-errors (version-to-list version)))
                               (setq package (or (lm-header "package")
                                                 (file-name-sans-extension
                                                  (file-name-nondirectory file))))
                               (setq output-start (autoload--setup-output
                                                   otherbuf outbuf absfile
                                                   load-name outfile))
                               (let ((standard-output (marker-buffer output-start))
                                     (print-quoted t))
                                 (princ `(push ',(cons (intern package) version)
                                               package--builtin-versions))
                                 (princ "\n")))))

                      ;; Do not insert autoload entries for excluded files.
                      (unless (member absfile autoload-excludes)
                        (goto-char (point-min))
                        (while (not (eobp))
                          (skip-chars-forward " \t\n\f")
                          (cond
                           ((looking-at (regexp-quote generate-autoload-cookie))
                            ;; If not done yet, figure out where to insert this text.
                            (unless output-start
                              (setq output-start (autoload--setup-output
                                                  otherbuf outbuf absfile
                                                  load-name outfile)))
                            (autoload--print-cookie-text output-start load-name file))
                           ((= (following-char) ?\;)
                            ;; Don't read the comment.
                            (forward-line 1))
                           (t
                  ;; Avoid (defvar <foo>) by requiring a trailing space.
                  ;; Also, ignore this prefix business
                  ;; for ;;;###tramp-autoload and friends.
                  (when (and (equal generate-autoload-cookie ";;;###autoload")
                             (looking-at "(\\(def[^ ]+\\) ['(]*\\([^' ()\"\n]+\\)[\n \t]")
                             (not (member
                                   (match-string 1)
                                   autoload-ignored-definitions)))
                    (push (match-string-no-properties 2) defs))
                            (forward-sexp 1)
                            (forward-line 1)))))))

          (when (and autoload-compute-prefixes defs)
            ;; This output needs to always go in the main loaddefs.el,
            ;; regardless of generated-autoload-file.
            ;; FIXME: the files that don't have autoload cookies but
            ;; do have definitions end up listed twice in loaddefs.el:
            ;; once for their register-definition-prefixes and once in
            ;; the list of "files without any autoloads".
            (let ((form (autoload--make-defs-autoload defs load-name)))
              (cond
               ((null form))             ;All defs obey the default rule, yay!
               ((not otherbuf)
                (unless output-start
                  (setq output-start (autoload--setup-output
                                      nil outbuf absfile load-name outfile)))
                (let ((autoload-print-form-outbuf
                       (marker-buffer output-start)))
                  (autoload-print-form form)))
               (t
                (let* ((other-output-start
                        ;; To force the output to go to the main loaddefs.el
                        ;; rather than to generated-autoload-file,
                        ;; there are two cases: if outbuf is non-nil,
                        ;; then passing otherbuf=nil is enough, but if
                        ;; outbuf is nil, that won't cut it, so we
                        ;; locally bind generated-autoload-file.
                        (autoload--setup-output nil outbuf absfile load-name
                                                outfile))
                       (autoload-print-form-outbuf
                        (marker-buffer other-output-start)))
                  (autoload-print-form form)
                  (with-current-buffer (marker-buffer other-output-start)
                    (save-excursion
                      ;; Insert the section-header line which lists
                      ;; the file name and which functions are in it, etc.
                      (goto-char other-output-start)
                      (let ((relfile (file-relative-name absfile)))
                        (autoload-insert-section-header
                         (marker-buffer other-output-start)
                         "actual autoloads are elsewhere" load-name relfile
			 (if autoload-timestamps
			     (file-attribute-modification-time
			      (file-attributes absfile))
			   autoload--non-timestamp))
                        (insert ";;; Generated autoloads from " relfile "\n")))
                    (insert generate-autoload-section-trailer)))))))

                  (when output-start
                    (let ((secondary-autoloads-file-buf
                           (if otherbuf (current-buffer))))
                      (with-current-buffer (marker-buffer output-start)
                        (cl-assert (> (point) output-start))
                        (save-excursion
                          ;; Insert the section-header line which lists the file name
                          ;; and which functions are in it, etc.
                          (goto-char output-start)
                          (let ((relfile (file-relative-name absfile)))
                            (autoload-insert-section-header
                             (marker-buffer output-start)
                             () load-name relfile
                             (if secondary-autoloads-file-buf
                                 ;; MD5 checksums are much better because they do not
                                 ;; change unless the file changes (so they'll be
                                 ;; equal on two different systems and will change
                                 ;; less often than time-stamps, thus leading to fewer
                                 ;; unneeded changes causing spurious conflicts), but
                                 ;; using time-stamps is a very useful optimization,
                                 ;; so we use time-stamps for the main autoloads file
                                 ;; (loaddefs.el) where we have special ways to
                                 ;; circumvent the "random change problem", and MD5
                                 ;; checksum in secondary autoload files where we do
                                 ;; not need the time-stamp optimization because it is
                                 ;; already provided by the primary autoloads file.
                                 (md5 secondary-autoloads-file-buf
                                      ;; We'd really want to just use
                                      ;; `emacs-internal' instead.
                                      nil nil 'emacs-mule-unix)
                               (if autoload-timestamps
                                   (file-attribute-modification-time
				    (file-attributes relfile))
                                 autoload--non-timestamp)))
                            (insert ";;; Generated autoloads from " relfile "\n")))
                        (insert generate-autoload-section-trailer))))
                  (or noninteractive
                      (message "Generating autoloads for %s...done" file)))
                (or visited
                    ;; We created this buffer, so we should kill it.
                    (kill-buffer (current-buffer))))
              (or (not output-start)
                  ;; If the entries were added to some other buffer, then the file
                  ;; doesn't add entries to OUTFILE.
                  otherbuf))
          (file-attribute-modification-time (file-attributes absfile))))
    (error
     ;; Probably unbalanced parens in forward-sexp. In that case, the
     ;; condition is scan-error, and the signal data includes point
     ;; where the error was found; we'd like to convert that to
     ;; line:col, but line-number-at-pos gets the wrong line in batch
     ;; mode for some reason.
     ;;
     ;; At least this gets the file name in the error message; the
     ;; developer can use goto-char to get to the error position.
     (error "%s:0:0: error: %s: %s" file (car err) (cdr err)))
    ))