aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-08-15 23:57:57 -0700
committerLars Ingebrigtsen2019-08-15 23:57:57 -0700
commitd1d738c8264b3e756259e3ba2112ff96b8ecf829 (patch)
tree1eca2b3b7bad3c71c03a91d97f9fddd1f39b8f54 /doc
parent19c1e4c81c7442dea48253e5961b6e54d78b6f0a (diff)
downloademacs-d1d738c8264b3e756259e3ba2112ff96b8ecf829.tar.gz
emacs-d1d738c8264b3e756259e3ba2112ff96b8ecf829.zip
Add some examples in "Adding Generalized Variables"
* doc/lispref/variables.texi (Adding Generalized Variables): Add examples for `gv-define-expander' and `gv-letplace' (bug#13343).
Diffstat (limited to 'doc')
-rw-r--r--doc/lispref/variables.texi41
1 files changed, 35 insertions, 6 deletions
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index 6e6448ec1e9..d62a5aa3af2 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -2533,14 +2533,43 @@ set. An example of using this macro is:
2533@end example 2533@end example
2534@end defmac 2534@end defmac
2535 2535
2536@findex gv-define-expander 2536@defmac gv-define-expander name handler
2537@findex gv-letplace 2537For more control over the expansion, the @code{gv-define-expander}
2538@c FIXME? Not sure what or how much to say about these. 2538macro can be used. For instance, a settable @code{substring} could be
2539@c See cl.texi for an example of using gv-letplace. 2539implemented this way:
2540For more control over the expansion, see the macro @code{gv-define-expander}. 2540
2541@example
2542(gv-define-expander substring
2543 (lambda (do place from &optional to)
2544 (gv-letplace (getter setter) place
2545 (macroexp-let2* nil ((start from) (end to))
2546 (funcall do `(substring ,getter ,start ,end)
2547 (lambda (v)
2548 (funcall setter `(cl--set-substring
2549 ,getter ,start ,end ,v))))))))
2550@end example
2551@end defmac
2552
2553@defmac gv-letplace (getter setter) place &rest body
2541The macro @code{gv-letplace} can be useful in defining macros that 2554The macro @code{gv-letplace} can be useful in defining macros that
2542perform similarly to @code{setf}; for example, the @code{incf} macro 2555perform similarly to @code{setf}; for example, the @code{incf} macro
2543of Common Lisp. Consult the source file @file{gv.el} for more details. 2556of Common Lisp could be implemented this way:
2557
2558@example
2559(defmacro incf (place &optional n)
2560 (gv-letplace (getter setter) place
2561 (macroexp-let2 nil v (or n 1)
2562 (funcall setter `(+ ,v ,getter)))))
2563@end example
2564
2565@var{getter} will be bound to a copyable expression that returns the
2566value of @var{place}. @var{setter} will be bound to a function that
2567takes an expression @var{v} and returns a new expression that sets
2568@var{place} to @var{v}. @var{body} should return a Emacs Lisp
2569expression manipulating @var{place} via @var{getter} and @var{setter}.
2570@end defmac
2571
2572Consult the source file @file{gv.el} for more details.
2544 2573
2545@cindex CL note---no @code{setf} functions 2574@cindex CL note---no @code{setf} functions
2546@quotation 2575@quotation