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

Re: use current folder name as argument to abitrary command



On Fri, Dec 12, 2008 at 09:20:56AM -0600, Kyle Wheeler wrote:
> > That said, even when I run 'set my_curdir="^"' in mutt after muttrc 
> > has been read, my_curdir is still empty.
> 
> Really? When I do it, my_curdir becomes "^". Test it like this:
> 
>      set ?my_curdir

My previous statement was incorrect.  When I run 

    set my_curdir="^"

it does indeed contain "^".  HOWEVER, when I have the following:

    folder-hook . set my_curdir="^"
    macro index,pager S "<save-message>$my_archdir/$my_curdir<enter>"

and hit 'S', Mutt says:

    Create /mnt/data/storage/mail/boxes/? ([yes]/no)

indicating that, at least in the context of the macro, my_curdir was
empty. Is this because when reading the rc file, mutt did not actually
run the folder-hook because no folder is loaded until after the rc file
is loaded, and then the usage of my_curdir in the macro gets evaluated
at a point when that variable has not yet been defined?

> Your macro has an additional problem: it wouldn't work even if 
> my_curdir WAS correctly being set! You see, variable expansion is 
> evaluated at the time the macro is established!
I figured that might be a problem.  I switched to the folder-hook
because I thought that might get reevaluated every time the hook was
run.  Is that true, or do I also need to escape variables in hooks as
well?

Speaking of variable escaping:

> If you want the variable to be re-interpreted every the macro is
> triggered, you'd have to do this:
>
>      macro index,pager S "<save-message>\$my_archdir<enter>"
I tried the following (never mind in this case if the folder-hook
doesn't actually give me the current folder name):

    folder-hook . set my_curdir="^"
    macro index,pager S "<save-message>$my_archdir/\$my_curdir<enter>"

Mutt's response was:

    Create /mnt/data/storage/mail/boxes/$my_curdir? ([yes]/no)

Rather than causing the variable to be re-evaluated, it appears to have
literalized it. my_archdir will never change once mutt is started, so
I'm not escaping that one.

> > If not, how does one get the current folder name in a variable which 
> > can be used in various places?
> 
> Well, technically, if you set $record to ^, you can use that. That's 
> not exactly *convenient*, since $record has a primary function, I know 
> that, but... As far as I know, there isn't a really *good* way to do 
> what you're looking for (at the moment).

Perhaps there's another variable that has a less important primary
function that I could use.

In general, how did you learn this stuff about which variables expect
mailbox paths, which are just regular strings, when macro expansion
happens, when stuff needs escaping, etc? I did not RT entire FM, but I
did look through it and didn't find anything very helpful.

Thanks for the help,
-- 
Noah Sheppard
Assistant Computer Resource Manager
Taylor University CSE Department
nsheppar@xxxxxxxxxxxxxx