Function: autoload-find-destination

autoload-find-destination is a byte-compiled function defined in autoload.el.gz.

Signature

(autoload-find-destination FILE LOAD-NAME OUTPUT-FILE)

Documentation

Find the destination point of the current buffer's autoloads.

FILE is the file name of the current buffer. LOAD-NAME is the name as it appears in the output. Returns a buffer whose point is placed at the requested location. Returns nil if the file's autoloads are up-to-date, otherwise removes any prior now out-of-date autoload entries.

Source Code

;; Defined in /usr/src/emacs/lisp/obsolete/autoload.el.gz
(defun autoload-find-destination (file load-name output-file)
  "Find the destination point of the current buffer's autoloads.
FILE is the file name of the current buffer.
LOAD-NAME is the name as it appears in the output.
Returns a buffer whose point is placed at the requested location.
Returns nil if the file's autoloads are up-to-date, otherwise
removes any prior now out-of-date autoload entries."
  (catch 'up-to-date
    (let* ((buf (current-buffer))
           (existing-buffer (if buffer-file-name buf))
           (output-file (autoload-generated-file output-file))
           (output-time (if (file-exists-p output-file)
                            (file-attribute-modification-time
			     (file-attributes output-file))))
           (found nil))
      (with-current-buffer (autoload-find-generated-file output-file)
        ;; This is to make generated-autoload-file have Unix EOLs, so
        ;; that it is portable to all platforms.
        (or (eq 0 (coding-system-eol-type buffer-file-coding-system))
	    (set-buffer-file-coding-system 'unix))
        (or (> (buffer-size) 0)
            (error "Autoloads file %s lacks boilerplate" buffer-file-name))
        (or (file-writable-p buffer-file-name)
            (error "Autoloads file %s is not writable" buffer-file-name))
        (widen)
        (goto-char (point-min))
        ;; Look for the section for LOAD-NAME.
        (while (and (not found)
                    (search-forward generate-autoload-section-header nil t))
          (let ((form (autoload-read-section-header)))
            (cond ((string= (nth 2 form) load-name)
                   ;; We found the section for this file.
                   ;; Check if it is up to date.
                   (let ((begin (match-beginning 0))
                         (last-time (nth 4 form))
                         (file-time (file-attribute-modification-time
				     (file-attributes file))))
                     (if (and (or (null existing-buffer)
                                  (not (buffer-modified-p existing-buffer)))
                              (cond
                               ;; FIXME? Arguably we should throw a
                               ;; user error, or some kind of warning,
                               ;; if we were called from update-file-autoloads,
                               ;; which can update only a single input file.
                               ;; It's not appropriate to use the output
                               ;; file modtime in such a case,
                               ;; if there are multiple input files
                               ;; contributing to the output.
                               ((and output-time
				     (member last-time
					     (list t autoload--non-timestamp)))
                                (not (time-less-p output-time file-time)))
                               ;; last-time is the time-stamp (specifying
                               ;; the last time we looked at the file) and
                               ;; the file hasn't been changed since.
                               ((listp last-time)
                                (not (time-less-p last-time file-time)))
                               ;; last-time is an MD5 checksum instead.
                               ((stringp last-time)
                                (equal last-time
				       (md5 buf nil nil 'emacs-mule)))))
                         (throw 'up-to-date nil)
                       (autoload-remove-section begin)
                       (setq found t))))
                  ((string< load-name (nth 2 form))
                   ;; We've come to a section alphabetically later than
                   ;; LOAD-NAME.  We assume the file is in order and so
                   ;; there must be no section for LOAD-NAME.  We will
                   ;; insert one before the section here.
                   (goto-char (match-beginning 0))
                   (setq found t)))))
        (or found
            (progn
              ;; No later sections in the file.  Put before the last page.
              (goto-char (point-max))
              (search-backward "\f" nil t)))
        (unless (memq (current-buffer) autoload-modified-buffers)
          (push (current-buffer) autoload-modified-buffers))
        (current-buffer)))))