Mercurial > hg > xemacs-beta
comparison lisp/cl-macs.el @ 4695:fee33ab25966
Add arglist info for autoloaded functions and macros.
lisp/ChangeLog addition:
2009-09-20 Aidan Kehoe <kehoea@parhasard.net>
Add arglist information to docstrings for autoloaded functions and
macros.
* hyper-apropos.el (hyper-apropos-get-doc):
Treat autoload docstrings like subr docstrings; correct the regexp
used.
* help.el (describe-function-show-arglist):
This no longer treats autoloads specially.
(function-arglist): Treat autoload docstrings like subr docstrings.
(function-documentation): Treat documentation strings that are
zero-length after the arglist has been removed as indicating a
lack of documentation.
* cl-macs.el (case):
(ecase):
(typecase):
(etypecase):
(block):
(return):
(return-from):
(progv):
(lexical-let):
(lexical-let*):
(remf):
(callf):
(callf2):
(define-modify-macro):
(deftype):
(define-compiler-macro):
Rely on the autoload code to always show an arglist for these
functions, don't supply an ad-hoc one in the docstring.
These changes are for the most obvious functions; there are some
missed that would require changing argument names in the docstring
or in the function bodies.
* autoload.el (make-autoload):
Add arg list information to the doc string, using the same
approach as for subrs.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 20 Sep 2009 23:50:05 +0100 |
parents | 2ac296807b88 |
children | eb1a409c317b |
comparison
equal
deleted
inserted
replaced
4694:2ac296807b88 | 4695:fee33ab25966 |
---|---|
608 | 608 |
609 ;;; Conditional control structures. | 609 ;;; Conditional control structures. |
610 | 610 |
611 ;;;###autoload | 611 ;;;###autoload |
612 (defmacro case (expr &rest clauses) | 612 (defmacro case (expr &rest clauses) |
613 "(case EXPR CLAUSES...): evals EXPR, chooses from CLAUSES on that value. | 613 "Evals EXPR, chooses from CLAUSES on that value. |
614 Each clause looks like (KEYLIST BODY...). EXPR is evaluated and compared | 614 Each clause looks like (KEYLIST BODY...). EXPR is evaluated and compared |
615 against each key in each KEYLIST; the corresponding BODY is evaluated. | 615 against each key in each KEYLIST; the corresponding BODY is evaluated. |
616 If no clause succeeds, case returns nil. A single atom may be used in | 616 If no clause succeeds, case returns nil. A single atom may be used in |
617 place of a KEYLIST of one atom. A KEYLIST of `t' or `otherwise' is | 617 place of a KEYLIST of one atom. A KEYLIST of `t' or `otherwise' is |
618 allowed only in the final clause, and matches if no other keys match. | 618 allowed only in the final clause, and matches if no other keys match. |
653 ;; anything to introduce it, as there is probably much more CL stuff | 653 ;; anything to introduce it, as there is probably much more CL stuff |
654 ;; missing, and the feature is not essential. --hniksic | 654 ;; missing, and the feature is not essential. --hniksic |
655 | 655 |
656 ;;;###autoload | 656 ;;;###autoload |
657 (defmacro ecase (expr &rest clauses) | 657 (defmacro ecase (expr &rest clauses) |
658 "(ecase EXPR CLAUSES...): like `case', but error if no case fits. | 658 "Like `case', but error if no case fits. |
659 `otherwise'-clauses are not allowed." | 659 `otherwise'-clauses are not allowed." |
660 ;; XEmacs addition: disallow t and otherwise | 660 ;; XEmacs addition: disallow t and otherwise |
661 (let ((disallowed (or (assq t clauses) | 661 (let ((disallowed (or (assq t clauses) |
662 (assq 'otherwise clauses)))) | 662 (assq 'otherwise clauses)))) |
663 (if disallowed | 663 (if disallowed |
664 (error "`%s' is not allowed in ecase" (car disallowed)))) | 664 (error "`%s' is not allowed in ecase" (car disallowed)))) |
665 (list* 'case expr (append clauses '((ecase-error-flag))))) | 665 (list* 'case expr (append clauses '((ecase-error-flag))))) |
666 | 666 |
667 ;;;###autoload | 667 ;;;###autoload |
668 (defmacro typecase (expr &rest clauses) | 668 (defmacro typecase (expr &rest clauses) |
669 "(typecase EXPR CLAUSES...): evals EXPR, chooses from CLAUSES on that value. | 669 "Evals EXPR, chooses from CLAUSES on that value. |
670 Each clause looks like (TYPE BODY...). EXPR is evaluated and, if it | 670 Each clause looks like (TYPE BODY...). EXPR is evaluated and, if it |
671 satisfies TYPE, the corresponding BODY is evaluated. If no clause succeeds, | 671 satisfies TYPE, the corresponding BODY is evaluated. If no clause succeeds, |
672 typecase returns nil. A TYPE of `t' or `otherwise' is allowed only in the | 672 typecase returns nil. A TYPE of `t' or `otherwise' is allowed only in the |
673 final clause, and matches if no other keys match." | 673 final clause, and matches if no other keys match." |
674 (let* ((temp (if (cl-simple-expr-p expr 3) expr (gensym))) | 674 (let* ((temp (if (cl-simple-expr-p expr 3) expr (gensym))) |
689 (if (eq temp expr) body | 689 (if (eq temp expr) body |
690 (list 'let (list (list temp expr)) body)))) | 690 (list 'let (list (list temp expr)) body)))) |
691 | 691 |
692 ;;;###autoload | 692 ;;;###autoload |
693 (defmacro etypecase (expr &rest clauses) | 693 (defmacro etypecase (expr &rest clauses) |
694 "(etypecase EXPR CLAUSES...): like `typecase', but error if no case fits. | 694 "Like `typecase', but error if no case fits. |
695 `otherwise'-clauses are not allowed." | 695 `otherwise'-clauses are not allowed." |
696 (list* 'typecase expr (append clauses '((ecase-error-flag))))) | 696 (list* 'typecase expr (append clauses '((ecase-error-flag))))) |
697 | 697 |
698 | 698 |
699 ;;; Blocks and exits. | 699 ;;; Blocks and exits. |
700 | 700 |
701 ;;;###autoload | 701 ;;;###autoload |
702 (defmacro block (name &rest body) | 702 (defmacro block (name &rest body) |
703 "(block NAME BODY...): define a lexically-scoped block named NAME. | 703 "Define a lexically-scoped block named NAME. |
704 NAME may be any symbol. Code inside the BODY forms can call `return-from' | 704 NAME may be any symbol. Code inside the BODY forms can call `return-from' |
705 to jump prematurely out of the block. This differs from `catch' and `throw' | 705 to jump prematurely out of the block. This differs from `catch' and `throw' |
706 in two respects: First, the NAME is an unevaluated symbol rather than a | 706 in two respects: First, the NAME is an unevaluated symbol rather than a |
707 quoted symbol or other form; and second, NAME is lexically rather than | 707 quoted symbol or other form; and second, NAME is lexically rather than |
708 dynamically scoped: Only references to it within BODY will work. These | 708 dynamically scoped: Only references to it within BODY will work. These |
740 (if cl-found (setcdr cl-found t))) | 740 (if cl-found (setcdr cl-found t))) |
741 (byte-compile-throw (cons 'throw (cdr cl-form))))) | 741 (byte-compile-throw (cons 'throw (cdr cl-form))))) |
742 | 742 |
743 ;;;###autoload | 743 ;;;###autoload |
744 (defmacro return (&optional result) | 744 (defmacro return (&optional result) |
745 "(return [RESULT]): return from the block named nil. | 745 "Return from the block named nil. |
746 This is equivalent to `(return-from nil RESULT)'." | 746 This is equivalent to `(return-from nil RESULT)'." |
747 (list 'return-from nil result)) | 747 (list 'return-from nil result)) |
748 | 748 |
749 ;;;###autoload | 749 ;;;###autoload |
750 (defmacro return-from (name &optional result) | 750 (defmacro return-from (name &optional result) |
751 "(return-from NAME [RESULT]): return from the block named NAME. | 751 "Return from the block named NAME. |
752 This jumps out to the innermost enclosing `(block NAME ...)' form, | 752 This jumps out to the innermost enclosing `(block NAME ...)' form, |
753 returning RESULT from that form (or nil if RESULT is omitted). | 753 returning RESULT from that form (or nil if RESULT is omitted). |
754 This is compatible with Common Lisp, but note that `defun' and | 754 This is compatible with Common Lisp, but note that `defun' and |
755 `defmacro' do not create implicit blocks as they do in Common Lisp." | 755 `defmacro' do not create implicit blocks as they do in Common Lisp." |
756 (let ((name2 (intern (format "--cl-block-%s--" name)))) | 756 (let ((name2 (intern (format "--cl-block-%s--" name)))) |
1701 | 1701 |
1702 ;;; Binding control structures. | 1702 ;;; Binding control structures. |
1703 | 1703 |
1704 ;;;###autoload | 1704 ;;;###autoload |
1705 (defmacro progv (symbols values &rest body) | 1705 (defmacro progv (symbols values &rest body) |
1706 "(progv SYMBOLS VALUES BODY...): bind SYMBOLS to VALUES dynamically in BODY. | 1706 "Bind SYMBOLS to VALUES dynamically in BODY. |
1707 The forms SYMBOLS and VALUES are evaluated, and must evaluate to lists. | 1707 The forms SYMBOLS and VALUES are evaluated, and must evaluate to lists. |
1708 Each SYMBOL in the first list is bound to the corresponding VALUE in the | 1708 Each SYMBOL in the first list is bound to the corresponding VALUE in the |
1709 second list (or made unbound if VALUES is shorter than SYMBOLS); then the | 1709 second list (or made unbound if VALUES is shorter than SYMBOLS); then the |
1710 BODY forms are executed and their result is returned. This is much like | 1710 BODY forms are executed and their result is returned. This is much like |
1711 a `let' form, except that the list of symbols can be computed at run-time." | 1711 a `let' form, except that the list of symbols can be computed at run-time." |
1790 cl-macro-environment))))) | 1790 cl-macro-environment))))) |
1791 | 1791 |
1792 (defvar cl-closure-vars nil) | 1792 (defvar cl-closure-vars nil) |
1793 ;;;###autoload | 1793 ;;;###autoload |
1794 (defmacro lexical-let (bindings &rest body) | 1794 (defmacro lexical-let (bindings &rest body) |
1795 "(lexical-let BINDINGS BODY...): like `let', but lexically scoped. | 1795 "Like `let', but lexically scoped. |
1796 The main visible difference is that lambdas inside BODY will create | 1796 The main visible difference is that lambdas inside BODY will create |
1797 lexical closures as in Common Lisp." | 1797 lexical closures as in Common Lisp." |
1798 (let* ((cl-closure-vars cl-closure-vars) | 1798 (let* ((cl-closure-vars cl-closure-vars) |
1799 (vars (mapcar #'(lambda (x) | 1799 (vars (mapcar #'(lambda (x) |
1800 (or (consp x) (setq x (list x))) | 1800 (or (consp x) (setq x (list x))) |
1830 vars)) | 1830 vars)) |
1831 ebody)))) | 1831 ebody)))) |
1832 | 1832 |
1833 ;;;###autoload | 1833 ;;;###autoload |
1834 (defmacro lexical-let* (bindings &rest body) | 1834 (defmacro lexical-let* (bindings &rest body) |
1835 "(lexical-let* BINDINGS BODY...): like `let*', but lexically scoped. | 1835 "Like `let*', but lexically scoped. |
1836 The main visible difference is that lambdas inside BODY will create | 1836 The main visible difference is that lambdas inside BODY will create |
1837 lexical closures as in Common Lisp." | 1837 lexical closures as in Common Lisp." |
1838 (if (null bindings) (cons 'progn body) | 1838 (if (null bindings) (cons 'progn body) |
1839 (setq bindings (reverse bindings)) | 1839 (setq bindings (reverse bindings)) |
1840 (while bindings | 1840 (while bindings |
2519 (list 'car temp) | 2519 (list 'car temp) |
2520 (cl-setf-do-store (nth 1 method) (list 'cdr temp))))))) | 2520 (cl-setf-do-store (nth 1 method) (list 'cdr temp))))))) |
2521 | 2521 |
2522 ;;;###autoload | 2522 ;;;###autoload |
2523 (defmacro remf (place tag) | 2523 (defmacro remf (place tag) |
2524 "(remf PLACE TAG): remove TAG from property list PLACE. | 2524 "Remove TAG from property list PLACE. |
2525 PLACE may be a symbol, or any generalized variable allowed by `setf'. | 2525 PLACE may be a symbol, or any generalized variable allowed by `setf'. |
2526 The form returns true if TAG was found and removed, nil otherwise." | 2526 The form returns true if TAG was found and removed, nil otherwise." |
2527 (let* ((method (cl-setf-do-modify place t)) | 2527 (let* ((method (cl-setf-do-modify place t)) |
2528 (tag-temp (and (not (cl-const-expr-p tag)) (gensym "--remf-tag--"))) | 2528 (tag-temp (and (not (cl-const-expr-p tag)) (gensym "--remf-tag--"))) |
2529 (val-temp (and (not (cl-simple-expr-p place)) | 2529 (val-temp (and (not (cl-simple-expr-p place)) |
2658 (setq body (list (list* 'letf (list (pop bindings)) body)))) | 2658 (setq body (list (list* 'letf (list (pop bindings)) body)))) |
2659 (car body))) | 2659 (car body))) |
2660 | 2660 |
2661 ;;;###autoload | 2661 ;;;###autoload |
2662 (defmacro callf (func place &rest args) | 2662 (defmacro callf (func place &rest args) |
2663 "(callf FUNC PLACE ARGS...): set PLACE to (FUNC PLACE ARGS...). | 2663 "Set PLACE to (FUNC PLACE ARGS...). |
2664 FUNC should be an unquoted function name. PLACE may be a symbol, | 2664 FUNC should be an unquoted function name. PLACE may be a symbol, |
2665 or any generalized variable allowed by `setf'." | 2665 or any generalized variable allowed by `setf'." |
2666 (let* ((method (cl-setf-do-modify place (cons 'list args))) | 2666 (let* ((method (cl-setf-do-modify place (cons 'list args))) |
2667 (rargs (cons (nth 2 method) args))) | 2667 (rargs (cons (nth 2 method) args))) |
2668 (list 'let* (car method) | 2668 (list 'let* (car method) |
2671 (list* 'funcall (list 'function func) | 2671 (list* 'funcall (list 'function func) |
2672 rargs)))))) | 2672 rargs)))))) |
2673 | 2673 |
2674 ;;;###autoload | 2674 ;;;###autoload |
2675 (defmacro callf2 (func arg1 place &rest args) | 2675 (defmacro callf2 (func arg1 place &rest args) |
2676 "(callf2 FUNC ARG1 PLACE ARGS...): set PLACE to (FUNC ARG1 PLACE ARGS...). | 2676 "Set PLACE to (FUNC ARG1 PLACE ARGS...). |
2677 Like `callf', but PLACE is the second argument of FUNC, not the first." | 2677 Like `callf', but PLACE is the second argument of FUNC, not the first." |
2678 (if (and (cl-safe-expr-p arg1) (cl-simple-expr-p place) (symbolp func)) | 2678 (if (and (cl-safe-expr-p arg1) (cl-simple-expr-p place) (symbolp func)) |
2679 (list 'setf place (list* func arg1 place args)) | 2679 (list 'setf place (list* func arg1 place args)) |
2680 (let* ((method (cl-setf-do-modify place (cons 'list args))) | 2680 (let* ((method (cl-setf-do-modify place (cons 'list args))) |
2681 (temp (and (not (cl-const-expr-p arg1)) (gensym "--arg1--"))) | 2681 (temp (and (not (cl-const-expr-p arg1)) (gensym "--arg1--"))) |
2686 (list* 'funcall (list 'function func) | 2686 (list* 'funcall (list 'function func) |
2687 rargs))))))) | 2687 rargs))))))) |
2688 | 2688 |
2689 ;;;###autoload | 2689 ;;;###autoload |
2690 (defmacro define-modify-macro (name arglist func &optional doc) | 2690 (defmacro define-modify-macro (name arglist func &optional doc) |
2691 "(define-modify-macro NAME ARGLIST FUNC): define a `setf'-like modify macro. | 2691 "Define a `setf'-like modify macro. |
2692 If NAME is called, it combines its PLACE argument with the other arguments | 2692 If NAME is called, it combines its PLACE argument with the other arguments |
2693 from ARGLIST using FUNC: (define-modify-macro incf (&optional (n 1)) +)" | 2693 from ARGLIST using FUNC: (define-modify-macro incf (&optional (n 1)) +)" |
2694 (if (memq '&key arglist) (error "&key not allowed in define-modify-macro")) | 2694 (if (memq '&key arglist) (error "&key not allowed in define-modify-macro")) |
2695 (let ((place (gensym "--place--"))) | 2695 (let ((place (gensym "--place--"))) |
2696 (list 'defmacro* name (cons place arglist) doc | 2696 (list 'defmacro* name (cons place arglist) doc |
2940 | 2940 |
2941 ;;; Types and assertions. | 2941 ;;; Types and assertions. |
2942 | 2942 |
2943 ;;;###autoload | 2943 ;;;###autoload |
2944 (defmacro deftype (name arglist &rest body) | 2944 (defmacro deftype (name arglist &rest body) |
2945 "(deftype NAME ARGLIST BODY...): define NAME as a new data type. | 2945 "Define NAME as a new data type. |
2946 The type name can then be used in `typecase', `check-type', etc." | 2946 The type name can then be used in `typecase', `check-type', etc." |
2947 (list 'eval-when '(compile load eval) | 2947 (list 'eval-when '(compile load eval) |
2948 (cl-transform-function-property | 2948 (cl-transform-function-property |
2949 name 'cl-deftype-handler (cons (list* '&cl-defs ''('*) arglist) body)))) | 2949 name 'cl-deftype-handler (cons (list* '&cl-defs ''('*) arglist) body)))) |
2950 | 2950 |
3048 | 3048 |
3049 ;;; Compiler macros. | 3049 ;;; Compiler macros. |
3050 | 3050 |
3051 ;;;###autoload | 3051 ;;;###autoload |
3052 (defmacro define-compiler-macro (func args &rest body) | 3052 (defmacro define-compiler-macro (func args &rest body) |
3053 "(define-compiler-macro FUNC ARGLIST BODY...): Define a compiler-only macro. | 3053 "Define a compiler-only macro. |
3054 This is like `defmacro', but macro expansion occurs only if the call to | 3054 This is like `defmacro', but macro expansion occurs only if the call to |
3055 FUNC is compiled (i.e., not interpreted). Compiler macros should be used | 3055 FUNC is compiled (i.e., not interpreted). Compiler macros should be used |
3056 for optimizing the way calls to FUNC are compiled; the form returned by | 3056 for optimizing the way calls to FUNC are compiled; the form returned by |
3057 BODY should do the same thing as a call to the normal function called | 3057 BODY should do the same thing as a call to the normal function called |
3058 FUNC, though possibly more efficiently. Note that, like regular macros, | 3058 FUNC, though possibly more efficiently. Note that, like regular macros, |