Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* How to get value of parameter in macro
@ 2010-01-06 11:36 Cecil Westerhof
  2010-01-06 15:35 ` Ted Zlatanov
  0 siblings, 1 reply; 6+ messages in thread
From: Cecil Westerhof @ 2010-01-06 11:36 UTC (permalink / raw)
  To: info-gnus-english

I am trying my first stab at macro's. I want to define key bindings to a
jump to a group. I tried something like:
    (defmacro gnus-group-jump-bind (key-binding group-to-jump-to)
      (define-key gnus-group-mode-map key-binding
        (lambda ()
          (interactive)
          (gnus-group-jump-to-group group-to-jump-to))))

    (gnus-group-jump-bind "vjd" "nndraft:drafts")

The key binding is okay, but the lambda function not. This becomes:
    (lambda nil (interactive) (gnus-group-jump-to-group group-to-jump-to))

instead of:
    (lambda nil (interactive) (gnus-group-jump-to-group "nndraft:drafts"))

What do I need to do to get the value of group-to-jump-to instead of the
string?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get value of parameter in macro
  2010-01-06 11:36 How to get value of parameter in macro Cecil Westerhof
@ 2010-01-06 15:35 ` Ted Zlatanov
  2010-01-06 15:58   ` Cecil Westerhof
  2010-01-06 16:49   ` Cecil Westerhof
  0 siblings, 2 replies; 6+ messages in thread
From: Ted Zlatanov @ 2010-01-06 15:35 UTC (permalink / raw)
  To: info-gnus-english

On Wed, 06 Jan 2010 12:36:03 +0100 Cecil Westerhof <Cecil@decebal.nl> wrote: 

CW> I am trying my first stab at macro's. I want to define key bindings to a
CW> jump to a group. I tried something like:
CW>     (defmacro gnus-group-jump-bind (key-binding group-to-jump-to)
CW>       (define-key gnus-group-mode-map key-binding
CW>         (lambda ()
CW>           (interactive)
CW>           (gnus-group-jump-to-group group-to-jump-to))))

CW>     (gnus-group-jump-bind "vjd" "nndraft:drafts")

CW> The key binding is okay, but the lambda function not. This becomes:
CW>     (lambda nil (interactive) (gnus-group-jump-to-group group-to-jump-to))

CW> instead of:
CW>     (lambda nil (interactive) (gnus-group-jump-to-group "nndraft:drafts"))

CW> What do I need to do to get the value of group-to-jump-to instead of the
CW> string?

Read the manual section on macros again, and again, and again.  It
really takes a while.  You are trying to find the , interpolation
marker, e.g. ",group-to-jump-to" will become "nndraft:drafts" but again
you should read the manual very thoroughly.

Ted

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get value of parameter in macro
  2010-01-06 15:35 ` Ted Zlatanov
@ 2010-01-06 15:58   ` Cecil Westerhof
  2010-01-06 16:49   ` Cecil Westerhof
  1 sibling, 0 replies; 6+ messages in thread
From: Cecil Westerhof @ 2010-01-06 15:58 UTC (permalink / raw)
  To: info-gnus-english

Ted Zlatanov <tzz@lifelogs.com> writes:

> CW> The key binding is okay, but the lambda function not. This becomes:
> CW>     (lambda nil (interactive) (gnus-group-jump-to-group group-to-jump-to))
>
> CW> instead of:
> CW>     (lambda nil (interactive) (gnus-group-jump-to-group "nndraft:drafts"))
>
> CW> What do I need to do to get the value of group-to-jump-to instead of the
> CW> string?
>
> Read the manual section on macros again, and again, and again.  It
> really takes a while.  You are trying to find the , interpolation
> marker, e.g. ",group-to-jump-to" will become "nndraft:drafts" but again
> you should read the manual very thoroughly.

I have already tried that, but -until now- without avail. Lisp is
certainly a 'little' harder to learn as other languages. But when I
understand it correctly you have a very powerful tool when you grasp it.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get value of parameter in macro
  2010-01-06 15:35 ` Ted Zlatanov
  2010-01-06 15:58   ` Cecil Westerhof
@ 2010-01-06 16:49   ` Cecil Westerhof
  2010-01-06 17:17     ` Cecil Westerhof
  1 sibling, 1 reply; 6+ messages in thread
From: Cecil Westerhof @ 2010-01-06 16:49 UTC (permalink / raw)
  To: info-gnus-english

Ted Zlatanov <tzz@lifelogs.com> writes:

> CW> I am trying my first stab at macro's. I want to define key bindings to a
> CW> jump to a group. I tried something like:
> CW>     (defmacro gnus-group-jump-bind (key-binding group-to-jump-to)
> CW>       (define-key gnus-group-mode-map key-binding
> CW>         (lambda ()
> CW>           (interactive)
> CW>           (gnus-group-jump-to-group group-to-jump-to))))
>
> CW>     (gnus-group-jump-bind "vjd" "nndraft:drafts")
>
> CW> The key binding is okay, but the lambda function not. This becomes:
> CW>     (lambda nil (interactive) (gnus-group-jump-to-group group-to-jump-to))
>
> CW> instead of:
> CW>     (lambda nil (interactive) (gnus-group-jump-to-group "nndraft:drafts"))
>
> CW> What do I need to do to get the value of group-to-jump-to instead of the
> CW> string?
>
> Read the manual section on macros again, and again, and again.  It
> really takes a while.  You are trying to find the , interpolation
> marker, e.g. ",group-to-jump-to" will become "nndraft:drafts" but again
> you should read the manual very thoroughly.

Found it:
    (defmacro gnus-group-jump-bind (key-binding group-to-jump-to)
      `(define-key gnus-group-mode-map ,key-binding
        (lambda ()
          (interactive)
          (gnus-group-jump-to-group ,group-to-jump-to))))

When you know it, it is not difficult.

But I am still not out of the woods.
Instead of using:
    (gnus-group-jump-bind "vjd" "nndraft:drafts")

I want to do something like:
    (gnus-group-jump-bind this-key this-group)

But that does not work because the macro then does not receive a string,
but a symbol. I tried to work with symbol-value, but that did not work.
If you -or someone else- has another pointer ...

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get value of parameter in macro
  2010-01-06 16:49   ` Cecil Westerhof
@ 2010-01-06 17:17     ` Cecil Westerhof
  2010-01-06 20:10       ` Cecil Westerhof
  0 siblings, 1 reply; 6+ messages in thread
From: Cecil Westerhof @ 2010-01-06 17:17 UTC (permalink / raw)
  To: info-gnus-english

Cecil Westerhof <Cecil@decebal.nl> writes:

> Found it:
>     (defmacro gnus-group-jump-bind (key-binding group-to-jump-to)
>       `(define-key gnus-group-mode-map ,key-binding
>         (lambda ()
>           (interactive)
>           (gnus-group-jump-to-group ,group-to-jump-to))))
>
> When you know it, it is not difficult.
>
> But I am still not out of the woods.
> Instead of using:
>     (gnus-group-jump-bind "vjd" "nndraft:drafts")
>
> I want to do something like:
>     (gnus-group-jump-bind this-key this-group)
>
> But that does not work because the macro then does not receive a string,
> but a symbol. I tried to work with symbol-value, but that did not work.
> If you -or someone else- has another pointer ...

And solved this problem also:
    (setq gnus-group-jump-list
          (list
           '("d" "nndraft:drafts")
           ))

    (defmacro gnus-group-jump-bind (key-binding group-to-jump-to)
      `(define-key gnus-group-mode-map ,(symbol-value key-binding)
        (lambda ()
          (interactive)
          (gnus-group-jump-to-group ,(symbol-value group-to-jump-to)))))

    (defun gnus-group-do-jump-bind ()
       (dolist (this-jump gnus-group-jump-list)
         (let ((this-group (second this-jump))
               (this-key   (concat "vj" (first this-jump))))
         (gnus-group-jump-bind this-key this-group))))

    (gnus-group-do-jump-bind)

And this does what I want. A problem could be that:
     (gnus-group-jump-bind "vjd" "nndraft:drafts")

does not work anymore, but just always use variables solves that
'problem'.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to get value of parameter in macro
  2010-01-06 17:17     ` Cecil Westerhof
@ 2010-01-06 20:10       ` Cecil Westerhof
  0 siblings, 0 replies; 6+ messages in thread
From: Cecil Westerhof @ 2010-01-06 20:10 UTC (permalink / raw)
  To: info-gnus-english

Cecil Westerhof <Cecil@decebal.nl> writes:

> And solved this problem also:
>     (setq gnus-group-jump-list
>           (list
>            '("d" "nndraft:drafts")
>            ))
>
>     (defmacro gnus-group-jump-bind (key-binding group-to-jump-to)
>       `(define-key gnus-group-mode-map ,(symbol-value key-binding)
>         (lambda ()
>           (interactive)
>           (gnus-group-jump-to-group ,(symbol-value group-to-jump-to)))))
>
>     (defun gnus-group-do-jump-bind ()
>        (dolist (this-jump gnus-group-jump-list)
>          (let ((this-group (second this-jump))
>                (this-key   (concat "vj" (first this-jump))))
>          (gnus-group-jump-bind this-key this-group))))

Pascal Bourguignon told me that it was not necessary to use a macro. So
I rewrote it without using a macro:
    (defun gnus-group-jump-bind ()
      "Define the key bindings for jumping to groups;"
      (dolist (this-jump gnus-group-jump-list)
        (let ((this-description (second this-jump))
              (this-group       (third  this-jump))
              (this-key         (concat "vj" (first this-jump))))
          (define-key gnus-group-mode-map this-key
            `(lambda ()
              ,this-description
              (interactive)
              (gnus-group-jump-to-group ,this-group))))))

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-01-06 20:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-06 11:36 How to get value of parameter in macro Cecil Westerhof
2010-01-06 15:35 ` Ted Zlatanov
2010-01-06 15:58   ` Cecil Westerhof
2010-01-06 16:49   ` Cecil Westerhof
2010-01-06 17:17     ` Cecil Westerhof
2010-01-06 20:10       ` Cecil Westerhof

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).