diff options
| author | Stefan Monnier | 2019-07-29 11:56:11 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2019-07-29 11:56:11 -0400 |
| commit | 75361be63fcd42497dd1eb93cab3255833334475 (patch) | |
| tree | b67e1dda5333f799e5df850765e1d68e8d1c77dd | |
| parent | b47ca8125b39b871328da114637449a86050baa5 (diff) | |
| download | emacs-75361be63fcd42497dd1eb93cab3255833334475.tar.gz emacs-75361be63fcd42497dd1eb93cab3255833334475.zip | |
* lisp/emacs-lisp/cl-macs.el (cl-defstruct): Add slot option :documentation
Use it to improve the docstring of the accessor functions.
* doc/misc/cl.texi: Rename menu entry to "CL-Lib".
(Structures): Add ':documentation' and mention ':type' as well,
which we don't completely ignore any more.
| -rw-r--r-- | doc/misc/cl.texi | 26 | ||||
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/emacs-lisp/cl-macs.el | 17 |
3 files changed, 32 insertions, 14 deletions
diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index a9197602634..afe8f01f596 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi | |||
| @@ -24,7 +24,7 @@ modify this GNU manual.'' | |||
| 24 | 24 | ||
| 25 | @dircategory Emacs lisp libraries | 25 | @dircategory Emacs lisp libraries |
| 26 | @direntry | 26 | @direntry |
| 27 | * CL: (cl). Partial Common Lisp support for Emacs Lisp. | 27 | * CL-Lib: (cl). Partial Common Lisp support for Emacs Lisp. |
| 28 | @end direntry | 28 | @end direntry |
| 29 | 29 | ||
| 30 | @finalout | 30 | @finalout |
| @@ -4036,12 +4036,6 @@ is either a slot symbol or a list of the form @samp{(@var{slot-name} | |||
| 4036 | is a Lisp form that is evaluated any time an instance of the | 4036 | is a Lisp form that is evaluated any time an instance of the |
| 4037 | structure type is created without specifying that slot's value. | 4037 | structure type is created without specifying that slot's value. |
| 4038 | 4038 | ||
| 4039 | Common Lisp defines several slot options, but the only one | ||
| 4040 | implemented in this package is @code{:read-only}. A non-@code{nil} | ||
| 4041 | value for this option means the slot should not be @code{setf}-able; | ||
| 4042 | the slot's value is determined when the object is created and does | ||
| 4043 | not change afterward. | ||
| 4044 | |||
| 4045 | @example | 4039 | @example |
| 4046 | (cl-defstruct person | 4040 | (cl-defstruct person |
| 4047 | (name nil :read-only t) | 4041 | (name nil :read-only t) |
| @@ -4049,7 +4043,23 @@ not change afterward. | |||
| 4049 | (sex 'unknown)) | 4043 | (sex 'unknown)) |
| 4050 | @end example | 4044 | @end example |
| 4051 | 4045 | ||
| 4052 | Any slot options other than @code{:read-only} are ignored. | 4046 | @var{slot-options} is a list of keyword-value pairs, where the |
| 4047 | following keywords can be used: | ||
| 4048 | |||
| 4049 | @table @code | ||
| 4050 | @item :read-only | ||
| 4051 | A non-nil value means the slot should not be @code{setf}-able; | ||
| 4052 | the slot's value is determined when the object is created and does | ||
| 4053 | not change afterward. | ||
| 4054 | |||
| 4055 | @item :type | ||
| 4056 | The expected type of the values held in this slot. | ||
| 4057 | |||
| 4058 | @item :documentation | ||
| 4059 | A documentation string describing the slot. | ||
| 4060 | @end table | ||
| 4061 | |||
| 4062 | Other slot options are currently ignored. | ||
| 4053 | 4063 | ||
| 4054 | For obscure historical reasons, structure options take a different | 4064 | For obscure historical reasons, structure options take a different |
| 4055 | form than slot options. A structure option is either a keyword | 4065 | form than slot options. A structure option is either a keyword |
| @@ -535,6 +535,9 @@ be functions. | |||
| 535 | *** 'cl-defstruct' has a new ':noinline' argument to prevent inlining | 535 | *** 'cl-defstruct' has a new ':noinline' argument to prevent inlining |
| 536 | its functions. | 536 | its functions. |
| 537 | 537 | ||
| 538 | +++ | ||
| 539 | *** `cl-defstruct' slots accept a ':documentation' property | ||
| 540 | |||
| 538 | --- | 541 | --- |
| 539 | *** 'cl-values-list' will now signal an error if its argument isn't a list. | 542 | *** 'cl-values-list' will now signal an error if its argument isn't a list. |
| 540 | 543 | ||
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index 8b9224bd1b7..1ae72666244 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el | |||
| @@ -2722,8 +2722,10 @@ node `(cl)Structures' for the description of the options. | |||
| 2722 | Each SLOT may instead take the form (SNAME SDEFAULT SOPTIONS...), where | 2722 | Each SLOT may instead take the form (SNAME SDEFAULT SOPTIONS...), where |
| 2723 | SDEFAULT is the default value of that slot and SOPTIONS are keyword-value | 2723 | SDEFAULT is the default value of that slot and SOPTIONS are keyword-value |
| 2724 | pairs for that slot. | 2724 | pairs for that slot. |
| 2725 | Currently, only one keyword is supported, `:read-only'. If this has a | 2725 | Supported keywords for slots are: |
| 2726 | non-nil value, that slot cannot be set via `setf'. | 2726 | - `:read-only': If this has a non-nil value, that slot cannot be set via `setf'. |
| 2727 | - `:documentation': this is a docstring describing the slot. | ||
| 2728 | - `:type': the type of the field; currently unused. | ||
| 2727 | 2729 | ||
| 2728 | \(fn NAME &optional DOCSTRING &rest SLOTS)" | 2730 | \(fn NAME &optional DOCSTRING &rest SLOTS)" |
| 2729 | (declare (doc-string 2) (indent 1) | 2731 | (declare (doc-string 2) (indent 1) |
| @@ -2902,14 +2904,17 @@ non-nil value, that slot cannot be set via `setf'. | |||
| 2902 | defaults)) | 2904 | defaults)) |
| 2903 | (if (assq slot descp) | 2905 | (if (assq slot descp) |
| 2904 | (error "Duplicate slots named %s in %s" slot name)) | 2906 | (error "Duplicate slots named %s in %s" slot name)) |
| 2905 | (let ((accessor (intern (format "%s%s" conc-name slot)))) | 2907 | (let ((accessor (intern (format "%s%s" conc-name slot))) |
| 2908 | (default-value (pop desc)) | ||
| 2909 | (doc (plist-get desc :documentation))) | ||
| 2906 | (push slot slots) | 2910 | (push slot slots) |
| 2907 | (push (pop desc) defaults) | 2911 | (push default-value defaults) |
| 2908 | ;; The arg "cl-x" is referenced by name in eg pred-form | 2912 | ;; The arg "cl-x" is referenced by name in eg pred-form |
| 2909 | ;; and pred-check, so changing it is not straightforward. | 2913 | ;; and pred-check, so changing it is not straightforward. |
| 2910 | (push `(,defsym ,accessor (cl-x) | 2914 | (push `(,defsym ,accessor (cl-x) |
| 2911 | ,(format "Access slot \"%s\" of `%s' struct CL-X." | 2915 | ,(format "Access slot \"%s\" of `%s' struct CL-X.%s" |
| 2912 | slot name) | 2916 | slot name |
| 2917 | (if doc (concat "\n" doc) "")) | ||
| 2913 | (declare (side-effect-free t)) | 2918 | (declare (side-effect-free t)) |
| 2914 | ,@(and pred-check | 2919 | ,@(and pred-check |
| 2915 | (list `(or ,pred-check | 2920 | (list `(or ,pred-check |