Mercurial > emacs
comparison lisp/emacs-lisp/autoload.el @ 90428:a8190f7e546e
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 285-296)
- Update from CVS
- Merge from gnus--rel--5.10
- Update from CVS: admin/FOR-RELEASE: Update refcard section.
* gnus--rel--5.10 (patch 102-104)
- Update from CVS
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-64
author | Miles Bader <miles@gnu.org> |
---|---|
date | Wed, 07 Jun 2006 18:05:10 +0000 |
parents | 5754737d1e04 29150c5d541b |
children | 8a8e69664178 |
comparison
equal
deleted
inserted
replaced
90427:ddb25860d044 | 90428:a8190f7e546e |
---|---|
271 (move-to-column 64) | 271 (move-to-column 64) |
272 (skip-chars-forward "^ \n") | 272 (skip-chars-forward "^ \n") |
273 (or (eolp) | 273 (or (eolp) |
274 (insert "\n" generate-autoload-section-continuation)))))) | 274 (insert "\n" generate-autoload-section-continuation)))))) |
275 | 275 |
276 (defun autoload-find-file (file) | |
277 "Fetch file and put it in a temp buffer. Return the buffer." | |
278 ;; It is faster to avoid visiting the file. | |
279 (with-current-buffer (get-buffer-create " *autoload-file*") | |
280 (kill-all-local-variables) | |
281 (erase-buffer) | |
282 (setq buffer-undo-list t | |
283 buffer-read-only nil) | |
284 (emacs-lisp-mode) | |
285 (insert-file-contents file nil) | |
286 (let ((enable-local-variables :safe)) | |
287 (hack-local-variables)) | |
288 (current-buffer))) | |
289 | |
290 (defvar no-update-autoloads nil | |
291 "File local variable to prevent scanning this file for autoload cookies.") | |
292 | |
276 (defun generate-file-autoloads (file) | 293 (defun generate-file-autoloads (file) |
277 "Insert at point a loaddefs autoload section for FILE. | 294 "Insert at point a loaddefs autoload section for FILE. |
278 autoloads are generated for defuns and defmacros in FILE | 295 Autoloads are generated for defuns and defmacros in FILE |
279 marked by `generate-autoload-cookie' (which see). | 296 marked by `generate-autoload-cookie' (which see). |
280 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 |
281 are used." | 298 are used. |
299 Return non-nil in the case where no autoloads were added at point." | |
282 (interactive "fGenerate autoloads for file: ") | 300 (interactive "fGenerate autoloads for file: ") |
283 (let ((outbuf (current-buffer)) | 301 (let ((outbuf (current-buffer)) |
284 (autoloads-done '()) | 302 (autoloads-done '()) |
285 (load-name (let ((name (file-name-nondirectory file))) | 303 (load-name (let ((name (file-name-nondirectory file))) |
286 (if (string-match "\\.elc?\\(\\.\\|$\\)" name) | 304 (if (string-match "\\.elc?\\(\\.\\|$\\)" name) |
289 (print-length nil) | 307 (print-length nil) |
290 (print-readably t) ; This does something in Lucid Emacs. | 308 (print-readably t) ; This does something in Lucid Emacs. |
291 (float-output-format nil) | 309 (float-output-format nil) |
292 (done-any nil) | 310 (done-any nil) |
293 (visited (get-file-buffer file)) | 311 (visited (get-file-buffer file)) |
294 output-end) | 312 output-start) |
295 | 313 |
296 ;; If the autoload section we create here uses an absolute | 314 ;; If the autoload section we create here uses an absolute |
297 ;; 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 |
298 ;; under a different path on another system, | 316 ;; under a different path on another system, |
299 ;; `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 |
307 (len (length dir-truename))) | 325 (len (length dir-truename))) |
308 (if (and (< len (length source-truename)) | 326 (if (and (< len (length source-truename)) |
309 (string= dir-truename (substring source-truename 0 len))) | 327 (string= dir-truename (substring source-truename 0 len))) |
310 (setq file (substring source-truename len)))) | 328 (setq file (substring source-truename len)))) |
311 | 329 |
312 (message "Generating autoloads for %s..." file) | 330 (with-current-buffer (or visited |
313 (save-excursion | 331 ;; It is faster to avoid visiting the file. |
314 (unwind-protect | 332 (autoload-find-file file)) |
315 (progn | 333 ;; Obey the no-update-autoloads file local variable. |
316 (if visited | 334 (unless no-update-autoloads |
317 (set-buffer visited) | 335 (message "Generating autoloads for %s..." file) |
318 ;; It is faster to avoid visiting the file. | 336 (setq output-start (with-current-buffer outbuf (point))) |
319 (set-buffer (get-buffer-create " *generate-autoload-file*")) | 337 (save-excursion |
320 (kill-all-local-variables) | 338 (save-restriction |
321 (erase-buffer) | 339 (widen) |
322 (setq buffer-undo-list t | 340 (goto-char (point-min)) |
323 buffer-read-only nil) | 341 (while (not (eobp)) |
324 (emacs-lisp-mode) | 342 (skip-chars-forward " \t\n\f") |
325 (insert-file-contents file nil)) | 343 (cond |
326 (save-excursion | 344 ((looking-at (regexp-quote generate-autoload-cookie)) |
327 (save-restriction | 345 (search-forward generate-autoload-cookie) |
328 (widen) | 346 (skip-chars-forward " \t") |
329 (goto-char (point-min)) | 347 (setq done-any t) |
330 (while (not (eobp)) | 348 (if (eolp) |
331 (skip-chars-forward " \t\n\f") | 349 ;; Read the next form and make an autoload. |
332 (cond | 350 (let* ((form (prog1 (read (current-buffer)) |
333 ((looking-at (regexp-quote generate-autoload-cookie)) | 351 (or (bolp) (forward-line 1)))) |
334 (search-forward generate-autoload-cookie) | 352 (autoload (make-autoload form load-name))) |
335 (skip-chars-forward " \t") | 353 (if autoload |
336 (setq done-any t) | 354 (push (nth 1 form) autoloads-done) |
337 (if (eolp) | 355 (setq autoload form)) |
338 ;; Read the next form and make an autoload. | 356 (let ((autoload-print-form-outbuf outbuf)) |
339 (let* ((form (prog1 (read (current-buffer)) | 357 (autoload-print-form autoload))) |
340 (or (bolp) (forward-line 1)))) | 358 |
341 (autoload (make-autoload form load-name))) | 359 ;; Copy the rest of the line to the output. |
342 (if autoload | 360 (princ (buffer-substring |
343 (setq autoloads-done (cons (nth 1 form) | 361 (progn |
344 autoloads-done)) | 362 ;; Back up over whitespace, to preserve it. |
345 (setq autoload form)) | 363 (skip-chars-backward " \f\t") |
346 (let ((autoload-print-form-outbuf outbuf)) | 364 (if (= (char-after (1+ (point))) ? ) |
347 (autoload-print-form autoload))) | 365 ;; Eat one space. |
348 | 366 (forward-char 1)) |
349 ;; Copy the rest of the line to the output. | 367 (point)) |
350 (princ (buffer-substring | 368 (progn (forward-line 1) (point))) |
351 (progn | 369 outbuf))) |
352 ;; Back up over whitespace, to preserve it. | 370 ((looking-at ";") |
353 (skip-chars-backward " \f\t") | 371 ;; Don't read the comment. |
354 (if (= (char-after (1+ (point))) ? ) | 372 (forward-line 1)) |
355 ;; Eat one space. | 373 (t |
356 (forward-char 1)) | 374 (forward-sexp 1) |
357 (point)) | 375 (forward-line 1)))))) |
358 (progn (forward-line 1) (point))) | 376 |
359 outbuf))) | 377 (when done-any |
360 ((looking-at ";") | 378 (with-current-buffer outbuf |
361 ;; Don't read the comment. | 379 (save-excursion |
362 (forward-line 1)) | 380 ;; Insert the section-header line which lists the file name |
363 (t | 381 ;; and which functions are in it, etc. |
364 (forward-sexp 1) | 382 (goto-char output-start) |
365 (forward-line 1))))))) | 383 (autoload-insert-section-header |
366 (or visited | 384 outbuf autoloads-done load-name file |
367 ;; We created this buffer, so we should kill it. | 385 (nth 5 (file-attributes file))) |
368 (kill-buffer (current-buffer))) | 386 (insert ";;; Generated autoloads from " |
369 (set-buffer outbuf) | 387 (autoload-trim-file-name file) "\n")) |
370 (setq output-end (point-marker)))) | 388 (insert generate-autoload-section-trailer))) |
371 (if done-any | 389 (message "Generating autoloads for %s...done" file)) |
372 (progn | 390 (or visited |
373 ;; Insert the section-header line | 391 ;; We created this buffer, so we should kill it. |
374 ;; which lists the file name and which functions are in it, etc. | 392 (kill-buffer (current-buffer)))) |
375 (autoload-insert-section-header outbuf autoloads-done load-name file | 393 (not done-any))) |
376 (nth 5 (file-attributes file))) | |
377 (insert ";;; Generated autoloads from " | |
378 (autoload-trim-file-name file) "\n") | |
379 (goto-char output-end) | |
380 (insert generate-autoload-section-trailer))) | |
381 (message "Generating autoloads for %s...done" file))) | |
382 | 394 |
383 ;;;###autoload | 395 ;;;###autoload |
384 (defun update-file-autoloads (file &optional save-after) | 396 (defun update-file-autoloads (file &optional save-after) |
385 "Update the autoloads for FILE in `generated-autoload-file' | 397 "Update the autoloads for FILE in `generated-autoload-file' |
386 \(which FILE might bind in its local variables). | 398 \(which FILE might bind in its local variables). |
455 (setq found 'new) | 467 (setq found 'new) |
456 ;; No later sections in the file. Put before the last page. | 468 ;; No later sections in the file. Put before the last page. |
457 (goto-char (point-max)) | 469 (goto-char (point-max)) |
458 (search-backward "\f" nil t))) | 470 (search-backward "\f" nil t))) |
459 (or (eq found 'up-to-date) | 471 (or (eq found 'up-to-date) |
460 (and (eq found 'new) | 472 (setq no-autoloads (generate-file-autoloads file))))) |
461 ;; Check that FILE has any cookies before generating a | |
462 ;; new section for it. | |
463 (save-excursion | |
464 (if existing-buffer | |
465 (set-buffer existing-buffer) | |
466 ;; It is faster to avoid visiting the file. | |
467 (set-buffer (get-buffer-create " *autoload-file*")) | |
468 (kill-all-local-variables) | |
469 (erase-buffer) | |
470 (setq buffer-undo-list t | |
471 buffer-read-only nil) | |
472 (emacs-lisp-mode) | |
473 (insert-file-contents file nil)) | |
474 (save-excursion | |
475 (save-restriction | |
476 (widen) | |
477 (goto-char (point-min)) | |
478 (prog1 | |
479 (if (re-search-forward | |
480 (concat "^" (regexp-quote | |
481 generate-autoload-cookie)) | |
482 nil t) | |
483 nil | |
484 (if (interactive-p) | |
485 (message "%s has no autoloads" file)) | |
486 (setq no-autoloads t) | |
487 t) | |
488 (or existing-buffer | |
489 (kill-buffer (current-buffer)))))))) | |
490 (generate-file-autoloads file)))) | |
491 (and save-after | 473 (and save-after |
492 (buffer-modified-p) | 474 (buffer-modified-p) |
493 (save-buffer)) | 475 (save-buffer)) |
494 | 476 |
495 (if no-autoloads file)))) | 477 (if no-autoloads file)))) |