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

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

Re: elisp newbie: simplifying from cl structures?


From: Tory S. Anderson
Subject: Re: elisp newbie: simplifying from cl structures?
Date: Sat, 07 Feb 2015 22:33:38 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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" <pjb@informatimago.com> writes:

> John Mastro <john.b.mastro@gmail.com> 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.



reply via email to

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