| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
(require 'lisp-mode) |
|---|
| 36 |
(require 'help-fns) |
|---|
| 37 |
(eval-when-compile (require 'cl)) |
|---|
| 38 |
|
|---|
| 39 |
(defvar generated-autoload-file "loaddefs.el" |
|---|
| 40 |
"*File \\[update-file-autoloads] puts autoloads into. |
|---|
| 41 |
A `.el' file can set this in its local variables section to make its |
|---|
| 42 |
autoloads go somewhere else. The autoload file is assumed to contain a |
|---|
| 43 |
trailer starting with a FormFeed character.") |
|---|
| 44 |
|
|---|
| 45 |
(defconst generate-autoload-cookie ";;;###autoload" |
|---|
| 46 |
"Magic comment indicating the following form should be autoloaded. |
|---|
| 47 |
Used by \\[update-file-autoloads]. This string should be |
|---|
| 48 |
meaningless to Lisp (e.g., a comment). |
|---|
| 49 |
|
|---|
| 50 |
This string is used: |
|---|
| 51 |
|
|---|
| 52 |
;;;###autoload |
|---|
| 53 |
\(defun function-to-be-autoloaded () ...) |
|---|
| 54 |
|
|---|
| 55 |
If this string appears alone on a line, the following form will be |
|---|
| 56 |
read and an autoload made for it. If there is further text on the line, |
|---|
| 57 |
that text will be copied verbatim to `generated-autoload-file'.") |
|---|
| 58 |
|
|---|
| 59 |
(defconst generate-autoload-section-header "\f\n;;;### " |
|---|
| 60 |
"String that marks the form at the start of a new file's autoload section.") |
|---|
| 61 |
|
|---|
| 62 |
(defconst generate-autoload-section-trailer "\n;;;***\n" |
|---|
| 63 |
"String which indicates the end of the section of autoloads for a file.") |
|---|
| 64 |
|
|---|
| 65 |
(defconst generate-autoload-section-continuation ";;;;;; " |
|---|
| 66 |
"String to add on each continuation of the section header form.") |
|---|
| 67 |
|
|---|
| 68 |
(defun make-autoload (form file) |
|---|
| 69 |
"Turn FORM into an autoload or defvar for source file FILE. |
|---|
| 70 |
Returns nil if FORM is not a special autoload form (i.e. a function definition |
|---|
| 71 |
or macro definition or a defcustom)." |
|---|
| 72 |
(let ((car (car-safe form)) expand) |
|---|
| 73 |
(cond |
|---|
| 74 |
|
|---|
| 75 |
((and (memq car '(easy-mmode-define-global-mode define-global-minor-mode |
|---|
| 76 |
define-globalized-minor-mode |
|---|
| 77 |
easy-mmode-define-minor-mode define-minor-mode)) |
|---|
| 78 |
(setq expand (let ((load-file-name file)) (macroexpand form))) |
|---|
| 79 |
(eq (car expand) 'progn) |
|---|
| 80 |
(memq :autoload-end expand)) |
|---|
| 81 |
(let ((end (memq :autoload-end expand))) |
|---|
| 82 |
|
|---|
| 83 |
(setcdr end nil) |
|---|
| 84 |
(cons 'progn |
|---|
| 85 |
(mapcar (lambda (form) (make-autoload form file)) |
|---|
| 86 |
(cdr expand))))) |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
((memq car '(defun define-skeleton defmacro define-derived-mode |
|---|
| 90 |
define-compilation-mode define-generic-mode |
|---|
| 91 |
easy-mmode-define-global-mode define-global-minor-mode |
|---|
| 92 |
define-globalized-minor-mode |
|---|
| 93 |
easy-mmode-define-minor-mode define-minor-mode |
|---|
| 94 |
defun* defmacro*)) |
|---|
| 95 |
(let* ((macrop (memq car '(defmacro defmacro*))) |
|---|
| 96 |
(name (nth 1 form)) |
|---|
| 97 |
(args (case car |
|---|
| 98 |
((defun defmacro defun* defmacro*) (nth 2 form)) |
|---|
| 99 |
((define-skeleton) '(&optional str arg)) |
|---|
| 100 |
((define-generic-mode define-derived-mode |
|---|
| 101 |
define-compilation-mode) nil) |
|---|
| 102 |
(t))) |
|---|
| 103 |
(body (nthcdr (get car 'doc-string-elt) form)) |
|---|
| 104 |
(doc (if (stringp (car body)) (pop body)))) |
|---|
| 105 |
(when (listp args) |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
(setq doc (help-add-fundoc-usage doc args))) |
|---|
| 109 |
|
|---|
| 110 |
(list 'autoload (if (listp name) name (list 'quote name)) file doc |
|---|
| 111 |
(or (and (memq car '(define-skeleton define-derived-mode |
|---|
| 112 |
define-generic-mode |
|---|
| 113 |
easy-mmode-define-global-mode |
|---|
| 114 |
define-global-minor-mode |
|---|
| 115 |
define-globalized-minor-mode |
|---|
| 116 |
easy-mmode-define-minor-mode |
|---|
| 117 |
define-minor-mode)) t) |
|---|
| 118 |
(eq (car-safe (car body)) 'interactive)) |
|---|
| 119 |
(if macrop (list 'quote 'macro) nil)))) |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
((eq car 'defcustom) |
|---|
| 123 |
(let ((varname (car-safe (cdr-safe form))) |
|---|
| 124 |
(init (car-safe (cdr-safe (cdr-safe form)))) |
|---|
| 125 |
(doc (car-safe (cdr-safe (cdr-safe (cdr-safe form))))) |
|---|
| 126 |
|
|---|
| 127 |
) |
|---|
| 128 |
`(progn |
|---|
| 129 |
(defvar ,varname ,init ,doc) |
|---|
| 130 |
(custom-autoload ',varname ,file |
|---|
| 131 |
,(condition-case nil |
|---|
| 132 |
(null (cadr (memq :set form))) |
|---|
| 133 |
(error nil)))))) |
|---|
| 134 |
|
|---|
| 135 |
((eq car 'defgroup) |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
(let ((groupname (nth 1 form))) |
|---|
| 140 |
`(let ((loads (get ',groupname 'custom-loads))) |
|---|
| 141 |
(if (member ',file loads) nil |
|---|
| 142 |
(put ',groupname 'custom-loads (cons ',file loads)))))) |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
(t nil)))) |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
(defun autoload-trim-file-name (file) |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
(setq file (expand-file-name file)) |
|---|
| 160 |
(file-relative-name file |
|---|
| 161 |
(file-name-directory generated-autoload-file))) |
|---|
| 162 |
|
|---|
| 163 |
(defun autoload-read-section-header () |
|---|
| 164 |
"Read a section header form. |
|---|
| 165 |
Since continuation lines have been marked as comments, |
|---|
| 166 |
we must copy the text of the form and remove those comment |
|---|
| 167 |
markers before we call `read'." |
|---|
| 168 |
(save-match-data |
|---|
| 169 |
(let ((beginning (point)) |
|---|
| 170 |
string) |
|---|
| 171 |
(forward-line 1) |
|---|
| 172 |
(while (looking-at generate-autoload-section-continuation) |
|---|
| 173 |
(forward-line 1)) |
|---|
| 174 |
(setq string (buffer-substring beginning (point))) |
|---|
| 175 |
(with-current-buffer (get-buffer-create " *autoload*") |
|---|
| 176 |
(erase-buffer) |
|---|
| 177 |
(insert string) |
|---|
| 178 |
(goto-char (point-min)) |
|---|
| 179 |
(while (search-forward generate-autoload-section-continuation nil t) |
|---|
| 180 |
(replace-match " ")) |
|---|
| 181 |
(goto-char (point-min)) |
|---|
| 182 |
(read (current-buffer)))))) |
|---|
| 183 |
|
|---|
| 184 |
(defvar autoload-print-form-outbuf nil |
|---|
| 185 |
"Buffer which gets the output of `autoload-print-form'.") |
|---|
| 186 |
|
|---|
| 187 |
(defun autoload-print-form (form) |
|---|
| 188 |
"Print FORM such that `make-docfile' will find the docstrings. |
|---|
| 189 |
The variable `autoload-print-form-outbuf' specifies the buffer to |
|---|
| 190 |
put the output in." |
|---|
| 191 |
(cond |
|---|
| 192 |
|
|---|
| 193 |
((eq (car form) 'progn) (mapcar 'autoload-print-form (cdr form))) |
|---|
| 194 |
|
|---|
| 195 |
((symbolp form) nil) |
|---|
| 196 |
(t |
|---|
| 197 |
(let ((doc-string-elt (get (car-safe form) 'doc-string-elt)) |
|---|
| 198 |
(outbuf autoload-print-form-outbuf)) |
|---|
| 199 |
(if (and doc-string-elt (stringp (nth doc-string-elt form))) |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
(let* ((p (nthcdr (1- doc-string-elt) form)) |
|---|
| 204 |
(elt (cdr p))) |
|---|
| 205 |
(setcdr p nil) |
|---|
| 206 |
(princ "\n(" outbuf) |
|---|
| 207 |
(let ((print-escape-newlines t) |
|---|
| 208 |
(print-escape-nonascii t)) |
|---|
| 209 |
(dolist (elt form) |
|---|
| 210 |
(prin1 elt outbuf) |
|---|
| 211 |
(princ " " outbuf))) |
|---|
| 212 |
(princ "\"\\\n" outbuf) |
|---|
| 213 |
(let ((begin (with-current-buffer outbuf (point)))) |
|---|
| 214 |
(princ (substring (prin1-to-string (car elt)) 1) |
|---|
| 215 |
outbuf) |
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
(with-current-buffer outbuf |
|---|
| 220 |
(save-excursion |
|---|
| 221 |
(while (re-search-backward "\n[[(]" begin t) |
|---|
| 222 |
(forward-char 1) |
|---|
| 223 |
(insert "\\")))) |
|---|
| 224 |
(if (null (cdr elt)) |
|---|
| 225 |
(princ ")" outbuf) |
|---|
| 226 |
(princ " " outbuf) |
|---|
| 227 |
(princ (substring (prin1-to-string (cdr elt)) 1) |
|---|
| 228 |
outbuf)) |
|---|
| 229 |
(terpri outbuf))) |
|---|
| 230 |
(let ((print-escape-newlines t) |
|---|
| 231 |
(print-escape-nonascii t)) |
|---|
| 232 |
(print form outbuf))))))) |
|---|
| 233 |
|
|---|
| 234 |
(defun autoload-ensure-default-file (file) |
|---|
| 235 |
"Make sure that the autoload file FILE exists and if not create it." |
|---|
| 236 |
(unless (file-exists-p file) |
|---|
| 237 |
(write-region |
|---|
| 238 |
(concat ";;; " (file-name-nondirectory file) |
|---|
| 239 |
" --- automatically extracted autoloads\n" |
|---|
| 240 |
";;\n" |
|---|
| 241 |
";;; Code:\n\n" |
|---|
| 242 |
"\n;; Local Variables:\n" |
|---|
| 243 |
";; version-control: never\n" |
|---|
| 244 |
";; no-byte-compile: t\n" |
|---|
| 245 |
";; no-update-autoloads: t\n" |
|---|
| 246 |
";; End:\n" |
|---|
| 247 |
";;; " (file-name-nondirectory file) |
|---|
| 248 |
" ends here\n") |
|---|
| 249 |
nil file)) |
|---|
| 250 |
file) |
|---|
| 251 |
|
|---|
| 252 |
(defun autoload-insert-section-header (outbuf autoloads load-name file time) |
|---|
| 253 |
"Insert the section-header line, |
|---|
| 254 |
which lists the file name and which functions are in it, etc." |
|---|
| 255 |
(insert generate-autoload-section-header) |
|---|
| 256 |
(prin1 (list 'autoloads autoloads load-name |
|---|
| 257 |
(if (stringp file) (autoload-trim-file-name file) file) |
|---|
| 258 |
time) |
|---|
| 259 |
outbuf) |
|---|
| 260 |
(terpri outbuf) |
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
(with-current-buffer outbuf |
|---|
| 264 |
(save-excursion |
|---|
| 265 |
(forward-line -1) |
|---|
| 266 |
(while (not (eolp)) |
|---|
| 267 |
(move-to-column 64) |
|---|
| 268 |
(skip-chars-forward "^ \n") |
|---|
| 269 |
(or (eolp) |
|---|
| 270 |
(insert "\n" generate-autoload-section-continuation)))))) |
|---|
| 271 |
|
|---|
| 272 |
(defun autoload-find-file (file) |
|---|
| 273 |
"Fetch file and put it in a temp buffer. Return the buffer." |
|---|
| 274 |
|
|---|
| 275 |
(with-current-buffer (get-buffer-create " *autoload-file*") |
|---|
| 276 |
(kill-all-local-variables) |
|---|
| 277 |
(erase-buffer) |
|---|
| 278 |
(setq buffer-undo-list t |
|---|
| 279 |
buffer-read-only nil) |
|---|
| 280 |
(emacs-lisp-mode) |
|---|
| 281 |
(insert-file-contents file nil) |
|---|
| 282 |
(let ((enable-local-variables :safe)) |
|---|
| 283 |
(hack-local-variables)) |
|---|
| 284 |
(current-buffer))) |
|---|
| 285 |
|
|---|
| 286 |
(defvar no-update-autoloads nil |
|---|
| 287 |
"File local variable to prevent scanning this file for autoload cookies.") |
|---|
| 288 |
|
|---|
| 289 |
(defun generate-file-autoloads (file) |
|---|
| 290 |
"Insert at point a loaddefs autoload section for FILE. |
|---|
| 291 |
Autoloads are generated for defuns and defmacros in FILE |
|---|
| 292 |
marked by `generate-autoload-cookie' (which see). |
|---|
| 293 |
If FILE is being visited in a buffer, the contents of the buffer |
|---|
| 294 |
are used. |
|---|
| 295 |
Return non-nil in the case where no autoloads were added at point." |
|---|
| 296 |
(interactive "fGenerate autoloads for file: ") |
|---|
| 297 |
(let ((outbuf (current-buffer)) |
|---|
| 298 |
(autoloads-done '()) |
|---|
| 299 |
(load-name (let ((name (file-name-nondirectory file))) |
|---|
| 300 |
(if (string-match "\\.elc?\\(\\.\\|$\\)" name) |
|---|
| 301 |
(substring name 0 (match-beginning 0)) |
|---|
| 302 |
name))) |
|---|
| 303 |
(print-length nil) |
|---|
| 304 |
(print-readably t) |
|---|
| 305 |
(float-output-format nil) |
|---|
| 306 |
(done-any nil) |
|---|
| 307 |
(visited (get-file-buffer file)) |
|---|
| 308 |
output-start) |
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
|
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
(setq file (expand-file-name file)) |
|---|
| 318 |
(let* ((source-truename (file-truename file)) |
|---|
| 319 |
(dir-truename (file-name-as-directory |
|---|
| 320 |
(file-truename default-directory))) |
|---|
| 321 |
(len (length dir-truename))) |
|---|
| 322 |
(if (and (< len (length source-truename)) |
|---|
| 323 |
(string= dir-truename (substring source-truename 0 len))) |
|---|
| 324 |
(setq file (substring source-truename len)))) |
|---|
| 325 |
|
|---|
| 326 |
(with-current-buffer (or visited |
|---|
| 327 |
|
|---|
| 328 |
(autoload-find-file file)) |
|---|
| 329 |
|
|---|
| 330 |
(unless no-update-autoloads |
|---|
| 331 |
(message "Generating autoloads for %s..." file) |
|---|
| 332 |
(setq output-start (with-current-buffer outbuf (point))) |
|---|
| 333 |
(save-excursion |
|---|
| 334 |
(save-restriction |
|---|
| 335 |
(widen) |
|---|
| 336 |
(goto-char (point-min)) |
|---|
| 337 |
(while (not (eobp)) |
|---|
| 338 |
(skip-chars-forward " \t\n\f") |
|---|
| 339 |
(cond |
|---|
| 340 |
((looking-at (regexp-quote generate-autoload-cookie)) |
|---|
| 341 |
(search-forward generate-autoload-cookie) |
|---|
| 342 |
(skip-chars-forward " \t") |
|---|
| 343 |
(setq done-any t) |
|---|
| 344 |
(if (eolp) |
|---|
| 345 |
|
|---|
| 346 |
(let* ((form (prog1 (read (current-buffer)) |
|---|
| 347 |
(or (bolp) (forward-line 1)))) |
|---|
| 348 |
(autoload (make-autoload form load-name))) |
|---|
| 349 |
(if autoload |
|---|
| 350 |
(push (nth 1 form) autoloads-done) |
|---|
| 351 |
(setq autoload form)) |
|---|
| 352 |
(let ((autoload-print-form-outbuf outbuf)) |
|---|
| 353 |
(autoload-print-form autoload))) |
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
(princ (buffer-substring |
|---|
| 357 |
(progn |
|---|
| 358 |
|
|---|
| 359 |
(skip-chars-backward " \f\t") |
|---|
| 360 |
(if (= (char-after (1+ (point))) ? ) |
|---|
| 361 |
|
|---|
| 362 |
(forward-char 1)) |
|---|
| 363 |
(point)) |
|---|
| 364 |
(progn (forward-line 1) (point))) |
|---|
| 365 |
outbuf))) |
|---|
| 366 |
((looking-at ";") |
|---|
| 367 |
|
|---|
| 368 |
(forward-line 1)) |
|---|
| 369 |
(t |
|---|
| 370 |
(forward-sexp 1) |
|---|
| 371 |
(forward-line 1)))))) |
|---|
| 372 |
|
|---|
| 373 |
(when done-any |
|---|
| 374 |
(with-current-buffer outbuf |
|---|
| 375 |
(save-excursion |
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
(goto-char output-start) |
|---|
| 379 |
(autoload-insert-section-header |
|---|
| 380 |
outbuf autoloads-done load-name file |
|---|
| 381 |
(nth 5 (file-attributes file))) |
|---|
| 382 |
(insert ";;; Generated autoloads from " |
|---|
| 383 |
(autoload-trim-file-name file) "\n")) |
|---|
| 384 |
(insert generate-autoload-section-trailer))) |
|---|
| 385 |
(message "Generating autoloads for %s...done" file)) |
|---|
| 386 |
(or visited |
|---|
| 387 |
|
|---|
| 388 |
(kill-buffer (current-buffer)))) |
|---|
| 389 |
(not done-any))) |
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
(defun update-file-autoloads (file &optional save-after) |
|---|
| 393 |
"Update the autoloads for FILE in `generated-autoload-file' |
|---|
| 394 |
\(which FILE might bind in its local variables). |
|---|
| 395 |
If SAVE-AFTER is non-nil (which is always, when called interactively), |
|---|
| 396 |
save the buffer too. |
|---|
| 397 |
|
|---|
| 398 |
Return FILE if there was no autoload cookie in it, else nil." |
|---|
| 399 |
(interactive "fUpdate autoloads for file: \np") |
|---|
| 400 |
(let ((load-name (let ((name (file-name-nondirectory file))) |
|---|
| 401 |
(if (string-match "\\.elc?\\(\\.\\|$\\)" name) |
|---|
| 402 |
(substring name 0 (match-beginning 0)) |
|---|
| 403 |
name))) |
|---|
| 404 |
(found nil) |
|---|
| 405 |
(existing-buffer (get-file-buffer file)) |
|---|
| 406 |
(no-autoloads nil)) |
|---|
| 407 |
(save-excursion |
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
(if existing-buffer |
|---|
| 411 |
(set-buffer existing-buffer)) |
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
(let ((coding-system-for-read 'raw-text)) |
|---|
| 415 |
(set-buffer (find-file-noselect |
|---|
| 416 |
(autoload-ensure-default-file |
|---|
| 417 |
(expand-file-name generated-autoload-file |
|---|
| 418 |
(expand-file-name "lisp" |
|---|
| 419 |
source-directory))))) |
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
(setq buffer-file-coding-system 'raw-text-unix)) |
|---|
| 423 |
(or (> (buffer-size) 0) |
|---|
| 424 |
(error "Autoloads file %s does not exist" buffer-file-name)) |
|---|
| 425 |
(or (file-writable-p buffer-file-name) |
|---|
| 426 |
(error "Autoloads file %s is not writable" buffer-file-name)) |
|---|
| 427 |
(save-excursion |
|---|
| 428 |
(save-restriction |
|---|
| 429 |
(widen) |
|---|
| 430 |
(goto-char (point-min)) |
|---|
| 431 |
|
|---|
| 432 |
(while (and (not found) |
|---|
| 433 |
(search-forward generate-autoload-section-header nil t)) |
|---|
| 434 |
(let ((form (autoload-read-section-header))) |
|---|
| 435 |
(cond ((string= (nth 2 form) load-name) |
|---|
| 436 |
|
|---|
| 437 |
|
|---|
| 438 |
(let ((begin (match-beginning 0)) |
|---|
| 439 |
(last-time (nth 4 form)) |
|---|
| 440 |
(file-time (nth 5 (file-attributes file)))) |
|---|
| 441 |
(if (and (or (null existing-buffer) |
|---|
| 442 |
(not (buffer-modified-p existing-buffer))) |
|---|
| 443 |
(listp last-time) (= (length last-time) 2) |
|---|
| 444 |
(not (time-less-p last-time file-time))) |
|---|
| 445 |
(progn |
|---|
| 446 |
(if (interactive-p) |
|---|
| 447 |
(message "\ |
|---|
| 448 |
Autoload section for %s is up to date." |
|---|
| 449 |
file)) |
|---|
| 450 |
(setq found 'up-to-date)) |
|---|
| 451 |
(search-forward generate-autoload-section-trailer) |
|---|
| 452 |
(delete-region begin (point)) |
|---|
| 453 |
(setq found t)))) |
|---|
| 454 |
((string< load-name (nth 2 form)) |
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
(goto-char (match-beginning 0)) |
|---|
| 460 |
(setq found 'new))))) |
|---|
| 461 |
(or found |
|---|
| 462 |
(progn |
|---|
| 463 |
(setq found 'new) |
|---|
| 464 |
|
|---|
| 465 |
(goto-char (point-max)) |
|---|
| 466 |
(search-backward "\f" nil t))) |
|---|
| 467 |
(or (eq found 'up-to-date) |
|---|
| 468 |
(setq no-autoloads (generate-file-autoloads file))))) |
|---|
| 469 |
(and save-after |
|---|
| 470 |
(buffer-modified-p) |
|---|
| 471 |
(save-buffer)) |
|---|
| 472 |
|
|---|
| 473 |
(if no-autoloads file)))) |
|---|
| 474 |
|
|---|
| 475 |
(defun autoload-remove-section (begin) |
|---|
| 476 |
(goto-char begin) |
|---|
| 477 |
(search-forward generate-autoload-section-trailer) |
|---|
| 478 |
(delete-region begin (point))) |
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
(defun update-directory-autoloads (&rest dirs) |
|---|
| 482 |
"\ |
|---|
| 483 |
Update loaddefs.el with all the current autoloads from DIRS, and no old ones. |
|---|
| 484 |
This uses `update-file-autoloads' (which see) to do its work. |
|---|
| 485 |
In an interactive call, you must give one argument, the name |
|---|
| 486 |
of a single directory. In a call from Lisp, you can supply multiple |
|---|
| 487 |
directories as separate arguments, but this usage is discouraged. |
|---|
| 488 |
|
|---|
| 489 |
The function does NOT recursively descend into subdirectories of the |
|---|
| 490 |
directory or directories specified." |
|---|
| 491 |
(interactive "DUpdate autoloads from directory: ") |
|---|
| 492 |
(let* ((files-re (let ((tmp nil)) |
|---|
| 493 |
(dolist (suf (get-load-suffixes) |
|---|
| 494 |
(concat "^[^=.].*" (regexp-opt tmp t) "\\'")) |
|---|
| 495 |
(unless (string-match "\\.elc" suf) (push suf tmp))))) |
|---|
| 496 |
(files (apply 'nconc |
|---|
| 497 |
(mapcar (lambda (dir) |
|---|
| 498 |
(directory-files (expand-file-name dir) |
|---|
| 499 |
t files-re)) |
|---|
| 500 |
dirs))) |
|---|
| 501 |
(this-time (current-time)) |
|---|
| 502 |
(no-autoloads nil) |
|---|
| 503 |
(autoloads-file |
|---|
| 504 |
(expand-file-name generated-autoload-file |
|---|
| 505 |
(expand-file-name "lisp" source-directory))) |
|---|
| 506 |
(top-dir (file-name-directory autoloads-file))) |
|---|
| 507 |
|
|---|
| 508 |
(with-current-buffer |
|---|
| 509 |
(find-file-noselect (autoload-ensure-default-file autoloads-file)) |
|---|
| 510 |
(save-excursion |
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
(setq files (delete (autoload-trim-file-name buffer-file-name) |
|---|
| 514 |
(mapcar 'autoload-trim-file-name files))) |
|---|
| 515 |
|
|---|
| 516 |
(goto-char (point-min)) |
|---|
| 517 |
(while (search-forward generate-autoload-section-header nil t) |
|---|
| 518 |
(let* ((form (autoload-read-section-header)) |
|---|
| 519 |
(file (nth 3 form))) |
|---|
| 520 |
(cond ((and (consp file) (stringp (car file))) |
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 |
(autoload-remove-section (match-beginning 0)) |
|---|
| 525 |
(let ((last-time (nth 4 form))) |
|---|
| 526 |
(dolist (file file) |
|---|
| 527 |
(let ((file-time (nth 5 (file-attributes file)))) |
|---|
| 528 |
(when (and file-time |
|---|
| 529 |
(not (time-less-p last-time file-time))) |
|---|
| 530 |
|
|---|
| 531 |
(push file no-autoloads) |
|---|
| 532 |
(setq files (delete file files))))))) |
|---|
| 533 |
((not (stringp file))) |
|---|
| 534 |
((not (file-exists-p (expand-file-name file top-dir))) |
|---|
| 535 |
|
|---|
| 536 |
(autoload-remove-section (match-beginning 0))) |
|---|
| 537 |
((equal (nth 4 form) (nth 5 (file-attributes file))) |
|---|
| 538 |
|
|---|
| 539 |
nil) |
|---|
| 540 |
(t |
|---|
| 541 |
(update-file-autoloads file))) |
|---|
| 542 |
(setq files (delete file files))))) |
|---|
| 543 |
|
|---|
| 544 |
(setq no-autoloads |
|---|
| 545 |
(append no-autoloads |
|---|
| 546 |
(delq nil (mapcar 'update-file-autoloads files)))) |
|---|
| 547 |
(when no-autoloads |
|---|
| 548 |
|
|---|
| 549 |
(setq no-autoloads (sort no-autoloads 'string<)) |
|---|
| 550 |
|
|---|
| 551 |
(goto-char (point-max)) |
|---|
| 552 |
(search-backward "\f" nil t) |
|---|
| 553 |
(autoload-insert-section-header |
|---|
| 554 |
(current-buffer) nil nil no-autoloads this-time) |
|---|
| 555 |
(insert generate-autoload-section-trailer)) |
|---|
| 556 |
|
|---|
| 557 |
(save-buffer)))) |
|---|
| 558 |
|
|---|
| 559 |
(define-obsolete-function-alias 'update-autoloads-from-directories |
|---|
| 560 |
'update-directory-autoloads "22.1") |
|---|
| 561 |
|
|---|
| 562 |
|
|---|
| 563 |
(defun batch-update-autoloads () |
|---|
| 564 |
"Update loaddefs.el autoloads in batch mode. |
|---|
| 565 |
Calls `update-directory-autoloads' on the command line arguments." |
|---|
| 566 |
(apply 'update-directory-autoloads command-line-args-left) |
|---|
| 567 |
(setq command-line-args-left nil)) |
|---|
| 568 |
|
|---|
| 569 |
(provide 'autoload) |
|---|
| 570 |
|
|---|
| 571 |
|
|---|
| 572 |
|
|---|
| 573 |
|
|---|