anchor.diff:      ModName=list_to_atom(filename:basename(File, ".erl")),
       case NewName of
           {generator, GenFun} ->
  -            GenFun({ModName, FA, V});
  +            GenFun({File, FA, V});
           {user_input, GenPrompt} ->
               {prompt, GenPrompt({ModName, FA,V})};
           _ when is_atom(NewName) ->
  
positive.code: %% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
  %% ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  %% =====================================================================
  %% The refactoring command level API that can be run in an Erlang shell.
  %%
  %% Author contact: H.Li@kent.ac.uk, Simon.J.Thompson@kent.ac.uk
  %%
  %% =====================================================================
  %%@hidden
  %%@private
  -module(wrangler_extended).
  
  -export([rename_fun/4, 
           rename_var/5, 
           swap_args/5,
           tuple_args/5,
           fold_expr/5,
           gen_fun/5,
           gen_fun/6,
           move_fun/4,
           unfold_fun_app/3]).
  
  -export([gen_question/2]).
  
  -include("../include/wrangler.hrl").
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%                                                              %%
  %% Generalised interface for moving a function btw modules.     %%
  %%                                                              %%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  -type (file_filter()::{file,fun((File::filename()) -> boolean())}).
  
  
negative.code:                          ?SPLICE(E@)==ExprStr)], FunDef)
      end.
  
  test_gen_fun(SearchPaths, Lazy) ->
      gen_fun({file, fun(_File)-> true end}, 
              fun({_F,_A}) ->
                      true
              end,
              "1",
              {user_input, fun(_) ->"New parameter name: " end},
              Lazy,
              SearchPaths, bu).
  
  
  %% @doc Generalised interface for folding expressions against function definition.
  -spec fold_expr(CurModOrFile::mod_or_file(), 
                  ModOrFile::mod_or_file(), 
                  FA::fa(), 
                  ClauseIndex::integer(), 
                  Lazy::boolean(),
                  SearhPaths::search_paths()) ->
                         [elementary_refac()] | lazy_refac().
  
  fold_expr(CurModOrFile, TgtModOrFile, FA, ClauseIndex, false, SearchPaths) ->
      Files1= gen_file_names(CurModOrFile, SearchPaths),
      Files2= gen_file_names(TgtModOrFile, SearchPaths),
      [fold_expr_1(File1,  File2, F, A, ClauseIndex, SearchPaths)
       ||File1<-Files1, File2<-Files2, {F, A}<-get_fun_arity(File2, FA)];
  fold_expr(CurModOrFile, TgtModOrFile, FA, ClauseIndex, true, SearchPaths) ->
      case gen_file_names(CurModOrFile, true, SearchPaths) of
          [] -> [];
          [F] ->get_next_fold_expr_command(
                  {F, none}, TgtModOrFile, FA, ClauseIndex, SearchPaths);
          {F, NextFileGen} ->
              get_next_fold_expr_command(
                {F, NextFileGen}, TgtModOrFile, FA, ClauseIndex, SearchPaths)
      end.
  
  get_next_fold_expr_command({File, NextFileGen}, TgtModOrFileFilter, FA, ClauseIndex, SearchPaths) ->
      case gen_file_names(TgtModOrFileFilter, true, SearchPaths) of 
          [] -> [];
          [TgtFile] ->
              get_next_fold_expr_command_1(
                {File, NextFileGen}, {TgtFile,none}, FA, ClauseIndex, SearchPaths,
                {TgtModOrFileFilter, FA});
          {TgtFile, NextTgtFileGen} ->
              get_next_fold_expr_command_1(
                {File, NextFileGen}, {TgtFile, NextTgtFileGen}, FA,  ClauseIndex, SearchPaths,
                {TgtModOrFileFilter, FA})
      end.
  
  get_next_fold_expr_command_1({File, NextFileGen}, {TgtFile, NextTgtFileGen}, 
                               FA, ClauseIndex, SearchPaths, {OrigTgtModOrFile, OrigFA}) ->
      case get_fun_arity({TgtFile, NextTgtFileGen}, FA, true) of
          [] ->
              case NextFileGen of
                  {lazy_file_gen, Gen} ->
                      case Gen() of 
                          [] ->
                             [];
                          {File1, NextFileGen1} ->
                              get_next_fold_expr_command({File1, NextFileGen1},OrigTgtModOrFile, 
                                                        OrigFA, ClauseIndex, SearchPaths)
                      end;
                  _ -> []
              end;
          [{F,A}] ->
              Refac= fold_expr_1(File, TgtFile, F, A, ClauseIndex, SearchPaths),
              case NextFileGen of 
                  {layze_file_gen, Gen} ->
                      case Gen() of 
                          [] ->
                              [Refac];
                          {File1, NextFileGen1} ->
                              {Refac, {lazy_gen, fun() ->
                                                         get_next_fold_expr_command(
                                                           {File1, NextFileGen1},OrigTgtModOrFile, 
                                                           OrigFA, ClauseIndex, SearchPaths)
                                                 end}}
                      end;
                  _ -> [Refac]
              end;
          {{TgtFile1, F,A},  {TgtFile2, NextTgtFileGen2}, NextFAGen}->
              Refac= fold_expr_1(File, TgtFile1, F, A, ClauseIndex, SearchPaths),
              {Refac, {lazy_gen, fun()->                                   
                                         get_next_fold_expr_command_1(
                                           {File, NextFileGen}, {TgtFile2, NextTgtFileGen2},
                                           NextFAGen, ClauseIndex, SearchPaths, 
                                           {OrigTgtModOrFile, OrigFA})
                                 end}}
      end.
             
  fold_expr_1(CurFile, TgtFile, FunName, Arity, ClauseIndex, SearchPaths) ->
      ModName=list_to_atom(filename:basename(TgtFile, ".erl")),
      {refactoring, {refac_fold_expression, fold_expr_by_name}, 
       [CurFile, atom_to_list(ModName), atom_to_list(FunName), 
        integer_to_list(Arity), integer_to_list(ClauseIndex), 
        SearchPaths]}.
          
  test_fold_expr(SearchPaths, Lazy) ->
      fold_expr({file, fun(_File)-> true end},
                {file, fun(_File)-> true end},
                fun({_F, A}) ->
                        A==0
                end, 
                1, Lazy, SearchPaths).
                        
  %% @doc Generalised interface for unfolding a function application.
  -spec unfold_fun_app(ModOrFile::mod_or_file(), 
                       FA:: fa(),
                       MFAorPos:: fun((mfa())->boolean()) |mfa()|pos(),
                       Lazy :: boolean(),
                       SearchPaths::search_paths())->
                              [elementary_refac()] | lazy_refac().
  unfold_fun_app(ModOrFile, FA, MFAorPos, false, SearchPaths) ->
      Files= gen_file_names(ModOrFile, SearchPaths),
      Refacs=[unfold_fun_app_1(File, {F, A}, MFAorPos, SearchPaths)
              ||File<-Files, {F, A}<-get_fun_arity(File, FA)],
      lists:append(Refacs);
  unfold_fun_app(ModOrFile, FA, MFAorPos, true, SearchPaths) ->
      Res=gen_file_names(ModOrFile, true, SearchPaths),
      case Res of
          [] -> [];
          [F] ->get_next_unfold_app_command(
                  {F, none}, FA, MFAorPos, SearchPaths, -1);
          {F, NextFileGen} ->
              get_next_unfold_app_command(
                {F, NextFileGen}, FA, MFAorPos, SearchPaths, -1)
      end.
  get_next_unfold_app_command({File, {lazy_file_gen, NextFileGen}}, FA, 
                              MFAorPos, SearchPaths, N) ->
      FAs= get_fun_arity({File, {lazy_file_gen, NextFileGen}}, FA, true),
      case FAs of
          []->[]; 
          [{F, A}] ->  
              Cmds=unfold_fun_app_1(File, {F, A}, MFAorPos, SearchPaths),
              case Cmds of 
                  [] -> [];
                  [R|Rs] when N==-1 ->
                      {R,{lazy_gen, fun()->
                                            get_next_unfold_app_command(
                                              {File, none}, FA, MFAorPos, SearchPaths, length(Rs))
                                    end}};
                  _ ->
                      Nth = length(Cmds)-N+1,
                      case N == 1 of 
                          true ->
                              [lists:neth(Nth, Cmds)];
                          _ ->
                              {lists:nth(Nth, Cmds), 
                               {lazy_gen, fun()->
                                                  get_next_unfold_app_command(
                                                    {File, none}, FA, MFAorPos, SearchPaths, N-1)
                                          end}}        
                      end
              end;
          {{File1, F,A},  {File2, NextFileGen2}, FAGen}->
              Cmds=unfold_fun_app_1(File1, {F, A}, MFAorPos, SearchPaths),
              case Cmds of 
                  [] ->
                      get_next_unfold_app_command({File2, NextFileGen2}, FAGen, MFAorPos, SearchPaths, -1);
                  [R] when N==-1 ->
                      {R,{lazy_gen, fun()->
                                            get_next_unfold_app_command(
                                              {File2, NextFileGen2}, FAGen, MFAorPos, SearchPaths, -1)
                                     end}};
                  [R|Rs] when N==-1 ->
                      {R,{lazy_gen, fun()->
                                            get_next_unfold_app_command(
                                              {File1, {lazy_file_gen, NextFileGen}}, FA, MFAorPos, SearchPaths, length(Rs))
                                    end}};
                  _ ->Nth = length(Cmds)-N+1,
                      case N==1 of 
                          true ->
                              {lists:nth(Nth, Cmds), 
                               {lazy_gen, fun()->
                                                  get_next_unfold_app_command(
                                                     {File2, NextFileGen2}, FAGen, MFAorPos, SearchPaths, -1)
                                          end}};     
                          false ->
                              {lists:nth(Nth, Cmds), 
                               {lazy_gen, fun()->
                                                  get_next_unfold_app_command(
                                                    {File1, {lazy_file_gen, NextFileGen}}, FA, MFAorPos, SearchPaths, N-1)
                                          end}}        
                      end
              end
      end.
           
          
          
  unfold_fun_app_1(File, {F, A}, MFAorPos, SearchPaths) ->
      case MFAorPos of 
          {Line, Col} when is_integer(Line) andalso is_integer(Col) ->
              {refactoring, {refac_unfold_fun_app, unfold_fun_app},
               [File, {Line, Col}, SearchPaths]};
          MFA ->
              Ps = get_app_locs(File, {F, A}, MFA),
              [{refactoring, {refac_unfold_fun_app, unfold_fun_app},
                [File, Pos, SearchPaths]} || Pos<-Ps]
      end.
          
  test_unfold_fun(SearchPaths, Lazy) ->
      unfold_fun_app({file, fun(_File)-> true end},
                     fun({_F, _A}) ->
                             true
                     end,
                     {test, t, 0}, Lazy, SearchPaths).
  
  %% @doc Generalised interface for swapping function arguments.
  -spec swap_args(ModOrFile::mod_or_file(),
                   FA::fa(),
                   Index1:: integer()| 
                            {user_input, Prompt::fun(({M::atom(), FA::{atom(),integer()}})->
                                                            string())},
                   Index2:: integer()|
                            {user_input,Prompt::fun(({M::atom(), FA::{atom(),integer()}})->
                                                           string())},
                   Lazy::boolean(),
                   SearchPaths::search_paths())->
                          [elementary_refac()]|lazy_refac().
  swap_args(ModOrFile, FA, Index1,Index2, false, SearchPaths)->
      Files= gen_file_names(ModOrFile, SearchPaths),
      [swap_args_1(File, {F, A}, Index1, Index2, SearchPaths)
       ||File<-Files, {F, A}<-get_fun_arity(File, FA)];
  
  swap_args(ModOrFile, FA, Index1, Index2, true, SearchPaths) ->
      case gen_file_names(ModOrFile, true, SearchPaths) of
          [] -> [];
          [F] ->get_next_swap_args_command(
                  {F, none}, FA, Index1, Index2, SearchPaths);
          {F, NextFileGen} ->
              get_next_swap_args_command(
                {F, NextFileGen}, FA, Index1, Index2, SearchPaths)
      end.
  
  get_next_swap_args_command({File, NextFileGen}, FA, Index1, Index2, SearchPaths) ->
      case get_fun_arity({File, NextFileGen}, FA, true) of
          []->[]; 
          [{F,A}] ->
              [swap_args_1(File, {F, A}, Index1, Index2, SearchPaths)]; 
          {{File1, F,A},  {File2, NextFileGen2}, NextFAGen}->
              Refac=swap_args_1(File1, {F, A}, Index1, Index2, SearchPaths),
              {Refac, {lazy_gen, fun()-> get_next_swap_args_command(
                                           {File2, NextFileGen2}, NextFAGen, 
                                           Index1, Index2, SearchPaths)
                                 end}}
      end.
   
  swap_args_1(File, {F, A}, Index1, Index2, SearchPaths) ->
      {refactoring, {refac_tuple, swap_args}, 
       [File, {F, A},  index_gen(Index1, {File, {F, A}}), 
        index_gen(Index2, {File, {F, A}}), SearchPaths]}.
      
  test_swap_args(SearchPaths, Lazy) ->
      swap_args({file, fun(_File)-> true end}, 
                 fun({_F, A}) ->
                         A>= 3 
                 end,
                 2, 3, Lazy, SearchPaths).
      
  %% @doc Generalised interface for tupling function arguments.
  -spec tuple_args(ModOrFile::mod_or_file(),
                   FA::fa(),
                   Index1:: integer()| 
                            {user_input, Prompt::fun(({M::atom(), FA::{atom(),integer()}})->
                                                            string())},
                   Index2:: integer()|
                            {user_input,Prompt::fun(({M::atom(), FA::{atom(),integer()}})->
                                                           string())},
                   Lazy::boolean(),
                   SearchPaths::search_paths())->
                          [elementary_refac()]|lazy_refac().
  tuple_args(ModOrFile, FA, Index1,Index2, false, SearchPaths)->
      Files= gen_file_names(ModOrFile, SearchPaths),
      [tuple_args_1(File, {F, A}, Index1, Index2, SearchPaths)
       ||File<-Files, {F, A}<-get_fun_arity(File, FA)];
  tuple_args(ModOrFile, FA, Index1, Index2, true, SearchPaths) ->
      case gen_file_names(ModOrFile, true, SearchPaths) of
          [] -> [];
          [F] ->get_next_tuple_args_command(
                  {F, none}, FA, Index1, Index2, SearchPaths);
          {F, NextFileGen} ->
              get_next_tuple_args_command(
                {F, NextFileGen}, FA, Index1, Index2, SearchPaths)
      end.
  
  get_next_tuple_args_command({File, NextFileGen}, FA, Index1, Index2, SearchPaths) ->
      case get_fun_arity({File, NextFileGen}, FA, true) of
          []->[]; 
          [{F,A}] ->
              [tuple_args_1(File, {F, A}, Index1, Index2, SearchPaths)]; 
          {{File1, F,A},  {File2, NextFileGen2}, NextFAGen}->
              Refac=tuple_args_1(File1, {F, A}, Index1, Index2, SearchPaths),
              {Refac, {lazy_gen, fun()-> get_next_tuple_args_command(
                                           {File2, NextFileGen2}, NextFAGen, 
                                           Index1, Index2, SearchPaths)
                                 end}}
      end.
   
  tuple_args_1(File, {F, A}, Index1, Index2, SearchPaths) ->
      {refactoring, {refac_tuple, tuple_args}, 
       [File, {F, A},  index_gen(Index1, {File, {F, A}}), 
        index_gen(Index2, {File, {F, A}}), SearchPaths]}.
      
  test_tuple_args(SearchPaths, Lazy) ->
      tuple_args({file, fun(_File)-> true end}, 
                 fun({_F, A}) ->
                         A>= 3 
                 end,
                 2, 3, Lazy, SearchPaths).
                 
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %%                                                              %%
  %%                Utility functions.                            %%
  %%                                                              %%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  gen_file_names(ModOrFile, SearchPaths) ->
      gen_file_names(ModOrFile, false, SearchPaths).
  gen_file_names(ModOrFile, Lazy, SearchPaths) ->
      Files = wrangler_misc:expand_files(SearchPaths, ".erl"),    
      case ModOrFile of 
          {file, FileFilter} ->
              case Lazy of 
                  true ->
                      get_next_file(Files, {file,FileFilter});
                  false ->[F||F<-Files, FileFilter(F)]
              end;
          {module, ModFilter} ->
              case Lazy of 
                  true ->
                      get_next_file(Files, {module, ModFilter});
                  false ->
                      [F||F<-Files, ModFilter(filename:basename(F, ".erl"))]
              end;
          _ when is_atom(ModOrFile) ->
              Fs=[F||F<-Files, filename:basename(F,".erl")==atom_to_list(ModOrFile)],
              case Fs of 
                  [] -> [];
                  [F|_] -> [F]
              end;
          _ when is_list(ModOrFile)->
              case filelib:is_regular(ModOrFile) of 
                  true ->
                      [ModOrFile];
                  false ->
                      throw({error, lists:flatten(io_lib:format(
                                      "invalid argument:~p.", [ModOrFile]))})
              end;
          _ -> 
              throw({error, lists:flatten(io_lib:format(
                             "invalid argument:~p.", [ModOrFile]))})
      end.
  
  get_next_file([], _FileOrModFilter) -> [];
  get_next_file([F|Fs], Filter) ->
      case Filter of 
          {module, Fun} -> 
              M = filename:basename(F, ".erl"),
              case Fun(M) of 
                  true ->
                      {F, {lazy_file_gen, fun()-> get_next_file(Fs, Filter) end}};
                  false ->
                      get_next_file(Fs, Filter)
              end;
          {file, Fun} ->
              case Fun(F) of 
                  true ->
                      {F, {lazy_file_gen, fun()-> get_next_file(Fs, Filter) end}};
                  false ->
                      get_next_file(Fs, Filter)
              end
      end.
              
                          
  
  locate_one_file(ModOrFile, SearchPaths) ->
      Res= gen_file_names(ModOrFile, SearchPaths),
  