anchor.diff:      ?wrangler_io("\nCMD: ~p:move_fun(~p, ~p, ~p, ~p, ~p, ~p, ~p).",
   		 [?MODULE, FName, Line, Col, TargetModorFileName, CreateNewFile, SearchPaths, TabWidth]),
       {TargetFName, TargetModName} = get_target_file_mod_name(FName, TargetModorFileName),
  -    case TargetFName of 
  -	FName -> {error, "The target module is the same as the current module."};
  -	_ -> case filelib:is_file(TargetFName) orelse CreateNewFile == t orelse CreateNewFile == true of
  -		 true ->
  -		     {ok, {AnnAST, Info}} = refac_util:parse_annotate_file(FName, true, SearchPaths, TabWidth),
  -		     case refac_util:pos_to_fun_def(AnnAST, {Line, Col}) of
  -			 {ok, Def} ->
  -			     {value, {fun_def, {ModName, FunName, Arity, _Pos1, _Pos2}}} =
  -				 lists:keysearch(fun_def, 1, refac_syntax:get_ann(Def)),
  -			     NewTargetFile = case not filelib:is_file(TargetFName) andalso (CreateNewFile == t orelse CreateNewFile == true) of
  -						 true -> create_new_file(TargetFName, TargetModName),
  -							 true;
  -						 _ -> false
  -					     end,
  -			     R = side_cond_check({FName, ModName, FunName, Arity, Def}, TargetFName, list_to_atom(TargetModName), Def, SearchPaths, TabWidth),
  -			     case R of
  -				 true ->
  -				     {ok, {TargetAnnAST, Info1}} = refac_util:parse_annotate_file(TargetFName, true, SearchPaths, TabWidth),  
  -				     {AnnAST1, TargetAnnAST1} =
  -					 do_transformation({AnnAST, Info}, {TargetAnnAST, Info1},{ModName, FunName, Arity}, TargetModName),
  -				     case refac_util:is_exported({FunName, Arity}, Info) of
  -					 true ->
  -					     ?wrangler_io("\nChecking client modules in the following search paths: \n~p\n", [SearchPaths]),
  -					     ClientFiles = lists:delete(TargetFName,
  -									refac_util:get_client_files(FName, SearchPaths)),
  -					     Results = refactor_in_client_modules(ClientFiles,
  -										  {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth),
  -					     case Editor of
  -						 emacs ->
  -						     io:format("Results:\n~p\n", [Results]),
  -						     refac_util:write_refactored_files_for_preview([{{FName, FName}, AnnAST1},
  -												    {{TargetFName, TargetFName, NewTargetFile}, TargetAnnAST1}| Results]),
  -						     ChangedClientFiles =
  -							 lists:map(fun ({{F, _F}, _AST}) -> F end, Results),
  -						     ChangedFiles = [FName, TargetFName| ChangedClientFiles],
  -						     ?wrangler_io("The following files are to be changed by this refactoring:\n~p\n", [ChangedFiles]),
  -						     {ok, ChangedFiles};
  -						 eclipse ->
  -						     Results1 = [{{FName, FName}, AnnAST1},
  -								 {{TargetFName, TargetFName}, TargetAnnAST1}| Results],
  -						     Res = lists:map(fun ({{FName1, NewFName1}, AST}) ->
  -									     {FName1, NewFName1, refac_prettypr:print_ast(refac_util:file_format(FName1),AST)}
  -								     end,
  -								     Results1),
  -						     {ok, Res}
  -					     end;
  -					 false ->
  -					     case Editor of
  -						 emacs ->
  -						     refac_util:write_refactored_files_for_preview([{{FName, FName}, AnnAST1},
  -												    {{TargetFName, TargetFName, NewTargetFile}, TargetAnnAST1}]),
  -						     ChangedFiles = [FName, TargetFName],
  -						     ?wrangler_io("The following files are to be changed by this refactoring:\n~p\n",
  -								  [ChangedFiles]),
  -						     {ok, ChangedFiles};
  -						 eclipse ->
  -						     Results1 = [{{FName, FName}, AnnAST1}, {{TargetFName, TargetFName}, TargetAnnAST1}],
  -						     Res = lists:map(fun ({{FName1, NewFName1}, AST}) ->
  -									     {FName1, NewFName1, refac_prettypr:print_ast(refac_util:file_format(FName1),AST)}
  -								     end,
  -								     Results1),
  -						     {ok, Res}
  -					     end
  -				     end;
  -				 {error, Reason} -> {error, Reason}
  -			     end;
  -			 {error, Reason} -> {error, Reason}
  -		     end;
  -		 false -> {error, " Target module/file does not exist."}
  -	     end
  +    case TargetFName of
  +	FName -> throw({error, "The target module is the same as the current module."});
  +	_ -> ok
  +    end,
  +    case filelib:is_file(TargetFName) orelse CreateNewFile == t orelse CreateNewFile == true of
  +	true -> ok;
  +	false -> throw({error, " Target module/file does not exist."})
  +    end,
  +    {ok, {AnnAST, Info}} = refac_util:parse_annotate_file(FName, true, SearchPaths, TabWidth),
  +    case refac_util:pos_to_fun_def(AnnAST, {Line, Col}) of
  +	{ok, Def} ->
  +	    {value, {fun_def, {ModName, FunName, Arity, _Pos1, _Pos2}}} =
  +		lists:keysearch(fun_def, 1, refac_syntax:get_ann(Def)),
  +	    NewTargetFile = case not filelib:is_file(TargetFName) andalso
  +				(CreateNewFile == t orelse CreateNewFile == true)
  +				of
  +				true -> create_new_file(TargetFName, TargetModName),
  +					true;
  +				_ -> false
  +			    end,
  +	    case side_cond_check({FName, ModName, FunName, Arity}, TargetFName,
  +				 TargetModName, Def, SearchPaths, TabWidth)
  +		of
  +		{error, Reason} ->
  +		    case NewTargetFile of
  +			true -> file:delete(TargetFName);
  +			_ -> ok
  +		    end,
  +		    throw({error, Reason});
  +		true -> ok
  +	    end,
  +	    Pid = start_atom_process(),
  +	    {ok, {TargetAnnAST, TargetInfo}} = refac_util:parse_annotate_file(TargetFName, true, SearchPaths, TabWidth),
  +	    {AnnAST1, TargetAnnAST1} =
  +		do_transformation(FName, {AnnAST, Info}, {TargetAnnAST, TargetInfo}, {ModName, FunName, Arity},
  +				  TargetModName, SearchPaths, TabWidth, Pid),
  +	    check_atoms(FName, AnnAST1, [FunName], Pid),
  +	    check_atoms(TargetFName, TargetAnnAST1, [FunName], Pid),
  +	    Results = case refac_util:is_exported({FunName, Arity}, Info) of
  +			  true ->
  +			      ?wrangler_io("\nChecking client modules in the following search paths: \n~p\n", [SearchPaths]),
  +			      ClientFiles = lists:delete(TargetFName, refac_util:get_client_files(FName, SearchPaths)),
  +			      refactor_in_client_modules(ClientFiles, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid);
  +			  false ->
  +			      []
  +		      end,
  +	    output_atom_warning_msg(Pid, not_renamed_warn_msg(FunName), renamed_warn_msg(ModName)),
  +	    stop_atom_process(Pid),
  +	    case Editor of
  +		emacs ->
  +		    refac_util:write_refactored_files_for_preview([{{FName, FName}, AnnAST1},
  +								   {{TargetFName, TargetFName, NewTargetFile}, TargetAnnAST1}| Results]),
  +		    ChangedClientFiles = lists:map(fun ({{F, _F}, _AST}) -> F end, Results),
  +		    ChangedFiles = [FName, TargetFName| ChangedClientFiles],
  +		    ?wrangler_io("The following files are to be changed by this refactoring:\n~p\n", [ChangedFiles]),
  +		    {ok, ChangedFiles};
  +		eclipse ->
  +		    Results1 = [{{FName, FName}, AnnAST1}, {{TargetFName, TargetFName}, TargetAnnAST1}| Results],
  +		    Res = lists:map(fun ({{FName1, NewFName1}, AST}) ->
  +					    {FName1, NewFName1, refac_prettypr:print_ast(refac_util:file_format(FName1), AST)}
  +				    end,
  +				    Results1),
  +		    {ok, Res}
  +	    end;
  +	{error, Reason} -> {error, Reason}
       end.
   
   get_target_file_mod_name(CurrentFName, TargetModorFileName) ->
  
positive.code:     FunDef21=reset_attrs(FunDef2, {M2, F2, A2}),
      FunDef11 == FunDef21.
  
  check_macros(FileName, TargetFileName, FunDef, SearchPaths, TabWidth) ->
      UsedMacros = collect_used_macros(FunDef),
      case UsedMacros of 
  	[] ->
  	    true;
  	_ -> 
  	    Dir = filename:dirname(FileName),
  	    DefaultIncl1 = [".","..", "../hrl", "../incl", "../inc", "../include"],
  	    DefaultIncl2 = [filename:join(Dir, X) || X <-DefaultIncl1],
  	    NewSearchPaths= SearchPaths++DefaultIncl2,
  	    case refac_epp:parse_file(FileName, NewSearchPaths, [], TabWidth, refac_util:file_format(FileName))  of 
  		{ok, _, {MDefs, _MUses}} -> 
  		    UsedMacroDefs = [{Name, {Args, refac_util:concat_toks(Toks)}} || {{_, Name}, {Args, Toks}} <-MDefs, lists:member(Name, UsedMacros)],
  		    case length(UsedMacros) > length(UsedMacroDefs) of 
  			true ->  UnDefinedUsedMacros = UsedMacros -- [Name || {Name, _Def} <-UsedMacroDefs],
  				 ?wrangler_io("\nThe following macros are used by the function to be moved, but not defined:~p\n", [UnDefinedUsedMacros]),
  				 throw({error, "There are undefined macros used by the function to be moved."});
  			_ ->  case refac_epp:parse_file(TargetFileName, NewSearchPaths, [], TabWidth, refac_util:file_format(TargetFileName)) of 
  				  {ok, _, {MDefs1, _MUses1}} ->
  				      UsedMacroDefsInTargetFile = [{Name, {Args, refac_util:concat_toks(Toks)}} 
  								   || {{_, Name}, {Args, Toks}} <-MDefs1, lists:member(Name, UsedMacros)],
  				      case  length(UsedMacros) > length(UsedMacroDefsInTargetFile) of 
  					  true ->
  					      UnDefinedUsedMacrosInTargetFile = UsedMacros -- [Name || {Name, _Def} <-UsedMacroDefsInTargetFile], 
  					      ?wrangler_io("\nThe following macros are used by the function to be moved, but not defined in the target module:~p\n", 
  							   [UnDefinedUsedMacrosInTargetFile]),
  					      throw({error, "Some macros used by the function to be moved are not defined in the target module."});
  					  _ ->
  					      case lists:keysort(1,UsedMacroDefs) == lists:keysort(1,UsedMacroDefsInTargetFile) of 
  						  true -> true;
  						  _ -> throw({error, "Moving this function could change program semantics because of different macro definitions."})
  					      end
  				      end;
  				  _ -> throw({error, "Refactoring failed because the target file does not compile."})
  			      end
  		    end;
  		_ -> throw({error, "Refactoring failed because the current file does not compile."})
  	    end
      end.
  	    
  collect_used_macros(FunDef) ->
      F = fun(T, S) ->
  		case refac_syntax:type(T) of
  
negative.code: 		  case lists:keysearch(fun_def,1,refac_syntax:get_ann(T1)) of
  		      {value, {fun_def, {ModName, FunName, Arity, _, _}}} ->
  			  case {ModName, FunName, Arity} of 
  			      {M, F, A} -> refac_syntax:set_pos(refac_syntax:remove_comments(refac_syntax:set_ann(T1, [])), {0,0});
  			      _ -> refac_syntax:set_pos(
  				     refac_syntax:remove_comments(
  				       refac_syntax:set_ann(T1,[{fun_def, {ModName, FunName, Arity, {0,0},{0,0}}}])),{0,0})
  			  end;	      
  		      _ -> refac_syntax:set_pos(refac_syntax:remove_comments(refac_syntax:set_ann(T1, [])), {0,0})
  		  end
  	  end,
      refac_syntax_lib:map(Fun, Node).
  
  
  do_rename_fun_in_tuples(Node, {FileName, SearchPaths, ModName, FunName, TargetModName, Arity, Pid, TabWidth}) ->
      case refac_syntax:tuple_elements(Node) of
  	[E1, E2, E3] ->
  	    case refac_rename_fun:try_eval(FileName, E1, SearchPaths, TabWidth) of
  		{value, ModName} ->
  		    case (refac_syntax:type(E2)==atom) andalso (refac_syntax:atom_value(E2)==FunName) of
  			true -> case (refac_syntax:type(E3)==list) andalso (refac_syntax:list_length(E3)==Arity) of
  				    true ->
  					Pid ! {add_renamed, {FileName, Node}},
  					{refac_syntax:tuple([copy_pos_attrs(E1, refac_syntax:atom(TargetModName)),E2, E3]), true}; 
  				    false ->
  					case (refac_syntax:type(E3)==nil) andalso (Arity==0) of 
  					    true ->
  						Pid ! {add_renamed, {FileName, Node}},
  						{refac_syntax:tuple([copy_pos_attrs(E1, refac_syntax:atom(TargetModName)),E2, E3]), true}; 
  					   false ->
  						case (refac_syntax:type(E3)==integer) andalso(refac_syntax:integer_value(E3)==Arity) of
  						    true ->
  							Pid ! {add_renamed, {FileName, Node}},
  							{refac_syntax:tuple([copy_pos_attrs(E1, refac_syntax:atom(TargetModName)),E2, E3]), true};
  						    false->
  							{Node, false}
  						end
  					end
  				end;
  			false -> {Node, false}
  		    end;
  		_ ->
  		    {Node, false}
  	    end;
  	[E0, E1, E2, E3] ->
  	    case refac_rename_fun:try_eval(FileName, E1, SearchPaths, TabWidth) of
  		{value, ModName} ->
  		    case (refac_syntax:type(E2)==atom) andalso (refac_syntax:atom_value(E2)==FunName) of
  			true -> case (refac_syntax:type(E3)==list) andalso (refac_syntax:list_length(E3)==Arity) of
  				    true ->
  					Pid ! {add_renamed, {FileName, Node}},
  					{refac_syntax:tuple([E0, copy_pos_attrs(E1, refac_syntax:atom(TargetModName)),E2, E3]), true}; 
  				    false ->
  					case (refac_syntax:type(E3)==nil) andalso (Arity==0) of 
  					    true ->
  						Pid ! {add_renamed, {FileName, Node}},
  						{refac_syntax:tuple([E0, copy_pos_attrs(E1, refac_syntax:atom(TargetModName)),E2, E3]), true}; 
  					   false ->
  						case (refac_syntax:type(E3)==integer) andalso(refac_syntax:integer_value(E3)==Arity) of
  						    true ->
  							Pid ! {add_renamed, {FileName, Node}},
  							{refac_syntax:tuple([E0, copy_pos_attrs(E1, refac_syntax:atom(TargetModName)),E2, E3]), true};
  						    false->
  							{Node, false}
  						end
  					end
  				end;
  			false -> {Node, false}
  		    end;
  		_ ->
  		    {Node, false}
  	    end;
  	_ -> {Node, false}
      end.
  
  format(none) ->
      none;
  format(Node) -> 
      refac_prettypr:format(Node).
  
  
  renamed_warn_msg(ModName) ->
      "\n=================================================================================\n"
       "WARNING: Wrangler has renamed the uses of '"++atom_to_list(ModName) ++ "' to the target "
       "module name within the following expressions while without enough "
       "syntactic/semantic information.\n Please check manually!\n".
    
  not_renamed_warn_msg(FunName) ->
      "\n=================================================================================\n"
       "WARNING: Wrangler could not infer whether the uses of '" ++atom_to_list(FunName) ++"' at the following positions "
       "refer to the function moved.\n Please check manually for necessary module name changes!\n".
      
  