unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Elisp help needed
@ 2003-11-26 22:59 Tassilo Horn
  2003-11-27  6:29 ` Eli Zaretskii
       [not found] ` <mailman.693.1069918173.399.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Tassilo Horn @ 2003-11-26 22:59 UTC (permalink / raw)


Hi,

I need some help with Elisp. I want to configure Gnus to my needs and
therefore wrote an Elisp function which should fetch the From-line of
mails I wanna send. With the From-line it should decide which
smtp-server the mail should be send through.
My code is:

(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.

Does anybody find the bug?
Or does anyone have another solution for my problem?

Much thanks in advance,
Tassilo

-- 
"I dunno - the guy who wrote the mouse driver in Windows systems was a
 genius. Ever noticed that the mouse can still work when the whole OS
 has crashed in a screaming heap?" - John Wiltshire

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Elisp help needed
  2003-11-26 22:59 Elisp " Tassilo Horn
@ 2003-11-27  6:29 ` Eli Zaretskii
       [not found] ` <mailman.693.1069918173.399.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2003-11-27  6:29 UTC (permalink / raw)


> 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.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Elisp help needed
       [not found] ` <mailman.693.1069918173.399.help-gnu-emacs@gnu.org>
@ 2003-11-27  8:48   ` Tassilo Horn
  0 siblings, 0 replies; 11+ messages in thread
From: Tassilo Horn @ 2003-11-27  8:48 UTC (permalink / raw)


Eli Zaretskii <eliz@elta.co.il> writes:

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

Ok, I'll try this first.

> 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.

Ah, great to know. Thank you. 

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

I'll read it.

> Good luck.

Thanks, you helped me a lot.

Regards,
Tassilo

-- 
"Excessive login or logout messages are a sure sign of senility."

^ permalink raw reply	[flat|nested] 11+ messages in thread

* elisp help needed
@ 2006-03-01 16:58 Robert D. Crawford
  2006-03-01 21:37 ` RD
  2006-03-02 12:50 ` Katsumi Yamaoka
  0 siblings, 2 replies; 11+ messages in thread
From: Robert D. Crawford @ 2006-03-01 16:58 UTC (permalink / raw)


I have the following lines in my .emacs file:

(remove-hook 'w3m-after-cursor-move-hook
     #'w3m-print-this-url)

and for some reason, to get it to eval I have to do it by hand every
time I restart emacs.  I *think* this might be the only code that is not
being evaled, but I do not know any way to be certain.  I know that
there are things below this line that are being correctly evaled.  All
the code in the customize section seems to be ok, and I have a function
that byte-compiles .el files when they are saved that works.

Is there some way to know what is being evaled?

Thanks,

rdc

-- 
<========================================================================>
Robert D. Crawford                                      rdc1x@comcast.net

Q:	How many IBM 370's does it take to execute a job?
A:	Four, three to hold it down, and one to rip its head off.
<========================================================================>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: elisp help needed
  2006-03-01 16:58 elisp help needed Robert D. Crawford
@ 2006-03-01 21:37 ` RD
  2006-03-02 11:36   ` Robert D. Crawford
  2006-03-02 12:50 ` Katsumi Yamaoka
  1 sibling, 1 reply; 11+ messages in thread
From: RD @ 2006-03-01 21:37 UTC (permalink / raw)


Robert D. Crawford wrote:
> I have the following lines in my .emacs file:
> 
> (remove-hook 'w3m-after-cursor-move-hook
>      #'w3m-print-this-url)
> 
> and for some reason, to get it to eval I have to do it by hand every
> time I restart emacs.  I *think* this might be the only code that is not
> being evaled, but I do not know any way to be certain.  I know that
> there are things below this line that are being correctly evaled.  All
> the code in the customize section seems to be ok, and I have a function
> that byte-compiles .el files when they are saved that works.
> 
> Is there some way to know what is being evaled?
> 
> Thanks,
> 
> rdc
> 

I use the old "print" method.  I salt my .emacs file with (message 
"blah") commands to report progress.

Is there a command after the remove-hook that puts the hook back?

Bob

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: elisp help needed
  2006-03-01 21:37 ` RD
@ 2006-03-02 11:36   ` Robert D. Crawford
  2006-03-02 13:28     ` elisp help needed [solved] Robert D. Crawford
  2006-03-04 12:26     ` elisp help needed Tim Cross
  0 siblings, 2 replies; 11+ messages in thread
From: Robert D. Crawford @ 2006-03-02 11:36 UTC (permalink / raw)


RD <rjjd@localnet.com> writes:

> Robert D. Crawford wrote:
>> I have the following lines in my .emacs file: 
>
> (remove-hook 'w3m-after-cursor-move-hook #'w3m-print-this-url) 
>
>and for some
>> reason, to get it to eval I have to do it by hand every time I
>> restart emacs.  I *think* this might be the only code that is not
>> being evaled, but I do not know any way to be certain.  I know that
>> there are things below this line that are being correctly evaled.
>> All the code in the customize section seems to be ok, and I have a
>> function that byte-compiles .el files when they are saved that works.
>> Is there some way to know what is being evaled?  Thanks, rdc
>>
>
> I use the old "print" method.  I salt my .emacs file with (message
> "blah") commands to report progress.

Yeah, I thought about doing this, but it seemed there should be a better
way.  
>
> Is there a command after the remove-hook that puts the hook back?

That is a good question.  I looked at the documentation for the
function and it says: 

w3m-print-this-url is an interactive compiled Lisp function in `w3m'.
(w3m-print-this-url &optional INTERACTIVE-P)

Display the url under point in the echo area and put it into `kill-ring'.

This function is advised.

After-advice `emacspeak':
Produce auditory icon.

The changes that emacspeak makes on the hook come from the file
emacspeak-w3m.el I think.  I guess it could be that the file is not
loaded until after the .emacs file is loaded and w3m is started for the
first time.  I am going to put some message lines in the file to see
when it is loaded.

If it is the case that the file is not loaded until after my .emacs,
what can be done to take care of this, outside of editing the source of
the file itself?  I think that is a very bad idea.

Thanks,

rdc

-- 
:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:
Robert D. Crawford                                      rdc1x@comcast.net

Q:	What do you have when you have a lawyer buried up to his neck in sand?
A:	Not enough sand.
:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:|:

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: elisp help needed
  2006-03-01 16:58 elisp help needed Robert D. Crawford
  2006-03-01 21:37 ` RD
@ 2006-03-02 12:50 ` Katsumi Yamaoka
  2006-03-02 13:34   ` Robert D. Crawford
  1 sibling, 1 reply; 11+ messages in thread
From: Katsumi Yamaoka @ 2006-03-02 12:50 UTC (permalink / raw)


>>>>> In <87irqygkzs.fsf@laptop.rdc1.home> Robert D. Crawford wrote:

> I have the following lines in my .emacs file:

> (remove-hook 'w3m-after-cursor-move-hook
>      #'w3m-print-this-url)

> and for some reason, to get it to eval I have to do it by hand every
> time I restart emacs.  I *think* this might be the only code that is not
> being evaled, but I do not know any way to be certain.

I guess it is eval'd before loading w3m.elc.  If so, nothing
will happen.  The best way is to put such things into the
~/.emacs-w3m.el file.  Please consult the emacs-w3m Info manual.
Here's an extract:

2.6 Minimal settings to run emacs-w3m
=====================================
[...]
`Startup File'
     We recommend using the `~/.emacs-w3m' file (which is the default
     value of `w3m-init-file') if you need to twiddle some emacs-w3m
     variables.  This file is similar to `~/.emacs', but is read when
     emacs-w3m starts.  Note that some options shouldn't be modified
     there, for example, `w3m-command'.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: elisp help needed [solved]
  2006-03-02 11:36   ` Robert D. Crawford
@ 2006-03-02 13:28     ` Robert D. Crawford
  2006-03-04 12:26     ` elisp help needed Tim Cross
  1 sibling, 0 replies; 11+ messages in thread
From: Robert D. Crawford @ 2006-03-02 13:28 UTC (permalink / raw)


"Robert D. Crawford" <rdc1x@comcast.net> writes:

>> Is there a command after the remove-hook that puts the hook back?
>
> That is a good question.  I looked at the documentation for the
> function and it says:
>
/snip/

> The changes that emacspeak makes on the hook come from the file
> emacspeak-w3m.el I think.  

I was wrong here, but  it really doesn't matter.  


> I guess it could be that the file is not
> loaded until after the .emacs file is loaded and w3m is started for
> the first t

Here is where the important part starts.  I guess the hook is defined,
or added to after the .emacs file is read.  All I did was to move the
function to the .emacs-w3m file so that it ws read when w3m starts and
everything was fine.

Thanks for putting me on the right track.

rdc

-- 
::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::
Robert D. Crawford                                      rdc1x@comcast.net

You will engage in a profitable business activity.
::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: elisp help needed
  2006-03-02 12:50 ` Katsumi Yamaoka
@ 2006-03-02 13:34   ` Robert D. Crawford
  0 siblings, 0 replies; 11+ messages in thread
From: Robert D. Crawford @ 2006-03-02 13:34 UTC (permalink / raw)


Katsumi Yamaoka <yamaoka@jpl.org> writes:

> I guess it is eval'd before loading w3m.elc.  If so, nothing will
> happen.  The best way is to put such things into the ~/.emacs-w3m.el
> file.  Please consult the emacs-w3m Info manual.  Here's an extract:
>
I wish I would have read your post before I replied to mine.

thanks,

rdc

-- 
::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::
Robert D. Crawford                                      rdc1x@comcast.net

You will engage in a profitable business activity.
::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::|::

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: elisp help needed
  2006-03-02 11:36   ` Robert D. Crawford
  2006-03-02 13:28     ` elisp help needed [solved] Robert D. Crawford
@ 2006-03-04 12:26     ` Tim Cross
  2006-03-04 13:57       ` Robert D. Crawford
  1 sibling, 1 reply; 11+ messages in thread
From: Tim Cross @ 2006-03-04 12:26 UTC (permalink / raw)


"Robert D. Crawford" <rdc1x@comcast.net> writes:

> RD <rjjd@localnet.com> writes:
>
>> Robert D. Crawford wrote:
>>> I have the following lines in my .emacs file: 
>>
>> (remove-hook 'w3m-after-cursor-move-hook #'w3m-print-this-url) 
>>
>>and for some
>>> reason, to get it to eval I have to do it by hand every time I
>>> restart emacs.  I *think* this might be the only code that is not
>>> being evaled, but I do not know any way to be certain.  I know that
>>> there are things below this line that are being correctly evaled.
>>> All the code in the customize section seems to be ok, and I have a
>>> function that byte-compiles .el files when they are saved that works.
>>> Is there some way to know what is being evaled?  Thanks, rdc
>>>
>>
>> I use the old "print" method.  I salt my .emacs file with (message
>> "blah") commands to report progress.
>
> Yeah, I thought about doing this, but it seemed there should be a better
> way.  
>>
>> Is there a command after the remove-hook that puts the hook back?
>
> That is a good question.  I looked at the documentation for the
> function and it says: 
>
> w3m-print-this-url is an interactive compiled Lisp function in `w3m'.
> (w3m-print-this-url &optional INTERACTIVE-P)
>
> Display the url under point in the echo area and put it into `kill-ring'.
>
> This function is advised.
>
> After-advice `emacspeak':
> Produce auditory icon.
>
> The changes that emacspeak makes on the hook come from the file
> emacspeak-w3m.el I think.  I guess it could be that the file is not
> loaded until after the .emacs file is loaded and w3m is started for the
> first time.  I am going to put some message lines in the file to see
> when it is loaded.
>
> If it is the case that the file is not loaded until after my .emacs,
> what can be done to take care of this, outside of editing the source of
> the file itself?  I think that is a very bad idea.
>
Robert,

I think something changed in the emacspeak-w3m which stops this
workaround for removing that function. However, if you look into the
customize group for w3m, you will find there is a hook variable which
adds that function, so you can just remove it. From memory, it is
w3m-after-cursor-move-hook.

Tim

-- 
Tim Cross
tcross@rapttech.com.au

There are two types of people in IT - those who do not manage what they 
understand and those who do not understand what they manage.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: elisp help needed
  2006-03-04 12:26     ` elisp help needed Tim Cross
@ 2006-03-04 13:57       ` Robert D. Crawford
  0 siblings, 0 replies; 11+ messages in thread
From: Robert D. Crawford @ 2006-03-04 13:57 UTC (permalink / raw)


Hi Tim,

Tim Cross <tcross@tiger.rapttech.com.au> writes:

> Robert,
>
> I think something changed in the emacspeak-w3m which stops this
> workaround for removing that function. 

I just had it in the wrong place.  I had it in my .emacs file and it
needed to be in my .emacs-w3m file.

> However, if you look into the customize group for w3m, you will find
> there is a hook variable which adds that function, so you can just
> remove it. From memory, it is w3m-after-cursor-move-hook.

I'll check this out.
>
Thanks,

rdc


-- 
<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->
Robert D. Crawford                                      rdc1x@comcast.net

You will remember something that you should not have forgotten.
<-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><-><->

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-03-04 13:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-01 16:58 elisp help needed Robert D. Crawford
2006-03-01 21:37 ` RD
2006-03-02 11:36   ` Robert D. Crawford
2006-03-02 13:28     ` elisp help needed [solved] Robert D. Crawford
2006-03-04 12:26     ` elisp help needed 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
  -- strict thread matches above, loose matches on Subject: below --
2003-11-26 22:59 Elisp " Tassilo Horn
2003-11-27  6:29 ` Eli Zaretskii
     [not found] ` <mailman.693.1069918173.399.help-gnu-emacs@gnu.org>
2003-11-27  8:48   ` Tassilo Horn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).