[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Eval keymapp in a macros
From: |
Michael Heerdegen |
Subject: |
Re: Eval keymapp in a macros |
Date: |
Mon, 02 Aug 2021 22:33:04 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Arthur Miller <arthur.miller@live.com> writes:
> #+begin_src emacs-lisp
>
> (defmacro with-key-map (mapname &rest body)
> `(let ((map ,mapname))
> (dolist (def '(,@body))
> (define-key map
> (if (vectorp (car def)) (car def)
> (read-kbd-macro (car def)))
> (if (or (listp (cdr def))
> (functionp (cdr def)))
> (cdr def)
> (if (eval `(keymapp ,(cdr def)))
> (eval (cdr def))))))))
>
> #+end_src
Unfortunately you didn't show how you use it. What's the purpose of
your macro? Anyway, `macroexpand' or `macroexpand-1' your call to see
what happens.
My hypothesis is that (cdr def) evals to a symbol (that is bound to a
keymap) - like `global-map', and not a keymap. So the expansion of a
macro call would actually test e.g.
(keymapp 'global-map) --> nil
Note that nothing in BODY is ever evaluated (it's behind a quote).
My tip when writing a macro (do you really need one btw?): Write an
example call and then the desired expansion down. Only after that write
down the macro implementation that offers exactly that expansion. You
can later do that in your head, but if you skip that step you get all
the surprises and pitfalls that macros are known for.
Michael.
- Eval keymapp in a macros, Arthur Miller, 2021/08/02
- Re: Eval keymapp in a macros,
Michael Heerdegen <=
- RE: [External] : Re: Eval keymapp in a macros, Drew Adams, 2021/08/02
- Re: Eval keymapp in a macros, Arthur Miller, 2021/08/03
- Re: Eval keymapp in a macros, Michael Heerdegen, 2021/08/03
- Re: Eval keymapp in a macros, Arthur Miller, 2021/08/04
- Re: Eval keymapp in a macros, Michael Heerdegen, 2021/08/04
- Re: Eval keymapp in a macros, Arthur Miller, 2021/08/05
- Re: Eval keymapp in a macros, Michael Heerdegen, 2021/08/05
- Re: Eval keymapp in a macros, Arthur Miller, 2021/08/12
- Re: Eval keymapp in a macros, Yuri Khan, 2021/08/04
- Re: Eval keymapp in a macros, Arthur Miller, 2021/08/04