comparison lisp/emacs-lisp/autoload.el @ 3777:d6f56b9586f7

(make-autoload): Use memq once instead eq twice. (generate-file-autoloads): For non-autoloads, copy the defn textually rather than printing it after reading.
author Roland McGrath <roland@gnu.org>
date Wed, 16 Jun 1993 23:06:58 +0000
parents 3b0cb275ca29
children 21c6c1e1a38b
comparison
equal deleted inserted replaced
3776:301e2dca5fd7 3777:d6f56b9586f7
32 32
33 (defun make-autoload (form file) 33 (defun make-autoload (form file)
34 "Turn FORM, a defun or defmacro, into an autoload for source file FILE. 34 "Turn FORM, a defun or defmacro, into an autoload for source file FILE.
35 Returns nil if FORM is not a defun or defmacro." 35 Returns nil if FORM is not a defun or defmacro."
36 (let ((car (car-safe form))) 36 (let ((car (car-safe form)))
37 (if (or (eq car 'defun) (eq car 'defmacro)) 37 (if (memq car '(defun defmacro))
38 (let (name doc macrop) 38 (let ((macrop (eq car 'defmacro))
39 (setq macrop (eq car 'defmacro)) 39 name doc)
40 (setq form (cdr form)) 40 (setq form (cdr form))
41 (setq name (car form)) 41 (setq name (car form))
42 ;; Ignore the arguments. 42 ;; Ignore the arguments.
43 (setq form (cdr (cdr form))) 43 (setq form (cdr (cdr form)))
44 (setq doc (car form)) 44 (setq doc (car form))
144 (search-forward generate-autoload-cookie) 144 (search-forward generate-autoload-cookie)
145 (skip-chars-forward " \t") 145 (skip-chars-forward " \t")
146 (setq done-any t) 146 (setq done-any t)
147 (if (eolp) 147 (if (eolp)
148 ;; Read the next form and make an autoload. 148 ;; Read the next form and make an autoload.
149 (let* ((form (prog1 (read (current-buffer)) 149 (let* ((before (point))
150 (form (prog1 (read (current-buffer))
150 (forward-line 1))) 151 (forward-line 1)))
151 (autoload (make-autoload form load-name)) 152 (autoload (make-autoload form load-name))
152 (doc-string-elt (get (car-safe form) 153 (doc-string-elt (get (car-safe form)
153 'doc-string-elt))) 154 'doc-string-elt)))
154 (if autoload 155 (if (null autoload)
155 (setq autoloads-done (cons (nth 1 form) 156 ;; We are copying a defvar or defconst form.
156 autoloads-done)) 157 ;; Copy the text instead of printing the form,
157 (setq autoload form)) 158 ;; so as to preserve the original formatting.
158 (if (and doc-string-elt 159 (let ((inbuf (current-buffer))
159 (stringp (nth doc-string-elt autoload))) 160 (after (point)))
160 ;; We need to hack the printing because the 161 (save-excursion
161 ;; doc-string must be printed specially for 162 (set-buffer outbuf)
162 ;; make-docfile (sigh). 163 ;; Insert the form.
163 (let* ((p (nthcdr (1- doc-string-elt) 164 (insert-buffer-substring inbuf before after)
164 autoload)) 165 (and doc-string-elt
165 (elt (cdr p))) 166 (stringp (nth doc-string-elt form))
166 (setcdr p nil) 167 ;; The form has a docstring.
167 (princ "\n(" outbuf) 168 ;; Hack it for make-docfile.
168 (mapcar (function (lambda (elt) 169 (save-excursion
169 (prin1 elt outbuf) 170 ;; Move point back to FORM's start.
170 (princ " " outbuf))) 171 (backward-char (- after before))
171 autoload) 172 (skip-chars-forward " \t\n")
172 (princ "\"\\\n" outbuf) 173 (or (looking-at "(")
173 (princ (substring 174 (error "expected ("))
174 (prin1-to-string (car elt)) 1) 175 (forward-char 1) ; Skip the paren.
175 outbuf) 176 ;; Skip sexps before the docstring.
176 (if (null (cdr elt)) 177 (forward-sexp doc-string-elt)
177 (princ ")" outbuf) 178 (skip-chars-forward " \t")
178 (princ " " outbuf) 179 (if (eolp) (delete-char 1))
180 (skip-chars-forward " \t")
181 (or (looking-at "\"")
182 (error "expected \""))
183 (forward-char 1) ; Skip the ".
184 (insert "\\\n"))) ;make-docfile happy.
185 (goto-char after)))
186 ;; Write the autoload for this defun or defmacro.
187 (setq autoloads-done (cons (nth 1 form)
188 autoloads-done))
189 (if (and doc-string-elt
190 (stringp (nth doc-string-elt autoload)))
191 ;; We need to hack the printing because the
192 ;; doc-string must be printed specially for
193 ;; make-docfile (sigh).
194 (let* ((p (nthcdr (1- doc-string-elt)
195 autoload))
196 (elt (cdr p)))
197 (setcdr p nil)
198 (princ "\n(" outbuf)
199 (mapcar (function (lambda (elt)
200 (prin1 elt outbuf)
201 (princ " " outbuf)))
202 autoload)
203 (princ "\"\\\n" outbuf)
179 (princ (substring 204 (princ (substring
180 (prin1-to-string (cdr elt)) 205 (prin1-to-string (car elt)) 1)
181 1) 206 outbuf)
182 outbuf)) 207 (if (null (cdr elt))
183 (terpri outbuf)) 208 (princ ")" outbuf)
184 (print autoload outbuf))) 209 (princ " " outbuf)
210 (princ (substring
211 (prin1-to-string (cdr elt))
212 1)
213 outbuf))
214 (terpri outbuf))
215 (print autoload outbuf))))
185 ;; Copy the rest of the line to the output. 216 ;; Copy the rest of the line to the output.
186 (let ((begin (point))) 217 (let ((begin (point)))
187 (forward-line 1) 218 (forward-line 1)
188 (princ (buffer-substring begin (point)) outbuf)))) 219 (princ (buffer-substring begin (point)) outbuf))))
189 ((looking-at ";") 220 ((looking-at ";")
190 ;; Don't read the comment. 221 ;; Don't read the comment.
191 (forward-line 1)) 222 (forward-line 1))
192 (t 223 (t
193 (forward-sexp 1) 224 (forward-sexp 1)
194 (forward-line 1))))))) 225 (forward-line 1)))))))
195 (or visited 226 (or visited
196 ;; We created this buffer, so we should kill it. 227 ;; We created this buffer, so we should kill it.
197 (kill-buffer (current-buffer))) 228 (kill-buffer (current-buffer)))
198 (set-buffer outbuf) 229 (set-buffer outbuf)
199 (setq output-end (point-marker)))) 230 (setq output-end (point-marker))))