diff options
| author | Lars Ingebrigtsen | 2019-08-15 23:57:57 -0700 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-08-15 23:57:57 -0700 |
| commit | d1d738c8264b3e756259e3ba2112ff96b8ecf829 (patch) | |
| tree | 1eca2b3b7bad3c71c03a91d97f9fddd1f39b8f54 /doc | |
| parent | 19c1e4c81c7442dea48253e5961b6e54d78b6f0a (diff) | |
| download | emacs-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.texi | 41 |
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 | 2537 | For more control over the expansion, the @code{gv-define-expander} |
| 2538 | @c FIXME? Not sure what or how much to say about these. | 2538 | macro can be used. For instance, a settable @code{substring} could be |
| 2539 | @c See cl.texi for an example of using gv-letplace. | 2539 | implemented this way: |
| 2540 | For 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 | ||
| 2541 | The macro @code{gv-letplace} can be useful in defining macros that | 2554 | The macro @code{gv-letplace} can be useful in defining macros that |
| 2542 | perform similarly to @code{setf}; for example, the @code{incf} macro | 2555 | perform similarly to @code{setf}; for example, the @code{incf} macro |
| 2543 | of Common Lisp. Consult the source file @file{gv.el} for more details. | 2556 | of 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 | ||
| 2566 | value of @var{place}. @var{setter} will be bound to a function that | ||
| 2567 | takes an expression @var{v} and returns a new expression that sets | ||
| 2568 | @var{place} to @var{v}. @var{body} should return a Emacs Lisp | ||
| 2569 | expression manipulating @var{place} via @var{getter} and @var{setter}. | ||
| 2570 | @end defmac | ||
| 2571 | |||
| 2572 | Consult 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 |