Mercurial > emacs
comparison lisp/emacs-lisp/autoload.el @ 71048:29150c5d541b
(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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 29 May 2006 02:53:14 +0000 |
parents | e98e3d0ee915 |
children | e727167b07e4 a8190f7e546e |
comparison
equal
deleted
inserted
replaced
71047:e98e3d0ee915 | 71048:29150c5d541b |
---|---|
285 (insert-file-contents file nil) | 285 (insert-file-contents file nil) |
286 (let ((enable-local-variables :safe)) | 286 (let ((enable-local-variables :safe)) |
287 (hack-local-variables)) | 287 (hack-local-variables)) |
288 (current-buffer))) | 288 (current-buffer))) |
289 | 289 |
290 (defvar no-update-autoloads nil | |
291 "File local variable to prevent scanning this file for autoload cookies.") | |
292 | |
290 (defun generate-file-autoloads (file) | 293 (defun generate-file-autoloads (file) |
291 "Insert at point a loaddefs autoload section for FILE. | 294 "Insert at point a loaddefs autoload section for FILE. |
292 autoloads are generated for defuns and defmacros in FILE | 295 Autoloads are generated for defuns and defmacros in FILE |
293 marked by `generate-autoload-cookie' (which see). | 296 marked by `generate-autoload-cookie' (which see). |
294 If FILE is being visited in a buffer, the contents of the buffer | 297 If FILE is being visited in a buffer, the contents of the buffer |
295 are used." | 298 are used. |
299 Return non-nil in the case where no autoloads were added at point." | |
296 (interactive "fGenerate autoloads for file: ") | 300 (interactive "fGenerate autoloads for file: ") |
297 (let ((outbuf (current-buffer)) | 301 (let ((outbuf (current-buffer)) |
298 (autoloads-done '()) | 302 (autoloads-done '()) |
299 (load-name (let ((name (file-name-nondirectory file))) | 303 (load-name (let ((name (file-name-nondirectory file))) |
300 (if (string-match "\\.elc?\\(\\.\\|$\\)" name) | 304 (if (string-match "\\.elc?\\(\\.\\|$\\)" name) |
303 (print-length nil) | 307 (print-length nil) |
304 (print-readably t) ; This does something in Lucid Emacs. | 308 (print-readably t) ; This does something in Lucid Emacs. |
305 (float-output-format nil) | 309 (float-output-format nil) |
306 (done-any nil) | 310 (done-any nil) |
307 (visited (get-file-buffer file)) | 311 (visited (get-file-buffer file)) |
308 output-end) | 312 output-start) |
309 | 313 |
310 ;; If the autoload section we create here uses an absolute | 314 ;; If the autoload section we create here uses an absolute |
311 ;; file name for FILE in its header, and then Emacs is installed | 315 ;; file name for FILE in its header, and then Emacs is installed |
312 ;; under a different path on another system, | 316 ;; under a different path on another system, |
313 ;; `update-autoloads-here' won't be able to find the files to be | 317 ;; `update-autoloads-here' won't be able to find the files to be |
321 (len (length dir-truename))) | 325 (len (length dir-truename))) |
322 (if (and (< len (length source-truename)) | 326 (if (and (< len (length source-truename)) |
323 (string= dir-truename (substring source-truename 0 len))) | 327 (string= dir-truename (substring source-truename 0 len))) |
324 (setq file (substring source-truename len)))) | 328 (setq file (substring source-truename len)))) |
325 | 329 |
326 (message "Generating autoloads for %s..." file) | 330 (with-current-buffer (or visited |
327 (save-excursion | 331 ;; It is faster to avoid visiting the file. |
328 (unwind-protect | 332 (autoload-find-file file)) |
329 (progn | 333 ;; Obey the no-update-autoloads file local variable. |
330 (set-buffer (or visited | 334 (unless no-update-autoloads |
331 ;; It is faster to avoid visiting the file. | 335 (message "Generating autoloads for %s..." file) |
332 (autoload-find-file file))) | 336 (setq output-start (with-current-buffer outbuf (point))) |
333 (save-excursion | 337 (save-excursion |
334 (save-restriction | 338 (save-restriction |
335 (widen) | 339 (widen) |
336 (goto-char (point-min)) | 340 (goto-char (point-min)) |
337 (while (not (eobp)) | 341 (while (not (eobp)) |
338 (skip-chars-forward " \t\n\f") | 342 (skip-chars-forward " \t\n\f") |
339 (cond | 343 (cond |
340 ((looking-at (regexp-quote generate-autoload-cookie)) | 344 ((looking-at (regexp-quote generate-autoload-cookie)) |
341 (search-forward generate-autoload-cookie) | 345 (search-forward generate-autoload-cookie) |
342 (skip-chars-forward " \t") | 346 (skip-chars-forward " \t") |
343 (setq done-any t) | 347 (setq done-any t) |
344 (if (eolp) | 348 (if (eolp) |
345 ;; Read the next form and make an autoload. | 349 ;; Read the next form and make an autoload. |
346 (let* ((form (prog1 (read (current-buffer)) | 350 (let* ((form (prog1 (read (current-buffer)) |
347 (or (bolp) (forward-line 1)))) | 351 (or (bolp) (forward-line 1)))) |
348 (autoload (make-autoload form load-name))) | 352 (autoload (make-autoload form load-name))) |
349 (if autoload | 353 (if autoload |
350 (push (nth 1 form) autoloads-done) | 354 (push (nth 1 form) autoloads-done) |
351 (setq autoload form)) | 355 (setq autoload form)) |
352 (let ((autoload-print-form-outbuf outbuf)) | 356 (let ((autoload-print-form-outbuf outbuf)) |
353 (autoload-print-form autoload))) | 357 (autoload-print-form autoload))) |
354 | 358 |
355 ;; Copy the rest of the line to the output. | 359 ;; Copy the rest of the line to the output. |
356 (princ (buffer-substring | 360 (princ (buffer-substring |
357 (progn | 361 (progn |
358 ;; Back up over whitespace, to preserve it. | 362 ;; Back up over whitespace, to preserve it. |
359 (skip-chars-backward " \f\t") | 363 (skip-chars-backward " \f\t") |
360 (if (= (char-after (1+ (point))) ? ) | 364 (if (= (char-after (1+ (point))) ? ) |
361 ;; Eat one space. | 365 ;; Eat one space. |
362 (forward-char 1)) | 366 (forward-char 1)) |
363 (point)) | 367 (point)) |
364 (progn (forward-line 1) (point))) | 368 (progn (forward-line 1) (point))) |
365 outbuf))) | 369 outbuf))) |
366 ((looking-at ";") | 370 ((looking-at ";") |
367 ;; Don't read the comment. | 371 ;; Don't read the comment. |
368 (forward-line 1)) | 372 (forward-line 1)) |
369 (t | 373 (t |
370 (forward-sexp 1) | 374 (forward-sexp 1) |
371 (forward-line 1))))))) | 375 (forward-line 1)))))) |
372 (or visited | 376 |
373 ;; We created this buffer, so we should kill it. | 377 (when done-any |
374 (kill-buffer (current-buffer))) | 378 (with-current-buffer outbuf |
375 (set-buffer outbuf) | 379 (save-excursion |
376 (setq output-end (point-marker)))) | 380 ;; Insert the section-header line which lists the file name |
377 (if done-any | 381 ;; and which functions are in it, etc. |
378 (progn | 382 (goto-char output-start) |
379 ;; Insert the section-header line | 383 (autoload-insert-section-header |
380 ;; which lists the file name and which functions are in it, etc. | 384 outbuf autoloads-done load-name file |
381 (autoload-insert-section-header outbuf autoloads-done load-name file | 385 (nth 5 (file-attributes file))) |
382 (nth 5 (file-attributes file))) | 386 (insert ";;; Generated autoloads from " |
383 (insert ";;; Generated autoloads from " | 387 (autoload-trim-file-name file) "\n")) |
384 (autoload-trim-file-name file) "\n") | 388 (insert generate-autoload-section-trailer))) |
385 (goto-char output-end) | 389 (message "Generating autoloads for %s...done" file)) |
386 (insert generate-autoload-section-trailer))) | 390 (or visited |
387 (message "Generating autoloads for %s...done" file))) | 391 ;; We created this buffer, so we should kill it. |
392 (kill-buffer (current-buffer)))) | |
393 (not done-any))) | |
388 | 394 |
389 ;;;###autoload | 395 ;;;###autoload |
390 (defun update-file-autoloads (file &optional save-after) | 396 (defun update-file-autoloads (file &optional save-after) |
391 "Update the autoloads for FILE in `generated-autoload-file' | 397 "Update the autoloads for FILE in `generated-autoload-file' |
392 \(which FILE might bind in its local variables). | 398 \(which FILE might bind in its local variables). |
461 (setq found 'new) | 467 (setq found 'new) |
462 ;; No later sections in the file. Put before the last page. | 468 ;; No later sections in the file. Put before the last page. |
463 (goto-char (point-max)) | 469 (goto-char (point-max)) |
464 (search-backward "\f" nil t))) | 470 (search-backward "\f" nil t))) |
465 (or (eq found 'up-to-date) | 471 (or (eq found 'up-to-date) |
466 (and (eq found 'new) | 472 (setq no-autoloads (generate-file-autoloads file))))) |
467 ;; Check that FILE has any cookies before generating a | |
468 ;; new section for it. | |
469 (with-current-buffer | |
470 (or existing-buffer | |
471 ;; It is faster to avoid visiting the file. | |
472 (autoload-find-file file)) | |
473 (save-excursion | |
474 (save-restriction | |
475 (widen) | |
476 (goto-char (point-min)) | |
477 (prog1 | |
478 (setq no-autoloads | |
479 (not (re-search-forward | |
480 (concat "^" (regexp-quote | |
481 generate-autoload-cookie)) | |
482 nil t))) | |
483 (if (and no-autoloads (interactive-p)) | |
484 (message "%s has no autoloads" file)) | |
485 (or existing-buffer | |
486 (kill-buffer (current-buffer)))))))) | |
487 (generate-file-autoloads file)))) | |
488 (and save-after | 473 (and save-after |
489 (buffer-modified-p) | 474 (buffer-modified-p) |
490 (save-buffer)) | 475 (save-buffer)) |
491 | 476 |
492 (if no-autoloads file)))) | 477 (if no-autoloads file)))) |