comparison lisp/help-fns.el @ 46957:ac5b720640e7

(help-split-fundoc): Replace the function name from the docstring with the one that should be displayed. (help-make-usage): Understand CL style arglists. (describe-function-1): Adapt to the new behavior of help-split-fundoc. (describe-variable): Use delete-region.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 19 Aug 2002 21:23:08 +0000
parents 3e733b163fd4
children debd2b1e4d08
comparison
equal deleted inserted replaced
46956:2c01ee3e5305 46957:ac5b720640e7
160 (print-help-return-message) 160 (print-help-return-message)
161 (with-current-buffer standard-output 161 (with-current-buffer standard-output
162 ;; Return the text we displayed. 162 ;; Return the text we displayed.
163 (buffer-string)))))) 163 (buffer-string))))))
164 164
165 (defun help-split-fundoc (doc &optional def) 165 (defun help-split-fundoc (doc def)
166 "Split a function docstring DOC into the actual doc and the usage info. 166 "Split a function docstring DOC into the actual doc and the usage info.
167 Return (USAGE . DOC) or nil if there's no usage info." 167 Return (USAGE . DOC) or nil if there's no usage info.
168 ;; Builtins get the calling sequence at the end of the doc string. 168 DEF is the function whose usage we're looking for in DOC."
169 ;; Functions can get the calling sequence at the end of the doc string.
169 ;; In cases where `function' has been fset to a subr we can't search for 170 ;; In cases where `function' has been fset to a subr we can't search for
170 ;; function's name in the doc string. Kluge round that using the printed 171 ;; function's name in the doc string so we use `fn' as the anonymous
171 ;; representation. The arg list then shows the wrong function name, but 172 ;; function name instead.
172 ;; that might be a useful hint.
173 (when doc 173 (when doc
174 (let* ((rep (prin1-to-string def)) 174 (let* ((rep (prin1-to-string (indirect-function def)))
175 (name (if (string-match " \\([^ ]+\\)>$" rep) 175 (name (if (string-match " \\([^ ]+\\)>$" rep)
176 (match-string 1 rep) rep))) 176 (match-string 1 rep) (prin1-to-string def))))
177 (if (string-match (format "\n\n\\((\\(fn\\|%s\\)\\( .*\\)?)\\)\\'" 177 (if (string-match (format "\n\n(\\(fn\\|%s\\)\\(\\( .*\\)?)\\)\\'"
178 (regexp-quote name)) 178 (regexp-quote name))
179 doc) 179 doc)
180 (cons (match-string 1 doc) 180 (cons (format "(%s%s"
181 ;; Replace `fn' with the actual function name.
182 (if (consp def) "anonymous" def)
183 (match-string 2 doc))
181 (substring doc 0 (match-beginning 0))))))) 184 (substring doc 0 (match-beginning 0)))))))
182 185
183 (defun help-function-arglist (def) 186 (defun help-function-arglist (def)
184 ;; Handle symbols aliased to other symbols. 187 ;; Handle symbols aliased to other symbols.
185 (if (and (symbolp def) (fboundp def)) (setq def (indirect-function def))) 188 (if (and (symbolp def) (fboundp def)) (setq def (indirect-function def)))
193 (t t))) 196 (t t)))
194 197
195 (defun help-make-usage (function arglist) 198 (defun help-make-usage (function arglist)
196 (cons (if (symbolp function) function 'anonymous) 199 (cons (if (symbolp function) function 'anonymous)
197 (mapcar (lambda (arg) 200 (mapcar (lambda (arg)
198 (if (not (symbolp arg)) arg 201 (if (not (symbolp arg))
202 (if (and (consp arg) (symbolp (car arg)))
203 ;; CL style default values for optional args.
204 (cons (intern (upcase (symbol-name (car arg))))
205 (cdr arg))
206 arg)
199 (let ((name (symbol-name arg))) 207 (let ((name (symbol-name arg)))
200 (if (string-match "\\`&" name) arg 208 (if (string-match "\\`&" name) arg
201 (intern (upcase name)))))) 209 (intern (upcase name))))))
202 arglist))) 210 arglist)))
203 211
293 ;; FIXME: This list can be very long (f.ex. for self-insert-command). 301 ;; FIXME: This list can be very long (f.ex. for self-insert-command).
294 (princ (mapconcat 'key-description keys ", "))) 302 (princ (mapconcat 'key-description keys ", ")))
295 (when (or remapped keys) 303 (when (or remapped keys)
296 (princ ".") 304 (princ ".")
297 (terpri)))) 305 (terpri))))
298 ;; Handle symbols aliased to other symbols.
299 (setq def (indirect-function def))
300 (let* ((arglist (help-function-arglist def)) 306 (let* ((arglist (help-function-arglist def))
301 (doc (documentation function)) 307 (doc (documentation function))
302 (usage (help-split-fundoc doc def))) 308 (usage (help-split-fundoc doc function)))
303 ;; If definition is a keymap, skip arglist note. 309 ;; If definition is a keymap, skip arglist note.
304 (unless (keymapp def) 310 (unless (keymapp def)
305 (princ (cond 311 (princ (cond
306 (usage (setq doc (cdr usage)) (car usage)) 312 (usage (setq doc (cdr usage)) (car usage))
307 ((listp arglist) (help-make-usage function arglist)) 313 ((listp arglist) (help-make-usage function arglist))
310 ((let ((fun function)) 316 ((let ((fun function))
311 (while (and (symbolp fun) 317 (while (and (symbolp fun)
312 (setq fun (symbol-function fun)) 318 (setq fun (symbol-function fun))
313 (not (setq usage (help-split-fundoc 319 (not (setq usage (help-split-fundoc
314 (documentation fun) 320 (documentation fun)
315 def))))) 321 function)))))
316 usage) 322 usage)
317 (car usage)) 323 (car usage))
318 (t "[Missing arglist. Please make a bug report.]"))) 324 (t "[Missing arglist. Please make a bug report.]")))
319 (terpri)) 325 (terpri))
320 (let ((obsolete (and 326 (let ((obsolete (and
390 (terpri) 396 (terpri)
391 (let ((from (point))) 397 (let ((from (point)))
392 (pp val) 398 (pp val)
393 (help-xref-on-pp from (point)) 399 (help-xref-on-pp from (point))
394 (if (< (point) (+ from 20)) 400 (if (< (point) (+ from 20))
395 (save-excursion 401 (delete-region (1- from) from)))))
396 (goto-char from)
397 (delete-char -1))))))
398 (terpri) 402 (terpri)
399 (when (local-variable-p variable) 403 (when (local-variable-p variable)
400 (princ (format "Local in buffer %s; " (buffer-name))) 404 (princ (format "Local in buffer %s; " (buffer-name)))
401 (if (not (default-boundp variable)) 405 (if (not (default-boundp variable))
402 (princ "globally void") 406 (princ "globally void")