aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-06-05 06:30:48 +0000
committerStefan Monnier2000-06-05 06:30:48 +0000
commita8add29deb4f1a75e718f656927d4663153a4cb4 (patch)
tree67531510473d740c6d148050d6ae6e5223d6daaa
parentd5b037c5bf1da10b37f97ac7a07dd7331d230de2 (diff)
downloademacs-a8add29deb4f1a75e718f656927d4663153a4cb4.tar.gz
emacs-a8add29deb4f1a75e718f656927d4663153a4cb4.zip
(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.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/emacs-lisp/autoload.el150
2 files changed, 74 insertions, 85 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 905c15ff523..46e78137c20 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,14 @@
12000-06-05 Stefan Monnier <monnier@cs.yale.edu> 12000-06-05 Stefan Monnier <monnier@cs.yale.edu>
2 2
3 * emacs-lisp/autoload.el (make-autoload): Simplify docstring.
4 Make use of symbol-property doc-string-elt.
5 Use memq rather than a sequence of eq.
6 (doc-string-elt): Fix the wrong or missing previously unused values.
7 (autoload-print-form): New function extracted from
8 generate-file-autoloads to allow recursion when handling progn
9 so that defvar's and defun's docstrings are properly printed.
10 (generate-file-autoloads): Use it.
11
3 * emacs-lisp/easy-mmode.el (easy-mmode-define-global-mode): Autoload. 12 * emacs-lisp/easy-mmode.el (easy-mmode-define-global-mode): Autoload.
4 Use find-file-hooks in the minor-mode function. 13 Use find-file-hooks in the minor-mode function.
5 Be careful not to loop indefinitely in the post-command-hook function. 14 Be careful not to loop indefinitely in the post-command-hook function.
diff --git a/lisp/emacs-lisp/autoload.el b/lisp/emacs-lisp/autoload.el
index 58f1fd0b904..8fabdb6e14a 100644
--- a/lisp/emacs-lisp/autoload.el
+++ b/lisp/emacs-lisp/autoload.el
@@ -62,35 +62,21 @@ that text will be copied verbatim to `generated-autoload-file'.")
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.
65Returns nil if FORM is not a `defun', `define-skeleton', 65Returns 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,
@@ -130,16 +116,17 @@ Returns nil if FORM is not a `defun', `define-skeleton',
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)
@@ -173,6 +160,52 @@ markers before we call `read'."
173 (goto-char (point-min)) 160 (goto-char (point-min))
174 (read (current-buffer)))))) 161 (read (current-buffer))))))
175 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)))))))
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.
178autoloads are generated for defuns and defmacros in FILE 211autoloads are generated for defuns and defmacros in FILE
@@ -237,68 +270,15 @@ are used."
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.