aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-07-16 16:24:59 +0000
committerStefan Monnier2002-07-16 16:24:59 +0000
commit2dbbed9ebae41715a52b2c80328b59cb51caee6a (patch)
treec8962929eb19c9aeeb61d08705ec5edf38118518
parentae1bb8acec2fc3b699a17f2d0f22a12debad3cfb (diff)
downloademacs-2dbbed9ebae41715a52b2c80328b59cb51caee6a.tar.gz
emacs-2dbbed9ebae41715a52b2c80328b59cb51caee6a.zip
(help-split-fundoc, help-function-arglist)
(help-make-usage): New funs, extracted from describe-function-1. (describe-function-1): Use them.
-rw-r--r--lisp/help-fns.el115
1 files changed, 53 insertions, 62 deletions
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index f07510ee205..c79aa356b78 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -165,6 +165,38 @@ and the file name is displayed in the echo area."
165 ;; Return the text we displayed. 165 ;; Return the text we displayed.
166 (buffer-string)))))) 166 (buffer-string))))))
167 167
168(defun help-split-fundoc (doc &optional def)
169 "Split a function docstring DOC into the actual doc and the usage info.
170Return (USAGE . DOC) or nil if there's no usage info."
171 ;; Builtins get the calling sequence at the end of the doc string.
172 ;; In cases where `function' has been fset to a subr we can't search for
173 ;; function's name in the doc string. Kluge round that using the printed
174 ;; representation. The arg list then shows the wrong function name, but
175 ;; that might be a useful hint.
176 (let* ((rep (prin1-to-string def))
177 (name (if (string-match " \\([^ ]+\\)>$" rep)
178 (match-string 1 rep) "fun")))
179 (if (string-match (format "^(%s[ )].*\\'" (regexp-quote name)) doc)
180 (cons (match-string 0 doc)
181 (substring doc 0 (match-beginning 0))))))
182
183(defun help-function-arglist (def)
184 (cond
185 ((byte-code-function-p def) (aref def 0))
186 ((eq (car-safe def) 'lambda) (nth 1 def))
187 ((and (eq (car-safe def) 'autoload) (not (eq (nth 4 def) 'keymap)))
188 "[Arg list not available until function definition is loaded.]")
189 (t t)))
190
191(defun help-make-usage (function arglist)
192 (cons (if (symbolp function) function 'anonymous)
193 (mapcar (lambda (arg)
194 (if (not (symbolp arg)) arg
195 (let ((name (symbol-name arg)))
196 (if (string-match "\\`&" name) arg
197 (intern (upcase name))))))
198 arglist)))
199
168;;;###autoload 200;;;###autoload
169(defun describe-function-1 (function) 201(defun describe-function-1 (function)
170 (let* ((def (if (symbolp function) 202 (let* ((def (if (symbolp function)
@@ -248,7 +280,7 @@ and the file name is displayed in the echo area."
248 (when (commandp function) 280 (when (commandp function)
249 (let* ((remapped (remap-command function)) 281 (let* ((remapped (remap-command function))
250 (keys (where-is-internal 282 (keys (where-is-internal
251 (or remapped function) overriding-local-map nil nil))) 283 (or remapped function) overriding-local-map nil nil)))
252 (when remapped 284 (when remapped
253 (princ "It is remapped to `") 285 (princ "It is remapped to `")
254 (princ (symbol-name remapped)) 286 (princ (symbol-name remapped))
@@ -265,68 +297,27 @@ and the file name is displayed in the echo area."
265 ;; If definition is a macro, find the function inside it. 297 ;; If definition is a macro, find the function inside it.
266 (if (eq (car-safe def) 'macro) 298 (if (eq (car-safe def) 'macro)
267 (setq def (cdr def))) 299 (setq def (cdr def)))
268 (let ((arglist (cond ((byte-code-function-p def) 300 (let* ((arglist (help-function-arglist def))
269 (car (append def nil))) 301 (doc (documentation function))
270 ((eq (car-safe def) 'lambda) 302 usage)
271 (nth 1 def)) 303 (princ (cond
272 ((and (eq (car-safe def) 'autoload) 304 ((listp arglist) (help-make-usage function arglist))
273 (not (eq (nth 4 def) 'keymap))) 305 ((stringp arglist) arglist)
274 (concat "[Arg list not available until " 306 ((and doc (subrp def) (setq usage (help-split-fundoc doc def)))
275 "function definition is loaded.]")) 307 (setq doc (cdr usage)) (car usage))
276 (t t)))) 308 (t "[Missing arglist. Please make a bug report.]")))
277 (cond ((listp arglist) 309 (terpri)
278 (princ (cons (if (symbolp function) function "anonymous") 310 (let ((obsolete (get function 'byte-obsolete-info)))
279 (mapcar (lambda (arg) 311 (when obsolete
280 (if (memq arg '(&optional &rest)) 312 (terpri)
281 arg 313 (princ "This function is obsolete")
282 (intern (upcase (symbol-name arg))))) 314 (if (nth 2 obsolete) (princ (format " since %s" (nth 2 obsolete))))
283 arglist))) 315 (princ ";") (terpri)
284 (terpri)) 316 (princ (if (stringp (car obsolete)) (car obsolete)
285 ((stringp arglist) 317 (format "use `%s' instead." (car obsolete))))
286 (princ arglist) 318 (terpri)))
287 (terpri))))
288 (let ((obsolete (get function 'byte-obsolete-info)))
289 (when obsolete
290 (terpri)
291 (princ "This function is obsolete")
292 (if (nth 2 obsolete) (princ (format " since %s" (nth 2 obsolete))))
293 (princ ";") (terpri)
294 (princ (if (stringp (car obsolete)) (car obsolete)
295 (format "use `%s' instead." (car obsolete))))
296 (terpri)))
297 (let ((doc (documentation function)))
298 (if doc 319 (if doc
299 (progn (terpri) 320 (progn (terpri) (princ doc))
300 (princ doc)
301 (if (subrp def)
302 (with-current-buffer standard-output
303 (beginning-of-line)
304 ;; Builtins get the calling sequence at the end of
305 ;; the doc string. Move it to the same place as
306 ;; for other functions.
307
308 ;; In cases where `function' has been fset to a
309 ;; subr we can't search for function's name in
310 ;; the doc string. Kluge round that using the
311 ;; printed representation. The arg list then
312 ;; shows the wrong function name, but that
313 ;; might be a useful hint.
314 (let* ((rep (prin1-to-string def))
315 (name (progn
316 (string-match " \\([^ ]+\\)>$" rep)
317 (match-string 1 rep))))
318 (if (looking-at (format "(%s[ )]" (regexp-quote name)))
319 (let ((start (point-marker)))
320 (goto-char (point-min))
321 (forward-paragraph)
322 (insert-buffer-substring (current-buffer) start)
323 (insert ?\n)
324 (delete-region (1- start) (point-max)))
325 (goto-char (point-min))
326 (forward-paragraph)
327 (insert
328 "[Missing arglist. Please make a bug report.]\n")))
329 (goto-char (point-max)))))
330 (princ "Not documented."))))) 321 (princ "Not documented.")))))
331 322
332 323