comparison lisp/emacs-lisp/advice.el @ 54493:d8586f19729a

(ad-subr-arglist): Simplify.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 22 Mar 2004 15:16:27 +0000
parents 695cf19ef79e
children e20bae3e3270
comparison
equal deleted inserted replaced
54492:75c387f0b055 54493:d8586f19729a
1 ;;; advice.el --- an overloading mechanism for Emacs Lisp functions 1 ;;; advice.el --- an overloading mechanism for Emacs Lisp functions
2 2
3 ;; Copyright (C) 1993,1994,2000, 2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 1993,1994,2000,01,2004 Free Software Foundation, Inc.
4 4
5 ;; Author: Hans Chalupsky <hans@cs.buffalo.edu> 5 ;; Author: Hans Chalupsky <hans@cs.buffalo.edu>
6 ;; Maintainer: FSF 6 ;; Maintainer: FSF
7 ;; Created: 12 Dec 1992 7 ;; Created: 12 Dec 1992
8 ;; Keywords: extensions, lisp, tools 8 ;; Keywords: extensions, lisp, tools
2561 (defun ad-subr-arglist (subr-name) 2561 (defun ad-subr-arglist (subr-name)
2562 "Retrieve arglist of the subr with SUBR-NAME. 2562 "Retrieve arglist of the subr with SUBR-NAME.
2563 Either use the one stored under the `ad-subr-arglist' property, 2563 Either use the one stored under the `ad-subr-arglist' property,
2564 or try to retrieve it from the docstring and cache it under 2564 or try to retrieve it from the docstring and cache it under
2565 that property, or otherwise use `(&rest ad-subr-args)'." 2565 that property, or otherwise use `(&rest ad-subr-args)'."
2566 (cond ((ad-subr-args-defined-p subr-name) 2566 (if (ad-subr-args-defined-p subr-name)
2567 (ad-get-subr-args subr-name)) 2567 (ad-get-subr-args subr-name)
2568 ;; says jwz: Should use this for Lemacs 19.8 and above: 2568 ;; says jwz: Should use this for Lemacs 19.8 and above:
2569 ;;((fboundp 'subr-min-args) 2569 ;;((fboundp 'subr-min-args)
2570 ;; ...) 2570 ;; ...)
2571 ;; says hans: I guess what Jamie means is that I should use the values 2571 ;; says hans: I guess what Jamie means is that I should use the values
2572 ;; of `subr-min-args' and `subr-max-args' to construct the subr arglist 2572 ;; of `subr-min-args' and `subr-max-args' to construct the subr arglist
2573 ;; without having to look it up via parsing the docstring, e.g., 2573 ;; without having to look it up via parsing the docstring, e.g.,
2574 ;; values 1 and 2 would suggest `(arg1 &optional arg2)' as an 2574 ;; values 1 and 2 would suggest `(arg1 &optional arg2)' as an
2575 ;; argument list. However, that won't work because there is no 2575 ;; argument list. However, that won't work because there is no
2576 ;; way to distinguish a subr with args `(a &optional b &rest c)' from 2576 ;; way to distinguish a subr with args `(a &optional b &rest c)' from
2577 ;; one with args `(a &rest c)' using that mechanism. Also, the argument 2577 ;; one with args `(a &rest c)' using that mechanism. Also, the argument
2578 ;; names from the docstring are more meaningful. Hence, I'll stick with 2578 ;; names from the docstring are more meaningful. Hence, I'll stick with
2579 ;; the old way of doing things. 2579 ;; the old way of doing things.
2580 (t (let ((doc (or (ad-real-documentation subr-name t) ""))) 2580 (let ((doc (or (ad-real-documentation subr-name t) "")))
2581 (cond ((string-match "^\\(([^\)]+)\\)\n?\\'" doc) 2581 (if (not (string-match "\n\n\\((.+)\\)\\'" doc))
2582 (ad-define-subr-args 2582 (error "The usage info is missing from the subr %s" subr-name)
2583 subr-name 2583 (ad-define-subr-args
2584 (cdr (car (read-from-string 2584 subr-name
2585 (downcase (match-string 1 doc)))))) 2585 (cdr (car (read-from-string
2586 (ad-get-subr-args subr-name)) 2586 (downcase (match-string 1 doc))))))
2587 ;; This is actually an error. 2587 (ad-get-subr-args subr-name)))))
2588 (t '(&rest ad-subr-args)))))))
2589 2588
2590 (defun ad-docstring (definition) 2589 (defun ad-docstring (definition)
2591 "Return the unexpanded docstring of DEFINITION." 2590 "Return the unexpanded docstring of DEFINITION."
2592 (let ((docstring 2591 (let ((docstring
2593 (if (ad-compiled-p definition) 2592 (if (ad-compiled-p definition)