comparison lisp/emacs-lisp/autoload.el @ 29416:6d8ceb166666

(make-autoload): Simplify docstring. Make use of symbol-property doc-string-elt. Use memq rather than a sequence of eq. (doc-string-elt): Fix the wrong or missing previously unused values. (autoload-print-form): New function extracted from generate-file-autoloads to allow recursion when handling progn so that defvar's and defun's docstrings are properly printed. (generate-file-autoloads): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 05 Jun 2000 06:30:22 +0000
parents 206604013d7f
children a6cd51379a76
comparison
equal deleted inserted replaced
29415:bf26ee36792e 29416:6d8ceb166666
60 (defconst generate-autoload-section-continuation ";;;;;; " 60 (defconst generate-autoload-section-continuation ";;;;;; "
61 "String to add on each continuation of the section header form.") 61 "String to add on each continuation of the section header form.")
62 62
63 (defun make-autoload (form file) 63 (defun make-autoload (form file)
64 "Turn FORM into an autoload or defvar for source file FILE. 64 "Turn FORM into an autoload or defvar for source file FILE.
65 Returns nil if FORM is not a `defun', `define-skeleton', 65 Returns nil if FORM is not a function or variable or macro definition."
66 `define-derived-mode', `define-generic-mode', `defmacro', `defcustom',
67 `define-minor-mode' or `easy-mmode-define-minor-mode'."
68 (let ((car (car-safe form))) 66 (let ((car (car-safe form)))
69 (if (memq car '(defun define-skeleton defmacro define-derived-mode 67 (if (memq car '(defun define-skeleton defmacro define-derived-mode
70 define-generic-mode easy-mmode-define-minor-mode 68 define-generic-mode easy-mmode-define-minor-mode
71 define-minor-mode defun*)) 69 define-minor-mode defun*))
72 (let ((macrop (eq car 'defmacro)) 70 (let ((macrop (eq car 'defmacro))
73 name doc) 71 (name (nth 1 form))
74 (setq form (cdr form) 72 (body (nthcdr (get car 'doc-string-elt) form))
75 name (car form) 73 (doc (if (stringp (car body)) (pop body))))
76 ;; Ignore the arguments.
77 form (cdr (cond
78 ((memq car '(define-skeleton define-minor-mode
79 easy-mmode-define-minor-mode)) form)
80 ((eq car 'define-derived-mode) (cdr (cdr form)))
81 ((eq car 'define-generic-mode)
82 (cdr (cdr (cdr (cdr (cdr form))))))
83 (t (cdr form))))
84 doc (car form))
85 (if (stringp doc)
86 (setq form (cdr form))
87 (setq doc nil))
88 ;; `define-generic-mode' quotes the name, so take care of that 74 ;; `define-generic-mode' quotes the name, so take care of that
89 (list 'autoload (if (listp name) name (list 'quote name)) file doc 75 (list 'autoload (if (listp name) name (list 'quote name)) file doc
90 (or (eq car 'define-skeleton) (eq car 'define-derived-mode) 76 (or (and (memq car '(define-skeleton define-derived-mode
91 (eq car 'define-generic-mode) 77 define-generic-mode
92 (eq car 'easy-mmode-define-minor-mode) 78 easy-mmode-define-minor-mode
93 (eq car 'define-minor-mode) 79 define-minor-mode)) t)
94 (eq (car-safe (car form)) 'interactive)) 80 (eq (car-safe (car form)) 'interactive))
95 (if macrop (list 'quote 'macro) nil))) 81 (if macrop (list 'quote 'macro) nil)))
96 ;; Convert defcustom to a simpler (and less space-consuming) defvar, 82 ;; Convert defcustom to a simpler (and less space-consuming) defvar,
97 ;; but add some extra stuff if it uses :require. 83 ;; but add some extra stuff if it uses :require.
98 (if (eq car 'defcustom) 84 (if (eq car 'defcustom)
128 ;;; which have autoloaded entries *and* are processed by make-docfile; 114 ;;; which have autoloaded entries *and* are processed by make-docfile;
129 ;;; there should be no such files. 115 ;;; there should be no such files.
130 116
131 (put 'autoload 'doc-string-elt 3) 117 (put 'autoload 'doc-string-elt 3)
132 (put 'defun 'doc-string-elt 3) 118 (put 'defun 'doc-string-elt 3)
119 (put 'defun* 'doc-string-elt 3)
133 (put 'defvar 'doc-string-elt 3) 120 (put 'defvar 'doc-string-elt 3)
134 (put 'defcustom 'doc-string-elt 3) 121 (put 'defcustom 'doc-string-elt 3)
135 (put 'defconst 'doc-string-elt 3) 122 (put 'defconst 'doc-string-elt 3)
136 (put 'defmacro 'doc-string-elt 3) 123 (put 'defmacro 'doc-string-elt 3)
137 (put 'defsubst 'doc-string-elt 3) 124 (put 'defsubst 'doc-string-elt 3)
138 (put 'define-skeleton 'doc-string-elt 3) 125 (put 'define-skeleton 'doc-string-elt 2)
139 (put 'define-derived-mode 'doc-string-elt 3) 126 (put 'define-derived-mode 'doc-string-elt 4)
140 (put 'easy-mmode-define-minor-mode 'doc-string-elt 3) 127 (put 'easy-mmode-define-minor-mode 'doc-string-elt 2)
141 (put 'define-minor-mode 'doc-string-elt 3) 128 (put 'define-minor-mode 'doc-string-elt 2)
142 (put 'define-generic-mode 'doc-string-elt 3) 129 (put 'define-generic-mode 'doc-string-elt 7)
143 130
144 131
145 (defun autoload-trim-file-name (file) 132 (defun autoload-trim-file-name (file)
146 ;; Returns a relative pathname of FILE 133 ;; Returns a relative pathname of FILE
147 ;; starting from the directory that loaddefs.el is in. 134 ;; starting from the directory that loaddefs.el is in.
170 (goto-char (point-min)) 157 (goto-char (point-min))
171 (while (search-forward generate-autoload-section-continuation nil t) 158 (while (search-forward generate-autoload-section-continuation nil t)
172 (replace-match " ")) 159 (replace-match " "))
173 (goto-char (point-min)) 160 (goto-char (point-min))
174 (read (current-buffer)))))) 161 (read (current-buffer))))))
162
163 ;; !! Requires OUTBUF to be bound !!
164 (defun autoload-print-form (form)
165 "Print FORM such that make-docfile will find the docstrings."
166 (cond
167 ;; If the form is a sequence, recurse.
168 ((eq (car form) 'progn) (mapcar 'autoload-print-form (cdr form)))
169 ;; Symbols at the toplevel are meaningless.
170 ((symbolp form) nil)
171 (t
172 (let ((doc-string-elt (get (car-safe form) 'doc-string-elt)))
173 (if (and doc-string-elt (stringp (nth doc-string-elt form)))
174 ;; We need to hack the printing because the
175 ;; doc-string must be printed specially for
176 ;; make-docfile (sigh).
177 (let* ((p (nthcdr (1- doc-string-elt) form))
178 (elt (cdr p)))
179 (setcdr p nil)
180 (princ "\n(" outbuf)
181 (let ((print-escape-newlines t)
182 (print-escape-nonascii t))
183 (mapcar (lambda (elt)
184 (prin1 elt outbuf)
185 (princ " " outbuf))
186 form))
187 (princ "\"\\\n" outbuf)
188 (let ((begin (with-current-buffer outbuf (point))))
189 (princ (substring (prin1-to-string (car elt)) 1)
190 outbuf)
191 ;; Insert a backslash before each ( that
192 ;; appears at the beginning of a line in
193 ;; the doc string.
194 (with-current-buffer outbuf
195 (save-excursion
196 (while (search-backward "\n(" begin t)
197 (forward-char 1)
198 (insert "\\"))))
199 (if (null (cdr elt))
200 (princ ")" outbuf)
201 (princ " " outbuf)
202 (princ (substring (prin1-to-string (cdr elt)) 1)
203 outbuf))
204 (terpri outbuf)))
205 (let ((print-escape-newlines t)
206 (print-escape-nonascii t))
207 (print form outbuf)))))))
175 208
176 (defun generate-file-autoloads (file) 209 (defun generate-file-autoloads (file)
177 "Insert at point a loaddefs autoload section for FILE. 210 "Insert at point a loaddefs autoload section for FILE.
178 autoloads are generated for defuns and defmacros in FILE 211 autoloads are generated for defuns and defmacros in FILE
179 marked by `generate-autoload-cookie' (which see). 212 marked by `generate-autoload-cookie' (which see).
235 (skip-chars-forward " \t") 268 (skip-chars-forward " \t")
236 (setq done-any t) 269 (setq done-any t)
237 (if (eolp) 270 (if (eolp)
238 ;; Read the next form and make an autoload. 271 ;; Read the next form and make an autoload.
239 (let* ((form (prog1 (read (current-buffer)) 272 (let* ((form (prog1 (read (current-buffer))
240 (or (bolp) (forward-line 1)))) 273 (or (bolp) (forward-line 1))))
241 (autoload-1 (make-autoload form load-name)) 274 (autoload (make-autoload form load-name)))
242 (autoload (if (eq (car autoload-1) 'progn)
243 (cadr autoload-1)
244 autoload-1))
245 (doc-string-elt (get (car-safe form)
246 'doc-string-elt)))
247 (if autoload 275 (if autoload
248 (setq autoloads-done (cons (nth 1 form) 276 (setq autoloads-done (cons (nth 1 form)
249 autoloads-done)) 277 autoloads-done))
250 (setq autoload form)) 278 (setq autoload form))
251 (if (and doc-string-elt 279 (autoload-print-form autoload))
252 (stringp (nth doc-string-elt autoload))) 280
253 ;; We need to hack the printing because the 281 ;; Copy the rest of the line to the output.
254 ;; doc-string must be printed specially for
255 ;; make-docfile (sigh).
256 (let* ((p (nthcdr (1- doc-string-elt)
257 autoload))
258 (elt (cdr p)))
259 (setcdr p nil)
260 (princ "\n(" outbuf)
261 (let ((print-escape-newlines t)
262 (print-escape-nonascii t))
263 (mapcar (function (lambda (elt)
264 (prin1 elt outbuf)
265 (princ " " outbuf)))
266 autoload))
267 (princ "\"\\\n" outbuf)
268 (let ((begin (save-excursion
269 (set-buffer outbuf)
270 (point))))
271 (princ (substring
272 (prin1-to-string (car elt)) 1)
273 outbuf)
274 ;; Insert a backslash before each ( that
275 ;; appears at the beginning of a line in
276 ;; the doc string.
277 (save-excursion
278 (set-buffer outbuf)
279 (save-excursion
280 (while (search-backward "\n(" begin t)
281 (forward-char 1)
282 (insert "\\"))))
283 (if (null (cdr elt))
284 (princ ")" outbuf)
285 (princ " " outbuf)
286 (princ (substring
287 (prin1-to-string (cdr elt))
288 1)
289 outbuf))
290 (terpri outbuf)))
291 (let ((print-escape-newlines t)
292 (print-escape-nonascii t))
293 (print autoload outbuf)))
294 (if (eq (car autoload-1) 'progn)
295 ;; Print the rest of the form
296 (let ((print-escape-newlines t)
297 (print-escape-nonascii t))
298 (mapcar (function (lambda (elt)
299 (print elt outbuf)))
300 (cddr autoload-1)))))
301 ;; Copy the rest of the line to the output.
302 (princ (buffer-substring 282 (princ (buffer-substring
303 (progn 283 (progn
304 ;; Back up over whitespace, to preserve it. 284 ;; Back up over whitespace, to preserve it.
305 (skip-chars-backward " \f\t") 285 (skip-chars-backward " \f\t")
306 (if (= (char-after (1+ (point))) ? ) 286 (if (= (char-after (1+ (point))) ? )