Bill Wohler | 30 Apr 09:12

Re: sortm arguments

Henrik Frisk <henrik.frisk <at> mhm.lu.se> wrote:

> > > (defun my-mh-sort-folder (arg)
> > >   "Sort current folder by subject or sender."
> > >   (interactive "p")
> > >   (if (= 1 arg)
> > >       (setq mh-sortm-args '(-textfield subject -limit 0)))
> > >   (if (= 2 arg)
> > >       (setq mh-sortm-args '(-textfield from -limit 0)))
> > >   (mh-sort-folder 4))
> > 
> > Generally, local variables are preferred in this kind of usage to avoid
> > unintentional side-effects:
> > 
> >     (let (mh-sortm-args (cond ((= 1 1)
> >                                '(-textfield subject -limit 0))
> >                               ((= 2 2)
> >                                '(-textfield from -limit 0))))
> >       (mh-sort-folder 4))
> > 
> I see your point, thanks! Perhaps obvious, I'm just starting to get
> aquainted with emacs Lisp... I figured the best way to learn is to get
> my hands dirty with it.

That's right! And read code.

> I realize this is getting a little off topic but running the function
> now results in the error:

It's on topic as far as I can tell :-).

> `let' bindings can have only one value-form: cond, ((= 1 arg) (quote
> (-textfield subject -limit 0))), ((= 2 arg) (quote (-textfield from
> -limit 0)))

I just typed in the code so typos were expected :-). Learning Emacs Lisp
involves using C-h f (as in `C-h f let RET' which *might* have exposed a
little light), and the Emacs Lisp manual `C-h i g (elisp) RET' which
with its examples would have finished the job.

I missed a couple of parens (shown with the non-functional characters []
for emphasis below).

     (let [(mh-sortm-args (cond ((= 1 1)
                                '(-textfield subject -limit 0))
                               ((= 2 2)
                                '(-textfield from -limit 0))))]
       (mh-sort-folder 4))

--

-- 
Bill Wohler <wohler <at> newt.com>  http://www.newt.com/wohler/  GnuPG ID:610BD9AD

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

Gmane