help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need help with macros


From: Pascal J. Bourguignon
Subject: Re: Need help with macros
Date: Wed, 06 Jan 2010 21:29:52 +0100
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux)

Cecil Westerhof <address@hidden> writes:

> Cecil Westerhof <address@hidden> writes:
>
>>> gnus-group-jump-bind has no need to be a macro.  As a macro it is
>>> wrong.  Use defun!
>>
>> I could not get the defun working, that is why I thought it had to be
>> done with a macro. The macro first also did not work. The macro works
>> now. I'll rewrite the macro to a defun.
>
> And this is without 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))))))

Good.

Two things.  

1- I'd like it better if gnus-group-jump-list was a parameter of the
   function rather than a global variable.


2- You could use destructuring-bind:

    (defun gnus-group-jump-bind (jump-list)
      "Define the key bindings for jumping to groups;"
      (dolist (this-jump jump-list)
        (destructuring-bind (this-key this-description this-group) this-jump
          (let ((binding (concat "vj" this-key)))
            (define-key gnus-group-mode-map binding 
               `(lambda ()
                   ,this-description
                   (interactive)
                   (gnus-group-jump-to-group ,this-group)))))))

    (gnus-group-jump-bind gnus-group-jump-list)


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]