1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-05 11:21:04 -08:00

(no-update-autoloads): Declare.

(generate-file-autoloads): Obey it.  Return whether autoloads were
added at point or not.
(update-file-autoloads): Use this new return value.
Remove redundant test for the presence of an autoload cookie.
This commit is contained in:
Stefan Monnier 2006-05-29 02:53:14 +00:00
parent 6913552560
commit b17b883963
2 changed files with 77 additions and 86 deletions

View file

@ -1,5 +1,11 @@
2006-05-28 Stefan Monnier <monnier@iro.umontreal.ca> 2006-05-28 Stefan Monnier <monnier@iro.umontreal.ca>
* emacs-lisp/autoload.el (no-update-autoloads): Declare.
(generate-file-autoloads): Obey it. Return whether autoloads were
added at point or not.
(update-file-autoloads): Use this new return value.
Remove redundant test for the presence of an autoload cookie.
* emacs-lisp/autoload.el (autoload-find-file): New fun. * emacs-lisp/autoload.el (autoload-find-file): New fun.
This one calls hack-local-variables. This one calls hack-local-variables.
(generate-file-autoloads, update-file-autoloads): Use it. (generate-file-autoloads, update-file-autoloads): Use it.

View file

@ -287,12 +287,16 @@ which lists the file name and which functions are in it, etc."
(hack-local-variables)) (hack-local-variables))
(current-buffer))) (current-buffer)))
(defvar no-update-autoloads nil
"File local variable to prevent scanning this file for autoload cookies.")
(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
marked by `generate-autoload-cookie' (which see). marked by `generate-autoload-cookie' (which see).
If FILE is being visited in a buffer, the contents of the buffer 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: ") (interactive "fGenerate autoloads for file: ")
(let ((outbuf (current-buffer)) (let ((outbuf (current-buffer))
(autoloads-done '()) (autoloads-done '())
@ -305,7 +309,7 @@ are used."
(float-output-format nil) (float-output-format nil)
(done-any nil) (done-any nil)
(visited (get-file-buffer file)) (visited (get-file-buffer file))
output-end) output-start)
;; If the autoload section we create here uses an absolute ;; If the autoload section we create here uses an absolute
;; file name for FILE in its header, and then Emacs is installed ;; file name for FILE in its header, and then Emacs is installed
@ -323,68 +327,70 @@ are used."
(string= dir-truename (substring source-truename 0 len))) (string= dir-truename (substring source-truename 0 len)))
(setq file (substring source-truename len)))) (setq file (substring source-truename len))))
(message "Generating autoloads for %s..." file) (with-current-buffer (or visited
(save-excursion ;; It is faster to avoid visiting the file.
(unwind-protect (autoload-find-file file))
(progn ;; Obey the no-update-autoloads file local variable.
(set-buffer (or visited (unless no-update-autoloads
;; It is faster to avoid visiting the file. (message "Generating autoloads for %s..." file)
(autoload-find-file file))) (setq output-start (with-current-buffer outbuf (point)))
(save-excursion (save-excursion
(save-restriction (save-restriction
(widen) (widen)
(goto-char (point-min)) (goto-char (point-min))
(while (not (eobp)) (while (not (eobp))
(skip-chars-forward " \t\n\f") (skip-chars-forward " \t\n\f")
(cond (cond
((looking-at (regexp-quote generate-autoload-cookie)) ((looking-at (regexp-quote generate-autoload-cookie))
(search-forward generate-autoload-cookie) (search-forward generate-autoload-cookie)
(skip-chars-forward " \t") (skip-chars-forward " \t")
(setq done-any t) (setq done-any t)
(if (eolp) (if (eolp)
;; 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))))
(autoload (make-autoload form load-name))) (autoload (make-autoload form load-name)))
(if autoload (if autoload
(push (nth 1 form) autoloads-done) (push (nth 1 form) autoloads-done)
(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)))
;; Copy the rest of the line to the output. ;; Copy the rest of the line to the output.
(princ (buffer-substring (princ (buffer-substring
(progn (progn
;; Back up over whitespace, to preserve it. ;; Back up over whitespace, to preserve it.
(skip-chars-backward " \f\t") (skip-chars-backward " \f\t")
(if (= (char-after (1+ (point))) ? ) (if (= (char-after (1+ (point))) ? )
;; Eat one space. ;; Eat one space.
(forward-char 1)) (forward-char 1))
(point)) (point))
(progn (forward-line 1) (point))) (progn (forward-line 1) (point)))
outbuf))) outbuf)))
((looking-at ";") ((looking-at ";")
;; Don't read the comment. ;; Don't read the comment.
(forward-line 1)) (forward-line 1))
(t (t
(forward-sexp 1) (forward-sexp 1)
(forward-line 1))))))) (forward-line 1))))))
(or visited
;; We created this buffer, so we should kill it. (when done-any
(kill-buffer (current-buffer))) (with-current-buffer outbuf
(set-buffer outbuf) (save-excursion
(setq output-end (point-marker)))) ;; Insert the section-header line which lists the file name
(if done-any ;; and which functions are in it, etc.
(progn (goto-char output-start)
;; Insert the section-header line (autoload-insert-section-header
;; which lists the file name and which functions are in it, etc. outbuf autoloads-done load-name file
(autoload-insert-section-header outbuf autoloads-done load-name file (nth 5 (file-attributes file)))
(nth 5 (file-attributes file))) (insert ";;; Generated autoloads from "
(insert ";;; Generated autoloads from " (autoload-trim-file-name file) "\n"))
(autoload-trim-file-name file) "\n") (insert generate-autoload-section-trailer)))
(goto-char output-end) (message "Generating autoloads for %s...done" file))
(insert generate-autoload-section-trailer))) (or visited
(message "Generating autoloads for %s...done" file))) ;; We created this buffer, so we should kill it.
(kill-buffer (current-buffer))))
(not done-any)))
;;;###autoload ;;;###autoload
(defun update-file-autoloads (file &optional save-after) (defun update-file-autoloads (file &optional save-after)
@ -463,28 +469,7 @@ Autoload section for %s is up to date."
(goto-char (point-max)) (goto-char (point-max))
(search-backward "\f" nil t))) (search-backward "\f" nil t)))
(or (eq found 'up-to-date) (or (eq found 'up-to-date)
(and (eq found 'new) (setq no-autoloads (generate-file-autoloads file)))))
;; Check that FILE has any cookies before generating a
;; new section for it.
(with-current-buffer
(or existing-buffer
;; It is faster to avoid visiting the file.
(autoload-find-file file))
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(prog1
(setq no-autoloads
(not (re-search-forward
(concat "^" (regexp-quote
generate-autoload-cookie))
nil t)))
(if (and no-autoloads (interactive-p))
(message "%s has no autoloads" file))
(or existing-buffer
(kill-buffer (current-buffer))))))))
(generate-file-autoloads file))))
(and save-after (and save-after
(buffer-modified-p) (buffer-modified-p)
(save-buffer)) (save-buffer))