aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2007-06-26 19:07:14 +0000
committerStefan Monnier2007-06-26 19:07:14 +0000
commit1fad2b12bad86310146e4e579501407ab55819f5 (patch)
tree5dc5f63e6bd1349233e4e0b8d78f8283d44fe0b0
parent56dada428edf7ecdbcf23a1915b23de83ca5b590 (diff)
downloademacs-1fad2b12bad86310146e4e579501407ab55819f5.tar.gz
emacs-1fad2b12bad86310146e4e579501407ab55819f5.zip
(autoload-find-destination): Return nil
rather than throwing `up-to-date'. (autoload-generate-file-autoloads): Adjust correspondingly. (update-file-autoloads): Be careful to let-bind autoload-modified-buffers and adjust to new calling conventions. (autoload-modified-buffers): Make it a dynamically scoped var. (update-directory-autoloads): Use file-relative-name instead of autoload-trim-file-name. (autoload-insert-section-header): Don't use autoload-trim-file-name since the file is already relative now. (autoload-trim-file-name): Remove.
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/emacs-lisp/autoload.el317
2 files changed, 164 insertions, 165 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 437d439f284..958b962c522 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,17 @@
12007-06-26 Stefan Monnier <monnier@iro.umontreal.ca> 12007-06-26 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * emacs-lisp/autoload.el (autoload-find-destination): Return nil
4 rather than throwing `up-to-date'.
5 (autoload-generate-file-autoloads): Adjust correspondingly.
6 (update-file-autoloads): Be careful to let-bind
7 autoload-modified-buffers and adjust to new calling conventions.
8 (autoload-modified-buffers): Make it a dynamically scoped var.
9 (update-directory-autoloads): Use file-relative-name instead of
10 autoload-trim-file-name.
11 (autoload-insert-section-header): Don't use autoload-trim-file-name
12 since the file is already relative now.
13 (autoload-trim-file-name): Remove.
14
3 * vc-arch.el (vc-arch-add-tagline): Do a slightly cleaner job. 15 * vc-arch.el (vc-arch-add-tagline): Do a slightly cleaner job.
4 (vc-arch-complete, vc-arch--version-completion-table) 16 (vc-arch-complete, vc-arch--version-completion-table)
5 (vc-arch-revision-completion-table): New functions to provide 17 (vc-arch-revision-completion-table): New functions to provide
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el
index 2861aedef3e..c0362f3e6f6 100644
--- a/lisp/emacs-lisp/autoload.el
+++ b/lisp/emacs-lisp/autoload.el
@@ -68,6 +68,8 @@ that text will be copied verbatim to `generated-autoload-file'.")
68(defconst generate-autoload-section-continuation ";;;;;; " 68(defconst generate-autoload-section-continuation ";;;;;; "
69 "String to add on each continuation of the section header form.") 69 "String to add on each continuation of the section header form.")
70 70
71(defvar autoload-modified-buffers) ;Dynamically scoped var.
72
71(defun make-autoload (form file) 73(defun make-autoload (form file)
72 "Turn FORM into an autoload or defvar for source file FILE. 74 "Turn FORM into an autoload or defvar for source file FILE.
73Returns nil if FORM is not a special autoload form (i.e. a function definition 75Returns nil if FORM is not a special autoload form (i.e. a function definition
@@ -157,16 +159,6 @@ or macro definition or a defcustom)."
157 (expand-file-name "lisp" 159 (expand-file-name "lisp"
158 source-directory))) 160 source-directory)))
159 161
160(defun autoload-trim-file-name (file)
161 ;; Returns a relative file path for FILE
162 ;; starting from the directory that loaddefs.el is in.
163 ;; That is normally a directory in load-path,
164 ;; which means Emacs will be able to find FILE when it looks.
165 ;; Any extra directory names here would prevent finding the file.
166 (setq file (expand-file-name file))
167 (file-relative-name file
168 (file-name-directory generated-autoload-file)))
169
170(defun autoload-read-section-header () 162(defun autoload-read-section-header ()
171 "Read a section header form. 163 "Read a section header form.
172Since continuation lines have been marked as comments, 164Since continuation lines have been marked as comments,
@@ -260,9 +252,7 @@ put the output in."
260 "Insert the section-header line, 252 "Insert the section-header line,
261which lists the file name and which functions are in it, etc." 253which lists the file name and which functions are in it, etc."
262 (insert generate-autoload-section-header) 254 (insert generate-autoload-section-header)
263 (prin1 (list 'autoloads autoloads load-name 255 (prin1 (list 'autoloads autoloads load-name file time)
264 (if (stringp file) (autoload-trim-file-name file) file)
265 time)
266 outbuf) 256 outbuf)
267 (terpri outbuf) 257 (terpri outbuf)
268 ;; Break that line at spaces, to avoid very long lines. 258 ;; Break that line at spaces, to avoid very long lines.
@@ -318,98 +308,99 @@ marked by `generate-autoload-cookie' (which see).
318If FILE is being visited in a buffer, the contents of the buffer are used. 308If FILE is being visited in a buffer, the contents of the buffer are used.
319OUTBUF is the buffer in which the autoload statements will be inserted. 309OUTBUF is the buffer in which the autoload statements will be inserted.
320If OUTBUF is nil, it will be determined by `autoload-generated-file'. 310If OUTBUF is nil, it will be determined by `autoload-generated-file'.
321Return non-nil in the case where no autoloads were added to OUTBUF.
322
323Can throw `up-to-date' to mean that the entries were found already and are
324up-to-date. Of course, this can only be the case if OUTBUF is not used."
325 (let ((autoloads-done '())
326 (load-name (autoload-file-load-name file))
327 (print-length nil)
328 (print-readably t) ; This does something in Lucid Emacs.
329 (float-output-format nil)
330 (visited (get-file-buffer file))
331 (absfile (expand-file-name file))
332 relfile
333 ;; nil until we found a cookie.
334 output-start)
335
336 (with-current-buffer (or visited
337 ;; It is faster to avoid visiting the file.
338 (autoload-find-file file))
339 ;; Obey the no-update-autoloads file local variable.
340 (unless no-update-autoloads
341 (message "Generating autoloads for %s..." file)
342 (save-excursion
343 (save-restriction
344 (widen)
345 (goto-char (point-min))
346 (while (not (eobp))
347 (skip-chars-forward " \t\n\f")
348 (cond
349 ((looking-at (regexp-quote generate-autoload-cookie))
350 ;; If not done yet, figure out where to insert this text.
351 (unless output-start
352 (unless outbuf
353 (setq outbuf (autoload-find-destination absfile)))
354 (with-current-buffer outbuf
355 (setq relfile (file-relative-name absfile))
356 (setq output-start (point)))
357 ;; (message "file=%S, relfile=%S, dest=%S"
358 ;; file relfile (autoload-generated-file))
359 )
360 (search-forward generate-autoload-cookie)
361 (skip-chars-forward " \t")
362 (if (eolp)
363 (condition-case err
364 ;; Read the next form and make an autoload.
365 (let* ((form (prog1 (read (current-buffer))
366 (or (bolp) (forward-line 1))))
367 (autoload (make-autoload form load-name)))
368 (if autoload
369 (push (nth 1 form) autoloads-done)
370 (setq autoload form))
371 (let ((autoload-print-form-outbuf outbuf))
372 (autoload-print-form autoload)))
373 (error
374 (message "Error in %s: %S" file err)))
375
376 ;; Copy the rest of the line to the output.
377 (princ (buffer-substring
378 (progn
379 ;; Back up over whitespace, to preserve it.
380 (skip-chars-backward " \f\t")
381 (if (= (char-after (1+ (point))) ? )
382 ;; Eat one space.
383 (forward-char 1))
384 (point))
385 (progn (forward-line 1) (point)))
386 outbuf)))
387 ((looking-at ";")
388 ;; Don't read the comment.
389 (forward-line 1))
390 (t
391 (forward-sexp 1)
392 (forward-line 1))))))
393
394 (when output-start
395 (with-current-buffer outbuf
396 (save-excursion
397 ;; Insert the section-header line which lists the file name
398 ;; and which functions are in it, etc.
399 (goto-char output-start)
400 (autoload-insert-section-header
401 outbuf autoloads-done load-name relfile
402 (nth 5 (file-attributes relfile)))
403 (insert ";;; Generated autoloads from " relfile "\n"))
404 (insert generate-autoload-section-trailer)))
405 (message "Generating autoloads for %s...done" file))
406 (or visited
407 ;; We created this buffer, so we should kill it.
408 (kill-buffer (current-buffer))))
409 (not output-start)))
410
411(defvar autoload-modified-buffers nil)
412 311
312Return non-nil iff FILE adds no autoloads to OUTBUF."
313 (catch 'done
314 (let ((autoloads-done '())
315 (load-name (autoload-file-load-name file))
316 (print-length nil)
317 (print-readably t) ; This does something in Lucid Emacs.
318 (float-output-format nil)
319 (visited (get-file-buffer file))
320 (absfile (expand-file-name file))
321 relfile
322 ;; nil until we found a cookie.
323 output-start)
324
325 (with-current-buffer (or visited
326 ;; It is faster to avoid visiting the file.
327 (autoload-find-file file))
328 ;; Obey the no-update-autoloads file local variable.
329 (unless no-update-autoloads
330 (message "Generating autoloads for %s..." file)
331 (save-excursion
332 (save-restriction
333 (widen)
334 (goto-char (point-min))
335 (while (not (eobp))
336 (skip-chars-forward " \t\n\f")
337 (cond
338 ((looking-at (regexp-quote generate-autoload-cookie))
339 ;; If not done yet, figure out where to insert this text.
340 (unless output-start
341 (unless outbuf
342 (setq outbuf (autoload-find-destination absfile))
343 (unless outbuf
344 ;; The file has autoload cookies, but they're
345 ;; already up-to-date.
346 (throw 'done t)))
347 (with-current-buffer outbuf
348 (setq relfile (file-relative-name absfile))
349 (setq output-start (point)))
350 ;; (message "file=%S, relfile=%S, dest=%S"
351 ;; file relfile (autoload-generated-file))
352 )
353 (search-forward generate-autoload-cookie)
354 (skip-chars-forward " \t")
355 (if (eolp)
356 (condition-case err
357 ;; Read the next form and make an autoload.
358 (let* ((form (prog1 (read (current-buffer))
359 (or (bolp) (forward-line 1))))
360 (autoload (make-autoload form load-name)))
361 (if autoload
362 (push (nth 1 form) autoloads-done)
363 (setq autoload form))
364 (let ((autoload-print-form-outbuf outbuf))
365 (autoload-print-form autoload)))
366 (error
367 (message "Error in %s: %S" file err)))
368
369 ;; Copy the rest of the line to the output.
370 (princ (buffer-substring
371 (progn
372 ;; Back up over whitespace, to preserve it.
373 (skip-chars-backward " \f\t")
374 (if (= (char-after (1+ (point))) ? )
375 ;; Eat one space.
376 (forward-char 1))
377 (point))
378 (progn (forward-line 1) (point)))
379 outbuf)))
380 ((looking-at ";")
381 ;; Don't read the comment.
382 (forward-line 1))
383 (t
384 (forward-sexp 1)
385 (forward-line 1))))))
386
387 (when output-start
388 (with-current-buffer outbuf
389 (save-excursion
390 ;; Insert the section-header line which lists the file name
391 ;; and which functions are in it, etc.
392 (goto-char output-start)
393 (autoload-insert-section-header
394 outbuf autoloads-done load-name relfile
395 (nth 5 (file-attributes relfile)))
396 (insert ";;; Generated autoloads from " relfile "\n"))
397 (insert generate-autoload-section-trailer)))
398 (message "Generating autoloads for %s...done" file))
399 (or visited
400 ;; We created this buffer, so we should kill it.
401 (kill-buffer (current-buffer))))
402 (not output-start))))
403
413(defun autoload-save-buffers () 404(defun autoload-save-buffers ()
414 (while autoload-modified-buffers 405 (while autoload-modified-buffers
415 (with-current-buffer (pop autoload-modified-buffers) 406 (with-current-buffer (pop autoload-modified-buffers)
@@ -424,78 +415,74 @@ save the buffer too.
424 415
425Return FILE if there was no autoload cookie in it, else nil." 416Return FILE if there was no autoload cookie in it, else nil."
426 (interactive "fUpdate autoloads for file: \np") 417 (interactive "fUpdate autoloads for file: \np")
427 (let ((no-autoloads nil)) 418 (let* ((autoload-modified-buffers nil)
428 (if (catch 'up-to-date 419 (no-autoloads (autoload-generate-file-autoloads file)))
429 (progn 420 (if autoload-modified-buffers
430 (setq no-autoloads (autoload-generate-file-autoloads file))
431 t))
432 (if save-after (autoload-save-buffers)) 421 (if save-after (autoload-save-buffers))
433 (if (interactive-p) 422 (if (interactive-p)
434 (message "Autoload section for %s is up to date." file))) 423 (message "Autoload section for %s is up to date." file)))
435 ;; If we caught `up-to-date', it means there are autoload entries, since
436 ;; otherwise we wouldn't have detected their up-to-dateness.
437 (if no-autoloads file))) 424 (if no-autoloads file)))
438 425
439(defun autoload-find-destination (file) 426(defun autoload-find-destination (file)
440 "Find the destination point of the current buffer's autoloads. 427 "Find the destination point of the current buffer's autoloads.
441FILE is the file name of the current buffer. 428FILE is the file name of the current buffer.
442Returns a buffer whose point is placed at the requested location. 429Returns a buffer whose point is placed at the requested location.
443Throws `up-to-date' if the file's autoloads are uptodate, otherwise 430Returns nil if the file's autoloads are uptodate, otherwise
444removes any prior now out-of-date autoload entries. 431removes any prior now out-of-date autoload entries.
445The current buffer only matters if it is visiting a file or if it has a buffer-local 432The current buffer only matters if it is visiting a file or if it has a buffer-local
446value for some variables such as `generated-autoload-file', so it's OK 433value for some variables such as `generated-autoload-file', so it's OK
447to call it from a dummy buffer if FILE is not currently visited." 434to call it from a dummy buffer if FILE is not currently visited."
448 ;; (message "autoload-find-destination %S" file) 435 (catch 'up-to-date
449 (let ((load-name (autoload-file-load-name file)) 436 (let ((load-name (autoload-file-load-name file))
450 (existing-buffer (if buffer-file-name (current-buffer))) 437 (existing-buffer (if buffer-file-name (current-buffer)))
451 (found nil)) 438 (found nil))
452 (with-current-buffer 439 (with-current-buffer
453 ;; We must read/write the file without any code conversion, 440 ;; We must read/write the file without any code conversion,
454 ;; but still decode EOLs. 441 ;; but still decode EOLs.
455 (let ((coding-system-for-read 'raw-text)) 442 (let ((coding-system-for-read 'raw-text))
456 (find-file-noselect 443 (find-file-noselect
457 (autoload-ensure-default-file (autoload-generated-file)))) 444 (autoload-ensure-default-file (autoload-generated-file))))
458 ;; This is to make generated-autoload-file have Unix EOLs, so 445 ;; This is to make generated-autoload-file have Unix EOLs, so
459 ;; that it is portable to all platforms. 446 ;; that it is portable to all platforms.
460 (setq buffer-file-coding-system 'raw-text-unix) 447 (setq buffer-file-coding-system 'raw-text-unix)
461 (or (> (buffer-size) 0) 448 (or (> (buffer-size) 0)
462 (error "Autoloads file %s does not exist" buffer-file-name)) 449 (error "Autoloads file %s does not exist" buffer-file-name))
463 (or (file-writable-p buffer-file-name) 450 (or (file-writable-p buffer-file-name)
464 (error "Autoloads file %s is not writable" buffer-file-name)) 451 (error "Autoloads file %s is not writable" buffer-file-name))
465 (widen) 452 (widen)
466 (goto-char (point-min)) 453 (goto-char (point-min))
467 ;; Look for the section for LOAD-NAME. 454 ;; Look for the section for LOAD-NAME.
468 (while (and (not found) 455 (while (and (not found)
469 (search-forward generate-autoload-section-header nil t)) 456 (search-forward generate-autoload-section-header nil t))
470 (let ((form (autoload-read-section-header))) 457 (let ((form (autoload-read-section-header)))
471 (cond ((string= (nth 2 form) load-name) 458 (cond ((string= (nth 2 form) load-name)
472 ;; We found the section for this file. 459 ;; We found the section for this file.
473 ;; Check if it is up to date. 460 ;; Check if it is up to date.
474 (let ((begin (match-beginning 0)) 461 (let ((begin (match-beginning 0))
475 (last-time (nth 4 form)) 462 (last-time (nth 4 form))
476 (file-time (nth 5 (file-attributes file)))) 463 (file-time (nth 5 (file-attributes file))))
477 (if (and (or (null existing-buffer) 464 (if (and (or (null existing-buffer)
478 (not (buffer-modified-p existing-buffer))) 465 (not (buffer-modified-p existing-buffer)))
479 (listp last-time) (= (length last-time) 2) 466 (listp last-time) (= (length last-time) 2)
480 (not (time-less-p last-time file-time))) 467 (not (time-less-p last-time file-time)))
481 (throw 'up-to-date nil) 468 (throw 'up-to-date nil)
482 (autoload-remove-section begin) 469 (autoload-remove-section begin)
483 (setq found t)))) 470 (setq found t))))
484 ((string< load-name (nth 2 form)) 471 ((string< load-name (nth 2 form))
485 ;; We've come to a section alphabetically later than 472 ;; We've come to a section alphabetically later than
486 ;; LOAD-NAME. We assume the file is in order and so 473 ;; LOAD-NAME. We assume the file is in order and so
487 ;; there must be no section for LOAD-NAME. We will 474 ;; there must be no section for LOAD-NAME. We will
488 ;; insert one before the section here. 475 ;; insert one before the section here.
489 (goto-char (match-beginning 0)) 476 (goto-char (match-beginning 0))
490 (setq found t))))) 477 (setq found t)))))
491 (or found 478 (or found
492 (progn 479 (progn
493 ;; No later sections in the file. Put before the last page. 480 ;; No later sections in the file. Put before the last page.
494 (goto-char (point-max)) 481 (goto-char (point-max))
495 (search-backward "\f" nil t))) 482 (search-backward "\f" nil t)))
496 (unless (memq (current-buffer) autoload-modified-buffers) 483 (unless (memq (current-buffer) autoload-modified-buffers)
497 (push (current-buffer) autoload-modified-buffers)) 484 (push (current-buffer) autoload-modified-buffers))
498 (current-buffer)))) 485 (current-buffer)))))
499 486
500(defun autoload-remove-section (begin) 487(defun autoload-remove-section (begin)
501 (goto-char begin) 488 (goto-char begin)
@@ -533,8 +520,8 @@ directory or directories specified."
533 (save-excursion 520 (save-excursion
534 521
535 ;; Canonicalize file names and remove the autoload file itself. 522 ;; Canonicalize file names and remove the autoload file itself.
536 (setq files (delete (autoload-trim-file-name buffer-file-name) 523 (setq files (delete (file-relative-name buffer-file-name)
537 (mapcar 'autoload-trim-file-name files))) 524 (mapcar 'file-relative-name files)))
538 525
539 (goto-char (point-min)) 526 (goto-char (point-min))
540 (while (search-forward generate-autoload-section-header nil t) 527 (while (search-forward generate-autoload-section-header nil t)