<<< Date Index >>>     <<< Thread Index >>>

Re: Difference between 'push' and 'exec', is there any?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday, August  8 at 06:38 PM, quoth Chris G:
>Is there any actual difference between the 'push' and 'exec' commands?

Yes.

Push queues up characters to be read in *as if you'd typed them* 
(though, confusingly, it also accepts function calls). Exec can only 
execute function calls. To quote the manual 
(http://www.mutt.org/doc/devel/manual.html):

    ``exec function'' is equivalent to ``push <function>''.

So, I can 'push <save-message>' and I can 'exec save-message'. 
However, I can 'push <save-message>=Drafts<enter>' but I can't exec 
that.

Both functions are generally meant to be done at *runtime* rather than 
in your muttrc.

>Also, if I source something like the following:-
>
>    set mbox_type=maildir
>    exec save-message
>    set mbox_type=mbox  
>
>It doesn't do what I expect as the message *doesn't* get saved in
>maildir format.  Presumably this is something to do with the order in
>which mutt executes the things it finds in a file which is sourced.
>Is there any information on this anywhere?

Repeat after me: A muttrc file is *not* a script.

It may have some behaviors that seem similar to a script, but it is 
NOT A SCRIPT. A muttrc is interpreted, in its entirety, before 
consequences of those commands are felt (with the exception of 
changing config_charset). Anything that is "source"'d is treated as an 
"initialization file", so settings all take effect more or less 
concurrently. Calls to exec and push will only be resolved once mutt 
is back in it's usual runtime loop.

In addition, save-message requires user input, and so can only happen 
when mutt is back in it's usual runtime loop, not in the middle of 
reading a file or executing a macro.

>Would a sourced file containing a series of 'push' commands execute
>them in the order expected (i.e. sort of backwards).  For example if I
>source the following:-
>
>    push ":set mbox_type=mbox"
>    push save-message
>    push ":set mbox_type=maildir"
>
>Will it switch to maildir, save a message and then switch back to
>mbox?

No. What will happens is that you'll switch to maildir, and then mutt 
will ask you where you would like to save the message, and then it 
will think you typed in ":set mbox_type=maildir" as the name of the 
mailbox to save it in.

push != exec. Push adds things to the input buffer. Mutt cannot read 
input from the keyboard when there's already input in there (i.e. the 
last push's text is in the input stream ahead of whatever you might 
type on the keyboard). There is currently no way to "wait for function 
X that requires user input to complete, then do Y" as you are 
attempting to do here, in part because mutt only has a single queue of 
"user input".

The only way I can think of to do kinda what you want is to create a 
script that uses safecat and asks you for a filename (e.g. with an 
ncurses dialog box, such as dialog or lxdialog).

~Kyle
- -- 
To bathe a cat takes brute force, perseverance, courage of 
conviction---and a cat. The last ingredient is usually hardest to come 
by.
                                                      -- Stephen Baker
-----BEGIN PGP SIGNATURE-----
Comment: Thank you for using encryption!

iD8DBQFGughnBkIOoMqOI14RApeoAKDqFb92ChtgZv5DLyVZQ75YfYsf7wCg/7Jm
NE1A1juLTnB372VeCo61K1E=
=yhxu
-----END PGP SIGNATURE-----