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

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

Re: Elisp help needed


From: Eli Zaretskii
Subject: Re: Elisp help needed
Date: 27 Nov 2003 08:29:08 +0200

> From: Tassilo Horn <address@hidden>
> Newsgroups: gnu.emacs.help
> Date: Wed, 26 Nov 2003 23:59:10 +0100
> 
> (defun fs-change-smtp ()
>   "Change the SMTP server according to the current from line."
>   (save-excursion
>     (let ((from
>          (save-restriction
>            (message-narrow-to-headers)
>            (message-fetch-field "from"))))
>       (cond
>        ((string-match from "address@hidden")
>       (setq smtpmail-smtp-server "mailhost.uni-koblenz.de"))
>        ((string-match from "address@hidden")
>       (setq smtpmail-smtp-server "mx.freenet.de"))
>        ((string-match from "address@hidden")
>       (setq smtpmail-smtp-server "mail.gmx.de"))
>        (t
>       (setq smtpmail-smtp-server "mailhost.uni-koblenz.de"))))))
> (add-hook 'message-send-hook 'fs-change-smtp)
> 
> But this doesn't work correctly. Always the default of the cond is
> taken, even the From-line is another mail address (gmx or freenet). So I
> think that the variable from has the wrong content.

I think you reversed the arguments to string-match (see the
function's doc string).

Also, I'm not sure message-fetch-field does what you think it does in
the buffer where you compose a message being sent (as opposed to the
buffer where you read mail sent by others to you).

Anyway, the proper way to solve such problems is to debug them.  With
the cursor inside the function, type "M-x edebug-defun RET", then do
whatever you do to compose a message, and you will see that when
fs-change-smtp is called, Edebug, the Emacs Lisp debugger kicks in
and lets you step through the code and see the results of each
evaluation.  That will show you what's wrong.

The chapter "Edebug" in the ELisp manual will tell you how to use
Edebug.

Good luck.





reply via email to

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