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

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

Re: Break from a dolist


From: Cecil Westerhof
Subject: Re: Break from a dolist
Date: Sun, 09 Sep 2012 14:49:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Op zondag 9 sep 2012 11:25 CEST schreef Jambunathan K.:

>> I have the following code to fetch the email address belonging to a
>> mailing list. I use it to automatically fill the to address when
>> posting to a newsgroup.
>>
>> (defun dcbl-gnus-get-mailing-list-address ()
>> "Get gnus-newsgroup-name mailing list address (if it has one);"
>> (let ((to-address nil))
>> (when gnus-newsgroup-name
>> (dolist (item dcbl-gnus-mailing-lists)
>> (when (string-match (car item) gnus-newsgroup-name)
>> (setq to-address (cdr item)))))
>> to-address))
>>
>> But when the address is found, it would be better to leave the loop.
>> Is this possible?
>
>
> (info "(elisp) Examples of Catch")

Thanks. That makes for better code. I now have the following code,
that I am going to call from dcbl-gnus-get-mailing-list-address. Much
more clear code and I have now a generic function that I can call from
other places also.

    (defun dcbl-get-tuple-value (tuple index)
      "Get value from tuple indexed by index (if it exist);"
        (when index
          (catch 'loop
            (dolist (item tuple)
              (when (string-match (car item) index)
                  (throw 'loop (cdr item)))))))

The proof is in:
    (dcbl-get-tuple-value dcbl-gnus-mailing-lists 
"nnimap+gmail:INBOX\\.Info\\.bbdb")
and that does what it should.

There is one problem. First my 'tuple' was like:

    (setq dcbl-gnus-mailing-lists '(
                                    (":INBOX\\.Info\\.bbdb$"          . 
"bbdb-info@lists.sourceforge.net")
                                    .
                                    .
                                    .
                                    (":bedrijf/organisatie/org-mode$" . 
"emacs-orgmode@gnu.org")
                                    ))

But now it is like:

    (setq dcbl-gnus-mailing-lists '(
                                    (":INBOX\\\\.Info\\\\.bbdb$"      . 
"bbdb-info@lists.sourceforge.net")
                                    .
                                    .
                                    .
                                    (":bedrijf/organisatie/org-mode$" . 
"emacs-orgmode@gnu.org")
                                    ))

The backslashes for escaping the . have gone from two to four. Why is this?

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


reply via email to

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