From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: How to put this in a macro
Date: Sat, 17 Apr 2010 11:14:38 -0400 [thread overview]
Message-ID: <barmar-10C6E4.11143817042010@62-183-169-81.bb.dnainternet.fi> (raw)
In-Reply-To: bf0039f9-f7eb-497d-bb74-88d3bb9c5077@u34g2000yqu.googlegroups.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1689 bytes --]
In article
<bf0039f9-f7eb-497d-bb74-88d3bb9c5077@u34g2000yqu.googlegroups.com>,
José A. Romero L. <escherdragon@gmail.com> wrote:
> On 17 Kwi, 08:38, Cecil Westerhof <Ce...@decebal.nl> wrote:
> > Barry Margolin <bar...@alum.mit.edu> writes:
> > > (defmacro canonicalize-start-end (start-var end-var)
> > > `(if (equal ,start-var ,end-var)
> > > (setq ,start-var (point-min)
> > > ,end-var (point-max))
> > > (setq ,start-var (or ,start-var (point-min))
> > > ,end-var (or ,end-var (point-max))))
> >
> > This gives an error:
> > Debugger entered--Lisp error: (void-variable start-var)
> > (list (quote equal) start-var end-var)
> (...)
>
> Makes sense. In general writing things like `(setq ,foo bar) is (if
> possible at all) asking for trouble -- what would happen when foo is
> nil, or 5?
My macro requires that the parameters be variables, not expressions.
>
> Maybe you could do something like this:
>
> (defmacro cw/set-bounds (start-sym end-sym)
> `(if (equal (symbol-value ,start-sym) (symbol-value ,end-sym))
> (progn
> (set ,start-sym (point-min))
> (set ,end-sym (point-max)))
> (progn
> (set ,start-sym (or start (point-min)))
> (set ,end-sym (or end (point-max))))))
>
> and use it as:
>
> (cw/set-bounds 'start 'end)
>
> i.e. passing the symbols of the variables you want to set.
If you call it like that, it can be a function, not a macro.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
next prev parent reply other threads:[~2010-04-17 15:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-16 21:13 How to put this in a macro Cecil Westerhof
2010-04-16 23:28 ` José A. Romero L.
2010-04-17 3:08 ` Barry Margolin
2010-04-17 6:38 ` Cecil Westerhof
2010-04-17 10:30 ` José A. Romero L.
2010-04-17 11:07 ` Cecil Westerhof
2010-04-17 11:40 ` Cecil Westerhof
2010-04-17 15:15 ` José A. Romero L.
2010-04-17 16:49 ` Barry Margolin
2010-04-17 16:57 ` José A. Romero L.
2010-04-17 21:41 ` Barry Margolin
2010-04-17 19:38 ` Cecil Westerhof
2010-04-17 23:58 ` José A. Romero L.
2010-04-17 12:13 ` José A. Romero L.
2010-04-17 15:14 ` Barry Margolin [this message]
2010-04-17 16:49 ` José A. Romero L.
2010-04-17 15:12 ` Barry Margolin
2010-04-18 7:50 ` Pascal J. Bourguignon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=barmar-10C6E4.11143817042010@62-183-169-81.bb.dnainternet.fi \
--to=barmar@alum.mit.edu \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.