anchor.diff:      end.
       
   
  -existing_macros(FileName, SearchPaths, TabWidth) -> 
  +existing_macros(FileName, SearchPaths, TabWidth) ->
       Dir = filename:dirname(FileName),
  -    DefaultIncl = [filename:join(Dir, X) || X <-refac_util:default_incls()],
  -    NewSearchPaths= SearchPaths++DefaultIncl,
  -    case refac_epp:parse_file(FileName, NewSearchPaths, [], TabWidth, refac_util:file_format(FileName))  of 
  -	{ok, _, {MDefs, MUses}} -> 
  -	    lists:usort(lists:map(fun({{_,Name}, _Def}) -> Name end, MDefs++MUses));	 
  -	_ -> {error, "The current file does not compile!"}
  +    DefaultIncl = [filename:join(Dir, X) || X <- refac_misc:default_incls()],
  +    NewSearchPaths = SearchPaths ++ DefaultIncl,
  +    case refac_epp:parse_file(FileName, NewSearchPaths, [], TabWidth, refac_util:file_format(FileName)) of
  +      {ok, _, {MDefs, MUses}} ->
  +	  lists:usort([Name || {{_, Name}, _Def} <- MDefs ++ MUses]);
  +      _ -> {error, "The current file does not compile!"}
       end.
   	    
  -	
  -
  -vars(Node) ->
  -    F = fun(T,S) ->
  -		case refac_syntax:type(T) of 
  -		    variable ->
  -			case lists:keysearch(category, 1, refac_syntax:get_ann(T)) of
  -			    {value, {category, macro_name}} ->
  -				 S;
  -			    _ ->		
  -				[refac_syntax:variable_name(T)|S]
  -			end;
  -		    _ -> S
  -		end
  -	end,
  -    lists:usort(refac_syntax_lib:fold(F, [], Node)).
  -  
   need_bracket(Toks, Exprs) ->
       case Exprs of 
   	[E] ->
  
positive.code: 	_ -> []
      end.
      
  
negative.code: 
  %% =============================================================================================
  
  -spec(new_macro/6::(filename(), pos(), pos(), string(), [dir()], integer()) ->
  	       {ok, string()}).
  new_macro(FileName, Start, End, NewMacroName, SearchPaths, TabWidth) ->
      new_macro(FileName, Start, End, NewMacroName, SearchPaths, TabWidth, emacs).
  
  -spec(new_macro_eclipse/6::(filename(), pos(), pos(), string(), [dir()], integer()) ->
  				 {ok, [{filename(), filename(), string()}]}).
  new_macro_eclipse(FileName, Start, End, NewMacroName, SearchPaths, TabWidth) ->
      new_macro(FileName, Start, End, NewMacroName, SearchPaths, TabWidth, eclipse).
  
  
  new_macro(FileName, Start = {SLine, SCol}, End = {ELine, ECol}, NewMacroName, SearchPaths, TabWidth, Editor) ->
      ?wrangler_io("\nCMD: ~p:new_macro(~p, {~p,~p}, {~p,~p}, ~p, ~p,~p).\n",
  		 [?MODULE, FileName, SLine, SCol, ELine, ECol, NewMacroName, SearchPaths, TabWidth]),
      Cmd = "CMD: " ++ atom_to_list(?MODULE) ++ ":new_macro(" ++ "\"" ++
  	    FileName ++ "\", {" ++ integer_to_list(SLine) ++ ", " ++ integer_to_list(SCol) ++ "}," ++
  	      "{" ++ integer_to_list(ELine) ++ ", " ++ integer_to_list(ECol) ++ "}," ++ "\"" ++ NewMacroName ++ "\","
  		++ "[" ++ refac_misc:format_search_paths(SearchPaths) ++ "]," ++ integer_to_list(TabWidth) ++ ").",
      {ok, {AnnAST, _Info}} = refac_util:parse_annotate_file(FileName, true, SearchPaths, TabWidth),
      case pre_cond_check(FileName, AnnAST, NewMacroName, Start, End, SearchPaths, TabWidth) of
        {ok, AnnAST, Sel, NeedBracket} ->
  	  AnnAST1 = do_intro_new_macro(AnnAST, NewMacroName, Sel, NeedBracket),
  	  return_refac_result(FileName, Editor, Cmd, AnnAST1);
        {error, Reason} -> throw({error, Reason})
      end.
  
  pre_cond_check(FileName, AnnAST, NewMacroName, Start, End, SearchPaths, TabWidth) ->
      case refac_misc:is_fun_name(NewMacroName) orelse refac_misc:is_var_name(NewMacroName) of
        true ->
  	  Ms = existing_macros(FileName, SearchPaths, TabWidth),
  	  MsToAvoid = collect_names_to_avoid(AnnAST),
  	  case lists:member(list_to_atom(NewMacroName), Ms ++ MsToAvoid) of
  	    true ->
  		{error, "Macro name provided is already in use!"};
  	    _ ->
  		case interface_api:pos_to_fun_def(AnnAST, Start) of
  		  {ok, FunDef} ->
  		      Sel = interface_api:pos_to_expr_or_pat_list(AnnAST, Start, End),
  		      case Sel of
  			[] -> {error, "You have not selected a sequence of expressions/patterns!"};
  			_ ->
  			    ExprList = [hd(Sel)],
  			    NeedBracket = need_bracket(refac_util:get_toks(FunDef), ExprList),
  			    {ok, AnnAST, [hd(Sel)], NeedBracket}
  		      end;
  		  _ -> {error, "You have not selected a sequence of expressions/patterns!"}
  		end
  	  end;
        _ -> {error, "Invalid macro name!"}
      end.
  do_intro_new_macro(AnnAST, MacroName, SelExpList, NeedBracket) ->
      SelExpList1 = case NeedBracket of
  		    true -> [refac_syntax:parentheses(hd(SelExpList))];
  		    _ -> SelExpList
  		  end,
      Vars = refac_misc:collect_var_names(SelExpList),
      Args = [refac_syntax:variable(P) || P <- Vars],
      MName = mk_macro_name(MacroName),
      MDef = mk_macro_def(MName, Args, SelExpList1),
      Forms = refac_syntax:form_list_elements(AnnAST),
      {Forms1, Forms2} = lists:splitwith(fun (F) -> refac_syntax:type(F) == attribute orelse
  						    refac_syntax:type(F) == comment
  				       end, Forms),
      {S1, E1} = refac_misc:get_start_end_loc(SelExpList),
      MApp = mk_macro_app(MName, Args),
      Fun = fun (F) ->
  		  {S, E} = refac_util:get_range(F),
  		  case (S =< S1) and (E1 =< E) of
  		      true -> replace_expr_with_macro(F, {SelExpList, S1, E1}, MApp);
  		      _ -> F
  		  end
  	  end,
      Forms11 = [Fun(F) || F <- Forms1],
      Forms21 = [Fun(F) || F <- Forms2],
      refac_syntax:form_list(Forms11 ++ [MDef] ++ Forms21).
  
  mk_macro_name(MacroName) ->
      case refac_misc:is_var_name(MacroName) of
        true -> refac_syntax:variable(list_to_atom(MacroName));
        _ -> refac_syntax:atom(list_to_atom(MacroName))
      end.
  
  mk_macro_def(MName, Args, Exps) ->
      case Args of
        [] -> refac_syntax:attribute(refac_syntax:atom(define), [MName| Exps]);
        _ ->
  	  MApp = refac_syntax:application(MName, Args),
  	  refac_syntax:attribute(refac_syntax:atom(define), [MApp| Exps])
      end.
  
  mk_macro_app(Args, MName) ->
      case Args of
        [] ->
  	  refac_syntax:macro(MName);
        _ ->
  	  refac_syntax:macro(MName, Args)
      end.
  
   
  
  -spec(replace_expr_with_macro/3::(syntaxTree(), {[syntaxTree()], pos(), pos()}, syntaxTree()) ->
  				       syntaxTree()).
  replace_expr_with_macro(Form, {ExpList, SLoc, ELoc},  MApp) ->
      case (length(ExpList)==1) of 
  	true ->
  	    element(1,refac_util:stop_tdTP(fun replace_single_expr_with_macro_app/2, Form, {MApp, SLoc, ELoc}));
  	_ ->
  	    element(1, refac_util:stop_tdTP(fun replace_expr_list_with_macro_app/2, Form, {MApp, SLoc, ELoc}))
      end.
  
  replace_single_expr_with_macro_app(Tree, {MApp, SLoc, ELoc}) ->
      case refac_util:get_range(Tree) of
        {SLoc, ELoc} ->
  	  {MApp, true};
        _ -> {Tree, false}
      end.
  
      
  replace_expr_list_with_macro_app(Tree, {MApp, SLoc, ELoc}) ->
      case refac_syntax:type(Tree) of
        clause ->
  	  Body = refac_syntax:clause_body(Tree),
  	  Pats = refac_syntax:clause_patterns(Tree),
  	  {NewBody, Modified} = process_exprs(Body, {MApp, SLoc, ELoc}),
  	  {NewPats, Modified1} = process_exprs(Pats, {MApp, SLoc, ELoc}),
  	  case Modified or Modified1 of
  	    true ->
  		G = refac_syntax:clause_guard(Tree),
  		{refac_syntax:copy_pos(
  		   Tree, refac_syntax:copy_attrs(
  			   Tree, refac_syntax:clause(NewPats, G, NewBody))), true};
  	    _ ->
  		{Tree, false}
  	  end;
        application ->
  	  Args = refac_syntax:application_arguments(Tree),
  	  {NewArgs, Modified} = process_exprs(Args, {MApp, SLoc, ELoc}),
  	  case Modified of
  	    true -> Op = refac_syntax:application_operator(Tree),
  		    {refac_syntax:copy_pos(
  		       Tree, refac_syntax:copy_attrs(
  			       Tree, refac_syntax:application(Op, NewArgs))), true};
  	    false -> {Tree, false}
  	  end;
        tuple ->
  	  Elems = refac_syntax:tuple_elements(Tree),
  	  {NewElems, Modified} = process_exprs(Elems, {MApp, SLoc, ELoc}),
  	  case Modified of
  	    true ->
  		{refac_syntax:copy_pos(Tree, refac_syntax:copy_attrs(
  					       Tree, refac_syntax:tuple(NewElems))), true};
  	    false -> {Tree, false}
  	  end;
        block_expr ->
  	  Exprs = refac_syntax:block_expr_body(Tree),
  	  {NewExprs, Modified} = process_exprs(Exprs, {MApp, SLoc, ELoc}),
  	  case Modified of
  	    true -> {refac_syntax:copy_pos(Tree, refac_syntax:copy_attrs(
  						   Tree, refac_syntax:block_expr(NewExprs))), true};
  	    _ -> {Tree, false}
  	  end;
        _ ->
  	  {Tree, false}
      end.
  
  process_exprs(Exprs, {MApp, SLoc, ELoc}) ->    
      {Exprs1, Exprs2} = lists:splitwith(fun(E) -> 
  					       {SLoc1, _} =refac_util:get_range(E),
  					       SLoc1 =/= SLoc 
  				       end, Exprs),
      case Exprs2 of 
  	[] -> {Exprs, false};
  