From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: torys.anderson@gmail.com (Tory S. Anderson) Newsgroups: gmane.emacs.help Subject: Re: elisp newbie: simplifying from cl structures? Date: Sat, 07 Feb 2015 22:33:38 -0500 Message-ID: <8761bdyt4d.fsf@gmail.com> References: <87mw4pnsr6.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1423366440 25977 80.91.229.3 (8 Feb 2015 03:34:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 8 Feb 2015 03:34:00 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Pascal J. Bourguignon" , John Mastro Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Feb 08 04:33:59 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YKIdD-0005Hq-5Z for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Feb 2015 04:33:59 +0100 Original-Received: from localhost ([::1]:55429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKIdC-0004xn-3j for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Feb 2015 22:33:58 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKIcz-0004xX-Rn for help-gnu-emacs@gnu.org; Sat, 07 Feb 2015 22:33:46 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKIcx-0005LG-U2 for help-gnu-emacs@gnu.org; Sat, 07 Feb 2015 22:33:45 -0500 Original-Received: from mail-yk0-x233.google.com ([2607:f8b0:4002:c07::233]:39219) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKIcx-0005LC-Ph for help-gnu-emacs@gnu.org; Sat, 07 Feb 2015 22:33:43 -0500 Original-Received: by mail-yk0-f179.google.com with SMTP id 142so8883149ykq.10 for ; Sat, 07 Feb 2015 19:33:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; bh=X30rfpwrLADfl/Z/MBIuVLM6EgXNsO5inBggS0L87Lg=; b=XvJHUdVmLKLKF32wQCmw/DHe8C0qciIaZ9OdVxH48QqC5GTW7bmsl+2gcKv0RbtJ2k nTsjIu0I7WbKpMoxgXl/bjyBXCnRI9LENDCWLnQM2eZMKbiFHlJ8B/EPUpWGBdl0mlYJ /b0IhB+lYclviwbgJsD9MMgAN783dWa/5RHyFE0dHFcmMMfW/LTZrRRSBV7X60lf8z6C zF4Dh+Gj7MQtnxT8UGWN0mgMGlbKjKVAqbGfl9GRcfrwcyTQtLAWeR6jnyJxuP3AqnDn 0DmuIQuYNuFDLQxh18VHfZNzZpfXZLVqxIZfaNGR1wpTVBUSfH1inBpin+WHpRoFLX3m QiFg== X-Received: by 10.236.5.202 with SMTP id 50mr3624224yhl.178.1423366423198; Sat, 07 Feb 2015 19:33:43 -0800 (PST) Original-Received: from localhost.localdomain ([2601:0:a602:24aa:ee55:f9ff:feb5:5589]) by mx.google.com with ESMTPSA id r100sm4747557yhp.31.2015.02.07.19.33.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Feb 2015 19:33:42 -0800 (PST) In-Reply-To: <87mw4pnsr6.fsf@kuiper.lan.informatimago.com> (Pascal J. Bourguignon's message of "Sun, 08 Feb 2015 01:37:01 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4002:c07::233 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:102574 Archived-At: Thanks for helping me straighten the code out and gain better understanding cl-tools and structure; it loads and mostly works. Thanks! --8<---------------cut here---------------start------------->8--- (defun change-smtp () "Change the SMTP server according to the current from line." (save-excursion (cl-loop with from = (save-restriction (message-narrow-to-headers) (message-fetch-field "from")) for (address server port) in smtp-accounts do (if (string-match address from) (return (funcall 'set-smtp server port address)) (message "Failed to match %s with %s" address from)) finally (error "Cannot infer SMTP information.")))) (add-hook 'message-send-mail-hook 'change-smtp) --8<---------------cut here---------------end--------------->8--- "Pascal J. Bourguignon" writes: > John Mastro writes: > >>> (defun change-smtp () >>> "Change the SMTP server according to the current from line." >>> (save-excursion >>> (cl-loop with from = (save-restriction >>> (message-narrow-to-headers) >>> (message-fetch-field "from")) >>> for (address server port) in smtp-accounts >>> if (string-match address from) >>> return (funcall 'set-smtp server port address)) >>> (error "Cannot infer SMTP information."))) >> >> Second try. The return won't escape the `error' in the above. >> >> (defun change-smtp () >> "Change the SMTP server according to the current from line." >> (save-excursion >> (cl-loop with from = (save-restriction >> (message-narrow-to-headers) >> (message-fetch-field "from")) >> for (address server port) in smtp-accounts >> if (string-match address from) >> return (funcall 'set-smtp server port address) >> finally (error "Cannot infer SMTP information.")))) > > do (if (string-match address from) > (return (funcall 'set-smtp server port address))) > finally (error "Cannot infer SMTP information.") > > will.