Show
Ignore:
Timestamp:
07/01/06 08:27:06 (2 years ago)
Author:
miyoshi
Message:

Sync up with Emacs CVS HEAD.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lisp/emacs-lisp/autoload.el

    r4058 r4098  
    274274            (insert "\n" generate-autoload-section-continuation)))))) 
    275275 
     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 
    276293(defun generate-file-autoloads (file) 
    277294  "Insert at point a loaddefs autoload section for FILE. 
    278 autoloads are generated for defuns and defmacros in FILE 
     295Autoloads are generated for defuns and defmacros in FILE 
    279296marked by `generate-autoload-cookie' (which see). 
    280297If FILE is being visited in a buffer, the contents of the buffer 
    281 are used." 
     298are used. 
     299Return non-nil in the case where no autoloads were added at point." 
    282300  (interactive "fGenerate autoloads for file: ") 
    283301  (let ((outbuf (current-buffer)) 
     
    292310        (done-any nil) 
    293311        (visited (get-file-buffer file)) 
    294        output-end
     312        output-start
    295313 
    296314    ;; If the autoload section we create here uses an absolute 
     
    310328          (setq file (substring source-truename len)))) 
    311329 
    312     (message "Generating autoloads for %s..." file) 
    313     (save-excursion 
    314       (unwind-protect 
    315           (progn 
    316             (if visited 
    317                 (set-buffer visited) 
    318               ;; It is faster to avoid visiting the file. 
    319               (set-buffer (get-buffer-create " *generate-autoload-file*")) 
    320               (kill-all-local-variables) 
    321               (erase-buffer) 
    322               (setq buffer-undo-list t 
    323                     buffer-read-only nil) 
    324               (emacs-lisp-mode) 
    325               (insert-file-contents file nil)) 
    326             (save-excursion 
    327               (save-restriction 
    328                 (widen) 
    329                 (goto-char (point-min)) 
    330                 (while (not (eobp)) 
    331                   (skip-chars-forward " \t\n\f") 
    332                   (cond 
    333                    ((looking-at (regexp-quote generate-autoload-cookie)) 
    334                     (search-forward generate-autoload-cookie) 
    335                     (skip-chars-forward " \t") 
    336                     (setq done-any t) 
    337                     (if (eolp) 
    338                         ;; Read the next form and make an autoload. 
    339                         (let* ((form (prog1 (read (current-buffer)) 
    340                                                (or (bolp) (forward-line 1)))) 
    341                                (autoload (make-autoload form load-name))) 
    342                           (if autoload 
    343                               (setq autoloads-done (cons (nth 1 form) 
    344                                                          autoloads-done)) 
    345                             (setq autoload form)) 
    346                           (let ((autoload-print-form-outbuf outbuf)) 
    347                             (autoload-print-form autoload))) 
    348  
    349                       ;; Copy the rest of the line to the output. 
    350                       (princ (buffer-substring 
    351                               (progn 
    352                                 ;; Back up over whitespace, to preserve it. 
    353                                 (skip-chars-backward " \f\t") 
    354                                 (if (= (char-after (1+ (point))) ? ) 
    355                                     ;; Eat one space. 
    356                                     (forward-char 1)) 
    357                                 (point)) 
    358                               (progn (forward-line 1) (point))) 
    359                              outbuf))) 
    360                    ((looking-at ";") 
    361                     ;; Don't read the comment. 
    362                     (forward-line 1)) 
    363                    (t 
    364                     (forward-sexp 1) 
    365                     (forward-line 1))))))) 
    366         (or visited 
    367             ;; We created this buffer, so we should kill it. 
    368             (kill-buffer (current-buffer))) 
    369         (set-buffer outbuf) 
    370         (setq output-end (point-marker)))) 
    371     (if done-any 
    372         (progn 
    373           ;; Insert the section-header line 
    374           ;; which lists the file name and which functions are in it, etc. 
    375           (autoload-insert-section-header outbuf autoloads-done load-name file 
    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))) 
     330    (with-current-buffer (or visited 
     331                             ;; It is faster to avoid visiting the file. 
     332                             (autoload-find-file file)) 
     333      ;; Obey the no-update-autoloads file local variable. 
     334      (unless no-update-autoloads 
     335        (message "Generating autoloads for %s..." file) 
     336        (setq output-start (with-current-buffer outbuf (point))) 
     337        (save-excursion 
     338          (save-restriction 
     339            (widen) 
     340            (goto-char (point-min)) 
     341            (while (not (eobp)) 
     342              (skip-chars-forward " \t\n\f") 
     343              (cond 
     344               ((looking-at (regexp-quote generate-autoload-cookie)) 
     345                (search-forward generate-autoload-cookie) 
     346                (skip-chars-forward " \t") 
     347                (setq done-any t) 
     348                (if (eolp) 
     349                    ;; Read the next form and make an autoload. 
     350                    (let* ((form (prog1 (read (current-buffer)) 
     351                                   (or (bolp) (forward-line 1)))) 
     352                           (autoload (make-autoload form load-name))) 
     353                      (if autoload 
     354                          (push (nth 1 form) autoloads-done) 
     355                        (setq autoload form)) 
     356                      (let ((autoload-print-form-outbuf outbuf)) 
     357                        (autoload-print-form autoload))) 
     358 
     359                  ;; Copy the rest of the line to the output. 
     360                  (princ (buffer-substring 
     361                          (progn 
     362                            ;; Back up over whitespace, to preserve it. 
     363                            (skip-chars-backward " \f\t") 
     364                            (if (= (char-after (1+ (point))) ? ) 
     365                                ;; Eat one space. 
     366                                (forward-char 1)) 
     367                            (point)) 
     368                          (progn (forward-line 1) (point))) 
     369                         outbuf))) 
     370               ((looking-at ";") 
     371                ;; Don't read the comment. 
     372                (forward-line 1)) 
     373               (t 
     374                (forward-sexp 1) 
     375                (forward-line 1)))))) 
     376 
     377        (when done-any 
     378          (with-current-buffer outbuf 
     379            (save-excursion 
     380              ;; Insert the section-header line which lists the file name 
     381              ;; and which functions are in it, etc. 
     382              (goto-char output-start) 
     383              (autoload-insert-section-header 
     384               outbuf autoloads-done load-name file 
     385               (nth 5 (file-attributes file))) 
     386              (insert ";;; Generated autoloads from " 
     387                      (autoload-trim-file-name file) "\n")) 
     388            (insert generate-autoload-section-trailer))) 
     389        (message "Generating autoloads for %s...done" file)) 
     390      (or visited 
     391          ;; We created this buffer, so we should kill it. 
     392          (kill-buffer (current-buffer)))) 
     393    (not done-any))) 
    382394  
    383395;;;###autoload 
     
    458470                (search-backward "\f" nil t))) 
    459471          (or (eq found 'up-to-date) 
    460               (and (eq found 'new) 
    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)))) 
     472              (setq no-autoloads (generate-file-autoloads file))))) 
    491473      (and save-after 
    492474           (buffer-modified-p)