Commit b59c7256 authored by Roland McGrath's avatar Roland McGrath
Browse files

(update-file-autoloads): Notice when searching found nothing at all.

(update-autoloads-from-directory): New function.
(batch-update-autoloads): Use it.
(update-directory-autoloads, update-autoloads-here): Functions removed.
parent c7c4ddd4
......@@ -156,6 +156,9 @@ are used."
(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
......@@ -286,7 +289,8 @@ autoloads go somewhere else.")
(save-excursion
;; We want to get a value for generated-autoload-file from
;; the local variables section if it's there.
(set-buffer (find-file-noselect file))
(if existing-buffer
(set-buffer existing-buffer))
(set-buffer (find-file-noselect generated-autoload-file))
(save-excursion
(save-restriction
......@@ -304,6 +308,7 @@ autoloads go somewhere else.")
(let ((begin (match-beginning 0))
(last-time (nth 4 form))
(file-time (nth 5 (file-attributes file))))
(message "%s: las %s vs %s" file last-time file-time)
(if (and (or (null existing-buffer)
(not (buffer-modified-p existing-buffer)))
(listp last-time) (= (length last-time) 2)
......@@ -326,106 +331,76 @@ autoloads go somewhere else.")
(goto-char (match-beginning 0))
(setq found 'new)))))
(or (eq found 'up-to-date)
(and (eq found 'new)
(and (memq found '(nil new))
;; Check that FILE has any cookies before generating a
;; new section for it.
(save-excursion
(set-buffer (find-file-noselect file))
(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
(widen)
(goto-char (point-min))
(if (search-forward (concat "\n"
generate-autoload-cookie)
nil t)
nil
(if (interactive-p)
(message file " has no autoloads"))
t))))
(save-restriction
(widen)
(goto-char (point-min))
(prog1
(if (search-forward
(concat "\n" generate-autoload-cookie)
nil t)
nil
(if (interactive-p)
(message file " has no autoloads"))
t)
(or existing-buffer
(kill-buffer (current-buffer))))))))
(generate-file-autoloads file))))
(if (interactive-p) (save-buffer))
(if (and (null existing-buffer)
(setq existing-buffer (get-file-buffer file)))
(kill-buffer existing-buffer)))))
(if (interactive-p) (save-buffer)))))
;;;###autoload
(defun update-autoloads-here ()
(defun update-autoloads-from-directory (dir)
"\
Update sections of the current buffer generated by \\[update-file-autoloads]."
(interactive)
(let ((generated-autoload-file (buffer-file-name)))
Update loaddefs.el with all the current autoloads from DIR, and no old ones.
This uses `update-file-autoloads' (which see) do its work."
(interactive "DUpdate autoloads from directory: ")
(let ((files (directory-files dir nil "^[^=].*\\.el$")))
(save-excursion
(goto-char (point-min))
(while (search-forward generate-autoload-section-header nil t)
(let* ((form (condition-case ()
(read (current-buffer))
(end-of-file nil)))
(file (nth 3 form)))
(if (and (stringp file)
(or (get-file-buffer file)
(file-exists-p file)))
()
(setq file (if (y-or-n-p (format "Can't find library `%s'; remove its autoloads? "
(nth 2 form) file))
t
(condition-case ()
(read-file-name (format "Find `%s' load file: "
(nth 2 form))
nil nil t)
(quit nil)))))
(if file
(let ((begin (match-beginning 0)))
(search-forward generate-autoload-section-trailer)
(delete-region begin (point))))
(if (stringp file)
(generate-file-autoloads file)))))))
;;;###autoload
(defun update-directory-autoloads (dir)
"Run \\[update-file-autoloads] on each .el file in DIR."
(interactive "DUpdate autoloads for directory: ")
(let ((enable-local-eval nil))
(mapcar 'update-file-autoloads
(directory-files dir t "^[^=].*\\.el$")))
(if (interactive-p)
(set-buffer (find-file-noselect
(if (file-exists-p generated-autoload-file)
generated-autoload-file
(expand-file-name generated-autoload-file
dir))))
(save-excursion
(set-buffer (find-file-noselect generated-autoload-file))
(save-buffer))))
(goto-char (point-min))
(while (search-forward generate-autoload-section-header nil t)
(let* ((form (condition-case ()
(read (current-buffer))
(end-of-file nil)))
(file (nth 3 form)))
(cond ((not (stringp file)))
((not (file-exists-p (expand-file-name file dir)))
;; Remove the obsolete section.
(let ((begin (match-beginning 0)))
(search-forward generate-autoload-section-trailer)
(delete-region begin (point))))
(t
(update-file-autoloads file)))
(setq files (delete file files)))))
;; Elements remaining in FILES have no existing autoload sections.
(mapcar 'update-file-autoloads files)
(save-buffer))))
;;;###autoload
(defun batch-update-autoloads ()
"Update the autoloads for the files or directories on the command line.
Runs \\[update-file-autoloads] on files and \\[update-directory-autoloads]
on directories. Must be used only with -batch, and kills Emacs on completion.
Each file will be processed even if an error occurred previously.
For example, invoke `emacs -batch -f batch-update-autoloads *.el'."
(if (not noninteractive)
(error "batch-update-autoloads is to be used only with -batch"))
(let ((lost nil)
(args command-line-args-left)
(enable-local-eval nil)) ;Don't query in batch mode.
(message "Updating autoloads in %s..." generated-autoload-file)
(let ((frob (function
(lambda (file)
(condition-case lossage
(update-file-autoloads file)
(error
(princ ">>Error processing ")
(princ file)
(princ ": ")
(princ (error-message-string lossage))
(princ "\n")
(setq lost t)))))))
(while args
(if (file-directory-p (expand-file-name (car args)))
(let ((rest (directory-files (car args) t "\\.el$")))
(while rest
(funcall frob (car rest))
(setq rest (cdr rest))))
(funcall frob (car args)))
(setq args (cdr args))))
(save-some-buffers t)
(message "Done")
(kill-emacs (if lost 1 0))))
"Update loaddefs.el autoloads in batch mode.
Calls `update-autoloads-from-directory' on each command line argument."
(mapcar 'update-autoloads-from-directory command-line-args-left)
(setq command-line-args-left nil))
(provide 'autoload)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment