comparison lisp/emacs-lisp/autoload.el @ 14043:d44a43c284e7

(update-file-autoloads): Notice when searching found nothing at all. (update-autoloads-from-directory): New function. (batch-update-autoloads): Use it. (update-directory-autoloads, update-autoloads-here): Functions removed.
author Roland McGrath <roland@gnu.org>
date Sat, 06 Jan 1996 18:38:41 +0000
parents b7bb85cdc666
children 1c331f9332ae
comparison
equal deleted inserted replaced
14042:161d50568707 14043:d44a43c284e7
154 (set-buffer visited) 154 (set-buffer visited)
155 ;; It is faster to avoid visiting the file. 155 ;; It is faster to avoid visiting the file.
156 (set-buffer (get-buffer-create " *generate-autoload-file*")) 156 (set-buffer (get-buffer-create " *generate-autoload-file*"))
157 (kill-all-local-variables) 157 (kill-all-local-variables)
158 (erase-buffer) 158 (erase-buffer)
159 (setq buffer-undo-list t
160 buffer-read-only nil)
161 (emacs-lisp-mode)
159 (insert-file-contents file nil)) 162 (insert-file-contents file nil))
160 (save-excursion 163 (save-excursion
161 (save-restriction 164 (save-restriction
162 (widen) 165 (widen)
163 (goto-char (point-min)) 166 (goto-char (point-min))
284 (found nil) 287 (found nil)
285 (existing-buffer (get-file-buffer file))) 288 (existing-buffer (get-file-buffer file)))
286 (save-excursion 289 (save-excursion
287 ;; We want to get a value for generated-autoload-file from 290 ;; We want to get a value for generated-autoload-file from
288 ;; the local variables section if it's there. 291 ;; the local variables section if it's there.
289 (set-buffer (find-file-noselect file)) 292 (if existing-buffer
293 (set-buffer existing-buffer))
290 (set-buffer (find-file-noselect generated-autoload-file)) 294 (set-buffer (find-file-noselect generated-autoload-file))
291 (save-excursion 295 (save-excursion
292 (save-restriction 296 (save-restriction
293 (widen) 297 (widen)
294 (goto-char (point-min)) 298 (goto-char (point-min))
302 ;; We found the section for this file. 306 ;; We found the section for this file.
303 ;; Check if it is up to date. 307 ;; Check if it is up to date.
304 (let ((begin (match-beginning 0)) 308 (let ((begin (match-beginning 0))
305 (last-time (nth 4 form)) 309 (last-time (nth 4 form))
306 (file-time (nth 5 (file-attributes file)))) 310 (file-time (nth 5 (file-attributes file))))
311 (message "%s: las %s vs %s" file last-time file-time)
307 (if (and (or (null existing-buffer) 312 (if (and (or (null existing-buffer)
308 (not (buffer-modified-p existing-buffer))) 313 (not (buffer-modified-p existing-buffer)))
309 (listp last-time) (= (length last-time) 2) 314 (listp last-time) (= (length last-time) 2)
310 (or (> (car last-time) (car file-time)) 315 (or (> (car last-time) (car file-time))
311 (and (= (car last-time) (car file-time)) 316 (and (= (car last-time) (car file-time))
324 ;; there must be no section for LOAD-NAME. We will 329 ;; there must be no section for LOAD-NAME. We will
325 ;; insert one before the section here. 330 ;; insert one before the section here.
326 (goto-char (match-beginning 0)) 331 (goto-char (match-beginning 0))
327 (setq found 'new))))) 332 (setq found 'new)))))
328 (or (eq found 'up-to-date) 333 (or (eq found 'up-to-date)
329 (and (eq found 'new) 334 (and (memq found '(nil new))
330 ;; Check that FILE has any cookies before generating a 335 ;; Check that FILE has any cookies before generating a
331 ;; new section for it. 336 ;; new section for it.
332 (save-excursion 337 (save-excursion
333 (set-buffer (find-file-noselect file)) 338 (if existing-buffer
339 (set-buffer existing-buffer)
340 ;; It is faster to avoid visiting the file.
341 (set-buffer (get-buffer-create " *autoload-file*"))
342 (kill-all-local-variables)
343 (erase-buffer)
344 (setq buffer-undo-list t
345 buffer-read-only nil)
346 (emacs-lisp-mode)
347 (insert-file-contents file nil))
334 (save-excursion 348 (save-excursion
335 (widen) 349 (save-restriction
336 (goto-char (point-min)) 350 (widen)
337 (if (search-forward (concat "\n" 351 (goto-char (point-min))
338 generate-autoload-cookie) 352 (prog1
339 nil t) 353 (if (search-forward
340 nil 354 (concat "\n" generate-autoload-cookie)
341 (if (interactive-p) 355 nil t)
342 (message file " has no autoloads")) 356 nil
343 t)))) 357 (if (interactive-p)
358 (message file " has no autoloads"))
359 t)
360 (or existing-buffer
361 (kill-buffer (current-buffer))))))))
344 (generate-file-autoloads file)))) 362 (generate-file-autoloads file))))
345 (if (interactive-p) (save-buffer)) 363 (if (interactive-p) (save-buffer)))))
346 (if (and (null existing-buffer)
347 (setq existing-buffer (get-file-buffer file)))
348 (kill-buffer existing-buffer)))))
349 364
350 ;;;###autoload 365 ;;;###autoload
351 (defun update-autoloads-here () 366 (defun update-autoloads-from-directory (dir)
352 "\ 367 "\
353 Update sections of the current buffer generated by \\[update-file-autoloads]." 368 Update loaddefs.el with all the current autoloads from DIR, and no old ones.
354 (interactive) 369 This uses `update-file-autoloads' (which see) do its work."
355 (let ((generated-autoload-file (buffer-file-name))) 370 (interactive "DUpdate autoloads from directory: ")
371 (let ((files (directory-files dir nil "^[^=].*\\.el$")))
356 (save-excursion 372 (save-excursion
357 (goto-char (point-min)) 373 (set-buffer (find-file-noselect
358 (while (search-forward generate-autoload-section-header nil t) 374 (if (file-exists-p generated-autoload-file)
359 (let* ((form (condition-case () 375 generated-autoload-file
360 (read (current-buffer)) 376 (expand-file-name generated-autoload-file
361 (end-of-file nil))) 377 dir))))
362 (file (nth 3 form)))
363 (if (and (stringp file)
364 (or (get-file-buffer file)
365 (file-exists-p file)))
366 ()
367 (setq file (if (y-or-n-p (format "Can't find library `%s'; remove its autoloads? "
368 (nth 2 form) file))
369 t
370 (condition-case ()
371 (read-file-name (format "Find `%s' load file: "
372 (nth 2 form))
373 nil nil t)
374 (quit nil)))))
375 (if file
376 (let ((begin (match-beginning 0)))
377 (search-forward generate-autoload-section-trailer)
378 (delete-region begin (point))))
379 (if (stringp file)
380 (generate-file-autoloads file)))))))
381
382 ;;;###autoload
383 (defun update-directory-autoloads (dir)
384 "Run \\[update-file-autoloads] on each .el file in DIR."
385 (interactive "DUpdate autoloads for directory: ")
386 (let ((enable-local-eval nil))
387 (mapcar 'update-file-autoloads
388 (directory-files dir t "^[^=].*\\.el$")))
389 (if (interactive-p)
390 (save-excursion 378 (save-excursion
391 (set-buffer (find-file-noselect generated-autoload-file)) 379 (goto-char (point-min))
392 (save-buffer)))) 380 (while (search-forward generate-autoload-section-header nil t)
381 (let* ((form (condition-case ()
382 (read (current-buffer))
383 (end-of-file nil)))
384 (file (nth 3 form)))
385 (cond ((not (stringp file)))
386 ((not (file-exists-p (expand-file-name file dir)))
387 ;; Remove the obsolete section.
388 (let ((begin (match-beginning 0)))
389 (search-forward generate-autoload-section-trailer)
390 (delete-region begin (point))))
391 (t
392 (update-file-autoloads file)))
393 (setq files (delete file files)))))
394 ;; Elements remaining in FILES have no existing autoload sections.
395 (mapcar 'update-file-autoloads files)
396 (save-buffer))))
393 397
394 ;;;###autoload 398 ;;;###autoload
395 (defun batch-update-autoloads () 399 (defun batch-update-autoloads ()
396 "Update the autoloads for the files or directories on the command line. 400 "Update loaddefs.el autoloads in batch mode.
397 Runs \\[update-file-autoloads] on files and \\[update-directory-autoloads] 401 Calls `update-autoloads-from-directory' on each command line argument."
398 on directories. Must be used only with -batch, and kills Emacs on completion. 402 (mapcar 'update-autoloads-from-directory command-line-args-left)
399 Each file will be processed even if an error occurred previously. 403 (setq command-line-args-left nil))
400 For example, invoke `emacs -batch -f batch-update-autoloads *.el'."
401 (if (not noninteractive)
402 (error "batch-update-autoloads is to be used only with -batch"))
403 (let ((lost nil)
404 (args command-line-args-left)
405 (enable-local-eval nil)) ;Don't query in batch mode.
406 (message "Updating autoloads in %s..." generated-autoload-file)
407 (let ((frob (function
408 (lambda (file)
409 (condition-case lossage
410 (update-file-autoloads file)
411 (error
412 (princ ">>Error processing ")
413 (princ file)
414 (princ ": ")
415 (princ (error-message-string lossage))
416 (princ "\n")
417 (setq lost t)))))))
418 (while args
419 (if (file-directory-p (expand-file-name (car args)))
420 (let ((rest (directory-files (car args) t "\\.el$")))
421 (while rest
422 (funcall frob (car rest))
423 (setq rest (cdr rest))))
424 (funcall frob (car args)))
425 (setq args (cdr args))))
426 (save-some-buffers t)
427 (message "Done")
428 (kill-emacs (if lost 1 0))))
429 404
430 (provide 'autoload) 405 (provide 'autoload)
431 406
432 ;;; autoload.el ends here 407 ;;; autoload.el ends here