unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Cecil Westerhof <Cecil@decebal.nl>
To: help-gnu-emacs@gnu.org
Subject: Re: Break from a dolist
Date: Sun, 09 Sep 2012 14:49:45 +0200	[thread overview]
Message-ID: <87k3w3wec6.fsf@Compaq.site> (raw)
In-Reply-To: mailman.8449.1347182656.855.help-gnu-emacs@gnu.org

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


  parent reply	other threads:[~2012-09-09 12:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-09  8:56 Break from a dolist Cecil Westerhof
2012-09-09  9:25 ` Jambunathan K
     [not found] ` <mailman.8449.1347182656.855.help-gnu-emacs@gnu.org>
2012-09-09 12:49   ` Cecil Westerhof [this message]
2012-09-09 13:52     ` Le Wang
2012-09-09 14:13       ` Jambunathan K
     [not found]       ` <mailman.8455.1347199946.855.help-gnu-emacs@gnu.org>
2012-09-09 19:47         ` Cecil Westerhof

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k3w3wec6.fsf@Compaq.site \
    --to=cecil@decebal.nl \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).