aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2012-11-05 20:42:17 -0500
committerGlenn Morris2012-11-05 20:42:17 -0500
commitebdbfb953591230bf217151535211af5a300ee3c (patch)
treee750f2a872919270c65adb7f23a7ffda59ea8e41
parent6b3770fb9dd180abbda32383eba5e961e76d7504 (diff)
downloademacs-ebdbfb953591230bf217151535211af5a300ee3c.tar.gz
emacs-ebdbfb953591230bf217151535211af5a300ee3c.zip
Add some documentation on defining new generalized variables
* doc/lispref/variables.texi (Setting Generalized Variables): Split most of previous contents into this subsection. (Adding Generalized Variables): New subsection. * doc/lispref/elisp.texi: Add Generalized Variables subsections to detailed menu. * etc/NEWS: Mention some gv.el macros by name.
-rw-r--r--doc/lispref/ChangeLog7
-rw-r--r--doc/lispref/elisp.texi5
-rw-r--r--doc/lispref/variables.texi70
-rw-r--r--etc/NEWS2
4 files changed, 84 insertions, 0 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 8057089cf68..d97a258da34 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,10 @@
12012-11-06 Glenn Morris <rgm@gnu.org>
2
3 * variables.texi (Setting Generalized Variables):
4 Split most of previous contents into this subsection.
5 (Adding Generalized Variables): New subsection.
6 * elisp.texi: Add Generalized Variables subsections to detailed menu.
7
12012-11-05 Chong Yidong <cyd@gnu.org> 82012-11-05 Chong Yidong <cyd@gnu.org>
2 9
3 * frames.texi (Initial Parameters): Doc fix (Bug#12144). 10 * frames.texi (Initial Parameters): Doc fix (Bug#12144).
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index 06a2ebfcaf8..5f10b450e84 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -502,6 +502,11 @@ Buffer-Local Variables
502* Default Value:: The default value is seen in buffers 502* Default Value:: The default value is seen in buffers
503 that don't have their own buffer-local values. 503 that don't have their own buffer-local values.
504 504
505Generalized Variables
506
507* Setting Generalized Variables:: The @code{setf} macro.
508* Adding Generalized Variables:: Defining new @code{setf} forms.
509
505Functions 510Functions
506 511
507* What Is a Function:: Lisp functions vs. primitives; terminology. 512* What Is a Function:: Lisp functions vs. primitives; terminology.
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index 88b7909126e..f9f69850ef8 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -1965,6 +1965,14 @@ and @samp{a[i] = x} stores an element using the same notation.
1965Just as certain forms like @code{a[i]} can be lvalues in C, there 1965Just as certain forms like @code{a[i]} can be lvalues in C, there
1966is a set of forms that can be generalized variables in Lisp. 1966is a set of forms that can be generalized variables in Lisp.
1967 1967
1968@menu
1969* Setting Generalized Variables:: The @code{setf} macro.
1970* Adding Generalized Variables:: Defining new @code{setf} forms.
1971@end menu
1972
1973@node Setting Generalized Variables
1974@subsection The @code{setf} Macro
1975
1968The @code{setf} macro is the most basic way to operate on generalized 1976The @code{setf} macro is the most basic way to operate on generalized
1969variables. The @code{setf} form is like @code{setq}, except that it 1977variables. The @code{setf} form is like @code{setq}, except that it
1970accepts arbitrary place forms on the left side rather than just 1978accepts arbitrary place forms on the left side rather than just
@@ -2049,3 +2057,65 @@ place can be used to insert or delete at any position in a list.
2049The @file{cl-lib} library defines various extensions for generalized 2057The @file{cl-lib} library defines various extensions for generalized
2050variables, including additional @code{setf} places. 2058variables, including additional @code{setf} places.
2051@xref{Generalized Variables,,, cl, Common Lisp Extensions}. 2059@xref{Generalized Variables,,, cl, Common Lisp Extensions}.
2060
2061
2062@node Adding Generalized Variables
2063@subsection Defining new @code{setf} forms
2064
2065This section describes how to define new forms that @code{setf} can
2066operate on.
2067
2068@defmac gv-define-simple-setter name setter &optional fix-return
2069This macro enables you to easily define @code{setf} methods for simple
2070cases. @var{name} is the name of a function, macro, or special form.
2071You can use this macro whenever @var{name} has a directly
2072corresponding @var{setter} function that updates it, e.g.,
2073@code{(gv-define-simple-setter car setcar)}.
2074
2075This macro translates a call of the form
2076
2077@example
2078(setf (@var{name} @var{args}@dots{}) @var{value})
2079@end example
2080
2081into
2082@example
2083(@var{setter} @var{args}@dots{} @var{value})
2084@end example
2085
2086@noindent
2087Such a @code{setf} call is documented to return @var{value}. This is
2088no problem with, e.g., @code{car} and @code{setcar}, because
2089@code{setcar} returns the value that it set. If your @var{setter}
2090function does not return @var{value}, use a non-@code{nil} value for
2091the @var{fix-return} argument of @code{gv-define-simple-setter}. This
2092wraps the @code{setf} expansion in @code{(prog1 @var{value} @dots{})}
2093so that it returns the correct result.
2094@end defmac
2095
2096
2097@defmac gv-define-setter name arglist &rest body
2098This macro allows for more complex @code{setf} expansions than the
2099previous form. You may need to use this form, for example, if there
2100is no simple setter function to call, or if there is one but it
2101requires different arguments to the place form.
2102
2103This macro expands the form
2104@code{(setf (@var{name} @var{args}@dots{}) @var{value})} by
2105first binding the @code{setf} argument forms
2106@code{(@var{value} @var{args}@dots{})} according to @var{arglist},
2107and then executing @var{body}. @var{body} should return a Lisp
2108form that does the assignment. Remember that it should return the
2109value that was set. An example of using this macro is:
2110
2111@example
2112(gv-define-setter caar (val x) `(setcar (car ,x) ,val))
2113@end example
2114@end defmac
2115
2116@c FIXME? Not sure what, if anything, to say about this.
2117@ignore
2118@defmac gv-define-expander name handler
2119This is the most general way to define a new @code{setf} expansion.
2120@end defmac
2121@end ignore
diff --git a/etc/NEWS b/etc/NEWS
index 4f8b56cb363..c9c68513a8b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -783,6 +783,8 @@ systems), or based on memory allocations.
783 783
784** CL-style generalized variables are now in core Elisp. 784** CL-style generalized variables are now in core Elisp.
785`setf' is autoloaded; `push' and `pop' accept generalized variables. 785`setf' is autoloaded; `push' and `pop' accept generalized variables.
786You can define your own generalized variables using `gv-define-simple-setter',
787`gv-define-setter', etc.
786 788
787+++ 789+++
788** `defun' also accepts a (declare DECLS) form, like `defmacro'. 790** `defun' also accepts a (declare DECLS) form, like `defmacro'.