I think, per expansion processing rules, a user expansion would (or should) be applied to all modules, as they are consulted. So, the expansion should apply everywhere.
re: specifics
Consider for example a language that allows specifying code blocks such as a “with” statement in VB.NET [1], which enables writing code without need to repeat an object expression – or, to take another example from logtalk – a scope declaration for an object description.
in both cases you want to have block of code, such as so:
begin_block(term_x).
keyword1(a,b,c).
end_block.
Internally, such block could be processed to mean language_term(term1(a,b,c,term_x)).
To get to that, one needs to process expanded terms for begin_block/1 and for end_block and keyword1.
Implicit there is also an ordering if two or more such blocks are declared and when the declaration of a term_y depends on the existence of a prior declaration term_x.
Now, what if term_x would be declared in a module and term_y in another module or user file – the problem then is to ensure correct ordering of expansion, as they occur during consult – which, i guess, is a level of control not specified in prolog – although, it might implicitly be based on some explicit or implicit module import dependency graph.
Dan
Edit:
But, if a user scoped term expansion is declared in a module – then knowledge of its existence seems to happen only after the module is consulted – so, ordering of module consult would, in such a case, affect expansion processing – as you have indicated …
So the programmer should ensure that a module that declares a DSL that should be usable across to program is consulted as early as possible – hence, how :-use_module are declared relative to the user file would be crucial.
[1] With...End With Statement - Visual Basic | Microsoft Learn