anchor.diff:      end.
   
   
  --spec(fold_expression_1/5::(filename(), atom(), integer(), [dir()], integer()) -> {syntaxTree(), moduleInfo()} | {error, string()}).
  -fold_expression_1(FileName, FunName, Arity, SearchPaths, TabWidth) ->
  -    {ok, {AnnAST, Info}} =refac_util:parse_annotate_file(FileName,true, SearchPaths, TabWidth),
  +-spec(fold_expression_1/4::(filename(), atom(), integer(), [dir()]) -> {syntaxTree(), moduleInfo()} | {error, string()}).
  +fold_expression_1(FileName, FunName, Arity, SearchPaths) ->
  +    {ok, {AnnAST, Info}} =refac_util:parse_annotate_file(FileName,true, SearchPaths),
       {value, {module, ModName}} = lists:keysearch(module, 1, Info),
       FunClauseDef= name_to_fun_clause(AnnAST, FunName, Arity),
       Candidates = search_candidate_exprs(AnnAST, {ModName, ModName}, FunName, FunClauseDef),
  
positive.code: %% @spec fold_expression(FileName::filename(), Line::integer(), Col::integer())-> term()
  %% =============================================================================================        
  
  -spec(fold_expr_by_loc/5::(filename(), integer(), integer(), [dir()], integer())->
  			 {ok, [{integer(), integer(), integer(), integer(), syntaxTree(), {filename(), atom(), syntaxTree(), integer()}}]}
  							 | {error, string()}).
  
  fold_expr_by_loc(FileName, Line, Col, SearchPaths, TabWidth) ->
      fold_expression(FileName, Line, Col, SearchPaths, TabWidth, emacs).
  
  -spec(fold_expr_by_loc_eclipse/5::(filename(), integer(), integer(), [dir()], integer()) -> {ok,  {syntaxTree(),
  										  [{{{integer(), integer()}, {integer(), integer()}}, syntaxTree()}]}}
  										     | {error, string()}).
  
  fold_expr_by_loc_eclipse(FileName, Line, Col, SearchPaths, TabWidth) ->
      fold_expression(FileName, Line, Col, SearchPaths, TabWidth, eclipse).
  
  fold_expression(FileName, Line, Col, SearchPaths, TabWidth, Editor) ->
      ?wrangler_io("\nCMD: ~p:fold_expression(~p, ~p,~p,~p).\n", [?MODULE, FileName, Line, Col, TabWidth]),
      {ok, {AnnAST, Info}} =refac_util:parse_annotate_file(FileName,true, SearchPaths, TabWidth),
      {value, {module, CurrentModName}} = lists:keysearch(module, 1, Info),
      case pos_to_fun_clause(AnnAST, {Line, Col}) of 
  	{ok, {Mod, FunName, _Arity, FunClauseDef, ClauseIndex}} ->
  	    case side_condition_analysis(FunClauseDef) of 
  		ok ->			    
  		    Candidates = search_candidate_exprs(AnnAST, {Mod, Mod}, FunName, FunClauseDef),
  		    case Candidates of 
  			[] -> {error, "No expressions that are suitable for folding against the selected function have been found!"};	
  			_ -> case Editor of 
  				 emacs ->Regions = lists:map(fun({{{StartLine, StartCol}, {EndLine, EndCol}},NewExp}) ->
  								     {StartLine, StartCol, EndLine,EndCol, NewExp, {FileName, CurrentModName, FunClauseDef, ClauseIndex}} end, 
  							     Candidates),
  					 {ok, Regions};
  				 eclipse ->  {ok, {FunClauseDef, Candidates}}
  			     end			      
  		    end;				 
  		{error, Reason} -> {error, Reason}
  	    end;
  	{error, _} ->
  	    {error, "You have not selected a function definition."}
      end.
  
  
  -spec(fold_expr_by_name/7::(filename(), string(), string(), string(), string(), [dir()], integer()) ->
  	     {ok, [{integer(), integer(), integer(), integer(), syntaxTree(), {filename(), atom(), syntaxTree(), integer()}}]}
  		 | {error, string()}).
  
  fold_expr_by_name(FileName, ModName, FunName, Arity, ClauseIndex, SearchPaths, TabWidth) ->
      case ModName of 
  	[] -> {error, "Invalid module name!"};
  	_  -> case FunName of 
  		  [] -> {error, "Invalid function name!"};
  		  _ -> case (Arity==[]) orelse (list_to_integer(Arity) <0) of   
  			   true -> {error, "Invalid arity!"};
  			   _ -> case (ClauseIndex==[]) orelse (list_to_integer(ClauseIndex) <1) of 
  				    true -> {error, "Invalid function clause index!"};
  				    _ ->				
  					fold_expr_by_name(FileName, list_to_atom(ModName), list_to_atom(FunName), 
  							  list_to_integer(Arity), list_to_integer(ClauseIndex), SearchPaths,  TabWidth, emacs)
  				end
  		       end
  	      end
      end.
   
  -spec(fold_expr_by_name_eclipse/7::(filename(), string(), string(), string(), string(), [dir()], integer()) ->
  	     {ok, [{{{integer(), integer()}, {integer(), integer()}}, syntaxTree()}]} 
  		 | {error, string()}).
  
  fold_expr_by_name_eclipse(FileName, ModName, FunName, Arity, ClauseIndex, SearchPaths, TabWidth) ->
  	case ModName of 
  		[] -> {error, "Invalid module name!"};
  		_  -> case FunName of 
  				  [] -> {error, "Invalid function name!"};
  				  _ -> case (Arity==[]) orelse (list_to_integer(Arity) <0) of   
  						   true -> {error, "Invalid arity!"};
  						   _ -> case (ClauseIndex==[]) orelse (list_to_integer(ClauseIndex) <1) of 
  									true -> {error, "Invalid function clause index!"};
  									_ ->				
  										fold_expr_by_name(FileName, list_to_atom(ModName), list_to_atom(FunName), 
  														  list_to_integer(Arity), list_to_integer(ClauseIndex), SearchPaths, TabWidth,  eclipse)
  								end
  					   end
  			  end
      end.
     
  
  fold_expr_by_name(FileName, ModName, FunName, Arity, ClauseIndex, SearchPaths, TabWidth,  Editor) ->
      ?wrangler_io("\nCMD: ~p:fold_expression(~p,~p,~p,~p,~p,~p).\n", [?MODULE, FileName, ModName, FunName, Arity, ClauseIndex, TabWidth]),
      {ok, {AnnAST, Info}} = refac_util:parse_annotate_file(FileName, true, SearchPaths, TabWidth),
      {value, {module, CurrentModName}} = lists:keysearch(module, 1, Info),
      Files = refac_util:expand_files(SearchPaths, ".erl"),
      FileNames = lists:filter(fun (F) -> list_to_atom(filename:basename(F, ".erl")) == ModName end, Files),
  
negative.code: 	end,
      Fun = hd(lists:filter(F, Forms)),
      hd(refac_syntax:function_clauses(Fun)).
  
  
  list_to_term(T) ->
      binary_to_term(list_to_binary(T)).
  
  term_to_list(T) ->
      binary_to_list(term_to_binary(T)).
  