comparison lisp/emacs-lisp/autoload.el @ 81623:835baa7a130c

(autoload-generated-file): Interpret names relative to current dir for file-local settings. (autoload-generate-file-autoloads): Add `outfile' arg. (update-directory-autoloads): Use it to directly call autoload-generate-file-autoloads instead of going through update-file-autoloads so we avoid redundant searches and so we can know the set of buffers changed so we can save them all.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 26 Jun 2007 19:53:12 +0000
parents 9d32dd7131c3
children 6416cbdef0fa
comparison
equal deleted inserted replaced
81622:9d32dd7131c3 81623:835baa7a130c
154 ;; the doc-string in FORM. 154 ;; the doc-string in FORM.
155 ;; Those properties are now set in lisp-mode.el. 155 ;; Those properties are now set in lisp-mode.el.
156 156
157 (defun autoload-generated-file () 157 (defun autoload-generated-file ()
158 (expand-file-name generated-autoload-file 158 (expand-file-name generated-autoload-file
159 (expand-file-name "lisp" 159 ;; File-local settings of generated-autoload-file should
160 source-directory))) 160 ;; be interpreted relative to the file's location,
161 ;; of course.
162 (if (not (local-variable-p 'generated-autoload-file))
163 (expand-file-name "lisp" source-directory))))
164
161 165
162 (defun autoload-read-section-header () 166 (defun autoload-read-section-header ()
163 "Read a section header form. 167 "Read a section header form.
164 Since continuation lines have been marked as comments, 168 Since continuation lines have been marked as comments,
165 we must copy the text of the form and remove those comment 169 we must copy the text of the form and remove those comment
299 are used. 303 are used.
300 Return non-nil in the case where no autoloads were added at point." 304 Return non-nil in the case where no autoloads were added at point."
301 (interactive "fGenerate autoloads for file: ") 305 (interactive "fGenerate autoloads for file: ")
302 (autoload-generate-file-autoloads file (current-buffer))) 306 (autoload-generate-file-autoloads file (current-buffer)))
303 307
304 (defun autoload-generate-file-autoloads (file &optional outbuf) 308 ;; When called from `generate-file-autoloads' we should ignore
309 ;; `generated-autoload-file' altogether. When called from
310 ;; `update-file-autoloads' we don't know `outbuf'. And when called from
311 ;; `update-directory-autoloads' it's in between: we know the default
312 ;; `outbuf' but we should obey any file-local setting of
313 ;; `generated-autoload-file'.
314 (defun autoload-generate-file-autoloads (file &optional outbuf outfile)
305 "Insert an autoload section for FILE in the appropriate buffer. 315 "Insert an autoload section for FILE in the appropriate buffer.
306 Autoloads are generated for defuns and defmacros in FILE 316 Autoloads are generated for defuns and defmacros in FILE
307 marked by `generate-autoload-cookie' (which see). 317 marked by `generate-autoload-cookie' (which see).
308 If FILE is being visited in a buffer, the contents of the buffer are used. 318 If FILE is being visited in a buffer, the contents of the buffer are used.
309 OUTBUF is the buffer in which the autoload statements will be inserted. 319 OUTBUF is the buffer in which the autoload statements should be inserted.
310 If OUTBUF is nil, it will be determined by `autoload-generated-file'. 320 If OUTBUF is nil, it will be determined by `autoload-generated-file'.
311 321
312 Return non-nil iff FILE adds no autoloads to OUTBUF." 322 If provided, OUTFILE is expected to be the file name of OUTBUF.
323 If OUTFILE is non-nil and FILE specifies a `generated-autoload-file'
324 different from OUTFILE, then OUTBUF is ignored.
325
326 Return non-nil iff FILE adds no autoloads to OUTFILE
327 \(or OUTBUF if OUTFILE is nil)."
313 (catch 'done 328 (catch 'done
314 (let ((autoloads-done '()) 329 (let ((autoloads-done '())
315 (load-name (autoload-file-load-name file)) 330 (load-name (autoload-file-load-name file))
316 (print-length nil) 331 (print-length nil)
317 (print-readably t) ; This does something in Lucid Emacs. 332 (print-readably t) ; This does something in Lucid Emacs.
318 (float-output-format nil) 333 (float-output-format nil)
319 (visited (get-file-buffer file)) 334 (visited (get-file-buffer file))
335 (otherbuf nil)
320 (absfile (expand-file-name file)) 336 (absfile (expand-file-name file))
321 relfile 337 relfile
322 ;; nil until we found a cookie. 338 ;; nil until we found a cookie.
323 output-start) 339 output-start)
324 340
336 (skip-chars-forward " \t\n\f") 352 (skip-chars-forward " \t\n\f")
337 (cond 353 (cond
338 ((looking-at (regexp-quote generate-autoload-cookie)) 354 ((looking-at (regexp-quote generate-autoload-cookie))
339 ;; If not done yet, figure out where to insert this text. 355 ;; If not done yet, figure out where to insert this text.
340 (unless output-start 356 (unless output-start
357 (when (and outfile
358 (not (equal outfile (autoload-generated-file))))
359 ;; A file-local setting of autoload-generated-file says
360 ;; we should ignore OUTBUF.
361 (setq outbuf nil)
362 (setq otherbuf t))
341 (unless outbuf 363 (unless outbuf
342 (setq outbuf (autoload-find-destination absfile)) 364 (setq outbuf (autoload-find-destination absfile))
343 (unless outbuf 365 (unless outbuf
344 ;; The file has autoload cookies, but they're 366 ;; The file has autoload cookies, but they're
345 ;; already up-to-date. 367 ;; already up-to-date. If OUTFILE is nil, the
346 (throw 'done t))) 368 ;; entries are in the expected OUTBUF, otherwise
369 ;; they're elsewhere.
370 (throw 'done outfile)))
347 (with-current-buffer outbuf 371 (with-current-buffer outbuf
348 (setq relfile (file-relative-name absfile)) 372 (setq relfile (file-relative-name absfile))
349 (setq output-start (point))) 373 (setq output-start (point)))
350 ;; (message "file=%S, relfile=%S, dest=%S" 374 ;; (message "file=%S, relfile=%S, dest=%S"
351 ;; file relfile (autoload-generated-file)) 375 ;; file relfile (autoload-generated-file))
397 (insert generate-autoload-section-trailer))) 421 (insert generate-autoload-section-trailer)))
398 (message "Generating autoloads for %s...done" file)) 422 (message "Generating autoloads for %s...done" file))
399 (or visited 423 (or visited
400 ;; We created this buffer, so we should kill it. 424 ;; We created this buffer, so we should kill it.
401 (kill-buffer (current-buffer)))) 425 (kill-buffer (current-buffer))))
402 (not output-start)))) 426 ;; If the entries were added to some other buffer, then the file
427 ;; doesn't add entries to OUTFILE.
428 (or (not output-start) otherbuf))))
403 429
404 (defun autoload-save-buffers () 430 (defun autoload-save-buffers ()
405 (while autoload-modified-buffers 431 (while autoload-modified-buffers
406 (with-current-buffer (pop autoload-modified-buffers) 432 (with-current-buffer (pop autoload-modified-buffers)
407 (save-buffer)))) 433 (save-buffer))))
509 (mapcar (lambda (dir) 535 (mapcar (lambda (dir)
510 (directory-files (expand-file-name dir) 536 (directory-files (expand-file-name dir)
511 t files-re)) 537 t files-re))
512 dirs))) 538 dirs)))
513 (this-time (current-time)) 539 (this-time (current-time))
514 (no-autoloads nil) ;files with no autoload cookies. 540 ;; Files with no autoload cookies or whose autoloads go to other
515 (autoloads-file (autoload-generated-file)) 541 ;; files because of file-local autoload-generated-file settings.
516 (top-dir (file-name-directory autoloads-file))) 542 (no-autoloads nil)
543 (autoload-modified-buffers nil))
517 544
518 (with-current-buffer 545 (with-current-buffer
519 (find-file-noselect (autoload-ensure-default-file autoloads-file)) 546 (find-file-noselect
547 (autoload-ensure-default-file (autoload-generated-file)))
520 (save-excursion 548 (save-excursion
521 549
522 ;; Canonicalize file names and remove the autoload file itself. 550 ;; Canonicalize file names and remove the autoload file itself.
523 (setq files (delete (file-relative-name buffer-file-name) 551 (setq files (delete (file-relative-name buffer-file-name)
524 (mapcar 'file-relative-name files))) 552 (mapcar 'file-relative-name files)))
539 (not (time-less-p last-time file-time))) 567 (not (time-less-p last-time file-time)))
540 ;; file unchanged 568 ;; file unchanged
541 (push file no-autoloads) 569 (push file no-autoloads)
542 (setq files (delete file files))))))) 570 (setq files (delete file files)))))))
543 ((not (stringp file))) 571 ((not (stringp file)))
544 ((not (file-exists-p (expand-file-name file top-dir))) 572 ((not (file-exists-p file))
545 ;; Remove the obsolete section. 573 ;; Remove the obsolete section.
546 (autoload-remove-section (match-beginning 0))) 574 (autoload-remove-section (match-beginning 0)))
547 ((equal (nth 4 form) (nth 5 (file-attributes file))) 575 ((equal (nth 4 form) (nth 5 (file-attributes file)))
548 ;; File hasn't changed. 576 ;; File hasn't changed.
549 nil) 577 nil)
550 (t 578 (t
551 (update-file-autoloads file))) 579 (autoload-remove-section (match-beginning 0))
580 (if (autoload-generate-file-autoloads
581 file (current-buffer) buffer-file-name)
582 (push file no-autoloads))))
552 (setq files (delete file files))))) 583 (setq files (delete file files)))))
553 ;; Elements remaining in FILES have no existing autoload sections yet. 584 ;; Elements remaining in FILES have no existing autoload sections yet.
554 (setq no-autoloads 585 (dolist (file files)
555 (append no-autoloads 586 (if (autoload-generate-file-autoloads file nil buffer-file-name)
556 (delq nil (mapcar 'update-file-autoloads files)))) 587 (push file no-autoloads)))
588
557 (when no-autoloads 589 (when no-autoloads
558 ;; Sort them for better readability. 590 ;; Sort them for better readability.
559 (setq no-autoloads (sort no-autoloads 'string<)) 591 (setq no-autoloads (sort no-autoloads 'string<))
560 ;; Add the `no-autoloads' section. 592 ;; Add the `no-autoloads' section.
561 (goto-char (point-max)) 593 (goto-char (point-max))
562 (search-backward "\f" nil t) 594 (search-backward "\f" nil t)
563 (autoload-insert-section-header 595 (autoload-insert-section-header
564 (current-buffer) nil nil no-autoloads this-time) 596 (current-buffer) nil nil no-autoloads this-time)
565 (insert generate-autoload-section-trailer)) 597 (insert generate-autoload-section-trailer))
566 598
567 (save-buffer)))) 599 (save-buffer)
600 ;; In case autoload entries were added to other files because of
601 ;; file-local autoload-generated-file settings.
602 (autoload-save-buffers))))
568 603
569 (define-obsolete-function-alias 'update-autoloads-from-directories 604 (define-obsolete-function-alias 'update-autoloads-from-directories
570 'update-directory-autoloads "22.1") 605 'update-directory-autoloads "22.1")
571 606
572 ;;;###autoload 607 ;;;###autoload