On Wed, Oct 05, 2016 at 04:42:38PM -0700, Kevin J. McCarthy wrote: > TL;DR: > > $alias_file is expanded at muttrc parsing time, not when the folder-hook > is run. > > One workaround is to defer evaluation of $alias_file by using > \$alias_file (see https://dev.mutt.org/doc/manual.html#set-myvar). > > Alternatively, you can just spell out the file in both the set and the > source. (literally, or perhaps by using a user-defined variable to > reduce duplication). > > Details: > > Since $alias_file defaults to the value of the muttrc, essentially each > of your hooks initially will set $alias_file and re-read the muttrc. > They are equivalent to: > > folder-hook "foo_folder" "unalias *; set alias_file = +foo_alias; source > muttrc" > > folder-hook "bar_folder" "unalias *; set alias_file = +bar_alias; source > muttrc" > > folder-hook "last_folder" "unalias *; set alias_file = +last_alias; source > muttrc" > > Lets say you enter foo_folder first. This will run the first hook > above, resourcing the muttrc and creating three new folder hooks. So > all the folder hooks will look like this: > > folder-hook "foo_folder" "unalias *; set alias_file = +foo_alias; source > muttrc" > folder-hook "foo_folder" "unalias *; set alias_file = +foo_alias; source > +foo_alias" > > folder-hook "bar_folder" "unalias *; set alias_file = +bar_alias; source > muttrc" > folder-hook "bar_folder" "unalias *; set alias_file = +bar_alias; source > +foo_alias" > > folder-hook "last_folder" "unalias *; set alias_file = +last_alias; source > muttrc" > folder-hook "last_folder" "unalias *; set alias_file = +last_alias; source > +foo_alias" > > Note that mutt will not create exact duplicate folder-hooks. So > subsequently entering foo_folder will not create any more folder hooks > when sourcing the muttrc. > > But, when you enter bar_folder, it will add a third folder hook to every > folder (sourcing +bar_alias), and last_folder will add a forth hook when > entered. After that, whichever folder you enter, the last folder hook > will "win".
Hi Kevin, thank you for the in-depth explanation. I now understand what was going on under the hood. I also read about variable late expansion, but for some reason i didn't think this was the case. Now everything works as expected. Thanks again for this exhaustive mail, really appreciated it. Have a nice day!