[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: elisp newbie: simplifying from cl structures?
From: |
John Mastro |
Subject: |
Re: elisp newbie: simplifying from cl structures? |
Date: |
Sat, 7 Feb 2015 15:16:21 -0800 |
Tory S. Anderson <torys.anderson@gmail.com> wrote:
> (defun change-smtp ()
> "Change the SMTP server according to the current from line."
> (save-excursion
> (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 (apply 'set-smtp server port
> address)))
> (error "Cannot infer SMTP information.")))
Try this (untested, sorry):
(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.")))
I think there were three issues:
1. return is a cl-loop keyword, so it shouldn't be in parenthesis
as if it were a function. That's the error you were getting.
2. The use of apply needed to change to funcall
3. And then it made sense to change from `for (address server . port)'
to `for (address server port)'. The difference (given the shape of
smtp-accounts) is that, in the former case, port will be a list
containing a single integer, whereas in the latter case it will be an
integer.
I also changed `loop' to `cl-loop', as is now preferred.
--
john