[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to put this in a macro
From: |
José A . Romero L . |
Subject: |
Re: How to put this in a macro |
Date: |
Tue, 04 May 2010 15:44:59 -0000 |
User-agent: |
G2/1.0 |
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?
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.
Cheers,
--
José A. Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)
- How to put this in a macro, Cecil Westerhof, 2010/05/04
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro, Barry Margolin, 2010/05/04
- Re: How to put this in a macro, Cecil Westerhof, 2010/05/04
- Re: How to put this in a macro,
José A . Romero L . <=
- Re: How to put this in a macro, Cecil Westerhof, 2010/05/04
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro, Cecil Westerhof, 2010/05/04
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro, Barry Margolin, 2010/05/04
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro, Barry Margolin, 2010/05/04
- Re: How to put this in a macro, Cecil Westerhof, 2010/05/04
- Re: How to put this in a macro, José A . Romero L ., 2010/05/04
- Re: How to put this in a macro, Barry Margolin, 2010/05/04