all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@elta.co.il>
Subject: Re: Elisp help needed
Date: 27 Nov 2003 08:29:08 +0200	[thread overview]
Message-ID: <uhe0qjpe3.fsf@elta.co.il> (raw)
In-Reply-To: <871xru20u9.fsf@inspiron.meinnetz.de> (message from Tassilo Horn on Wed, 26 Nov 2003 23:59:10 +0100)

> From: Tassilo Horn <heimdall@uni-koblenz.de>
> 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 "heimdall@uni-koblenz.de")
> 	(setq smtpmail-smtp-server "mailhost.uni-koblenz.de"))
>        ((string-match from "tassilo.horn@freenet.de")
> 	(setq smtpmail-smtp-server "mx.freenet.de"))
>        ((string-match from "tassilo.horn@gmx.de")
> 	(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	other threads:[~2003-11-27  6:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-26 22:59 Elisp help needed Tassilo Horn
2003-11-27  6:29 ` Eli Zaretskii [this message]
     [not found] ` <mailman.693.1069918173.399.help-gnu-emacs@gnu.org>
2003-11-27  8:48   ` Tassilo Horn
  -- strict thread matches above, loose matches on Subject: below --
2006-03-01 16:58 elisp " Robert D. Crawford
2006-03-01 21:37 ` RD
2006-03-02 11:36   ` Robert D. Crawford
2006-03-04 12:26     ` Tim Cross
2006-03-04 13:57       ` Robert D. Crawford
2006-03-02 12:50 ` Katsumi Yamaoka
2006-03-02 13:34   ` Robert D. Crawford

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

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

  git send-email \
    --in-reply-to=uhe0qjpe3.fsf@elta.co.il \
    --to=eliz@elta.co.il \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.