anchor.diff:  	end,
       Es = refac_syntax_lib:fold(F, [], Tree),
       [E ||  E <- Es, length(E) >= MinLen].
  -		 
  -
  -
  -      
  -
  -%% get the binding structure of variables.
  +
  +
  +%% Get the binding structure of variables.
   %%-spec(var_binding_structure/1::([syntaxTree()]) -> [{integer(), integer()}]).      
  +
   var_binding_structure(ASTList) ->
  -    Fun1 = fun (T, S) ->
  -		   case refac_syntax:type(T) of
  -		     variable ->
  -			 Name = refac_syntax:variable_name(T),
  -			 SrcLoc = refac_syntax:get_pos(T),
  -			 As = refac_syntax:get_ann(T),
  -			 case lists:keysearch(def, 1, As) of
  -			   {value, {def, DefLoc}} ->
  -			        [{atom_to_list(Name), SrcLoc,
  -						    DefLoc}|S];
  -			   _ -> S
  -			 end;
  -		     _ -> S
  -		   end
  -	   end,
  -    %% collect all variables including their defining and occuring locations. 
  -    B = lists:keysort(2, lists:flatmap(fun(T) -> refac_syntax_lib:fold(Fun1, [], T) end, ASTList)),
  -    %% collect occuring locations.
  -    SrcLocs = lists:map(fun ({_Name, SrcLoc, _DefLoc}) -> SrcLoc end, B),
  -    Res = case SrcLocs of 
  -	      [] -> 
  -		  [];
  -	      _ ->  IndexedLocs = lists:zip(SrcLocs, lists:seq(1, length(SrcLocs))),
  -		    B1 = lists:usort(lists:map(fun ({_Name, SrcLoc, DefLoc}) ->
  -						       DefLoc1 = hd(DefLoc),             %% DefLoc is  a list, does this cause problems? .
  -						       {value, {SrcLoc, Index1}} = lists:keysearch(SrcLoc, 1, IndexedLocs),
  -						       Index2 = case lists:keysearch(DefLoc1, 1, IndexedLocs) of 
  -								    {value, {_, Ind}} -> Ind;
  -								    _ -> 0 %% free variable
  -								end,
  -						       {Index1, Index2}
  -					       end,
  -					       B)),
  -		    lists:keysort(1, B1)
  +    VarLocs = lists:keysort(2, collect_vars(ASTList)),
  +    case VarLocs of
  +      [] ->
  +	  [];
  +      _ -> var_binding_structure_1(VarLocs)
  +    end.
  +
  +var_binding_structure_1(VarLocs) ->
  +    SrcLocs = [SrcLoc || {_Name, SrcLoc, _DefLoc} <- VarLocs],
  +    IndexedLocs = lists:zip(SrcLocs, lists:seq(1, length(SrcLocs))),
  +    Fun = fun ({_Name, SrcLoc, DefLoc}) ->
  +		  DefLoc1 = hd(DefLoc),
  +		  {value, {SrcLoc, Index1}} = lists:keysearch(SrcLoc, 1, IndexedLocs),
  +		  Index2 = case lists:keysearch(DefLoc1, 1, IndexedLocs) of
  +			       {value, {_, Ind}} -> Ind;
  +			       _ -> 0 %% free variable
  +			   end,
  +		  {Index1, Index2}
   	  end,
  -    Res.
  +    BS = [Fun(VL) || VL <- VarLocs],
  +    lists:keysort(1, lists:usort(BS)).
  +
  +collect_vars(AST) when is_list(AST) ->
  +    lists:flatmap(fun (T) -> collect_vars(T) end, AST);
  +collect_vars(AST) ->
  +    Fun = fun (T, S) ->
  +		  case refac_syntax:type(T) of
  +		    variable ->
  +			Name = refac_syntax:variable_name(T),
  +			SrcLoc = refac_syntax:get_pos(T),
  +			As = refac_syntax:get_ann(T),
  +			case lists:keysearch(def, 1, As) of
  +			  {value, {def, DefLoc}} ->
  +				[{atom_to_list(Name), SrcLoc, DefLoc}| S];
  +			    _ -> S
  +			end;
  +		      _ -> S
  +		  end
  +	  end,
  +    refac_syntax_lib:fold(Fun, [], AST).
  +
   
   compose_search_result_info(FileName, Ranges) ->
       compose_search_result_info(FileName, Ranges, "").
  
positive.code: 
  %% Search the clones of an expression from Tree.
  search_one_expr(Tree, Exp) ->
      Exp1  = simplify_expr(Exp),
      BdStructExp = var_binding_structure([Exp]),
      F = fun(T, Acc) ->
  		case refac_util:is_expr(T) of 
  		    true -> T1 = simplify_expr(T),
  			    case Exp1 == T1 of 
  				true -> 
  				    BdStructT = var_binding_structure([T]),
  				    case BdStructExp == BdStructT of 
  					true ->
  					    {{StartLn, StartCol}, {EndLn, EndCol}}= refac_util:get_range(T),
  					    Acc ++ [{{StartLn, StartCol}, {EndLn, EndCol}}];
  					    _  -> Acc
  				    end;
  				_ -> Acc
  			    end;
  		    _ -> Acc
  		end
  	end,
      refac_syntax_lib:fold(F, [], Tree).
      
  
  %% search the clones of an expresion sequence from Tree.			
  search_expr_seq(Tree, ExpList) ->
      AllExpList = contained_exprs(Tree, length(ExpList)),
     lists:flatmap(fun(EL) ->get_clone(ExpList, EL) end, AllExpList).
     
      
      
  get_clone(List1, List2) ->    
      Len1 = length(List1),
      Len2 = length(List2),
      case Len1 =< Len2 of 
  	true -> 
  	    List11 = lists:map(fun(T) -> simplify_expr(T) end, List1),
  	    List21 = lists:map(fun(T) -> simplify_expr(T) end, List2),
  	    case lists:prefix(List11, List21) of 
  		true ->
  		    List22 = lists:sublist(List2, Len1),
  		    BdList1 = var_binding_structure(List1),
  		    BdList2 = var_binding_structure(List22),
  		    case BdList1 == BdList2 of 
  			true ->
  			    E1 = hd(List22),
  			    En = lists:last(List22),
  			    {{StartLn, StartCol}, _EndLoc} = refac_util:get_range(E1),
  			    {_StartLoc1, {EndLn, EndCol}} = refac_util:get_range(En),
  			    [{{StartLn, StartCol}, {EndLn, EndCol}}] ++ get_clone(List1, tl(List2));
  			_ -> get_clone(List1, tl(List2))
  		    end;				       
  		    _ -> get_clone(List1, tl(List2))
  		end;			
  	_  -> []
      end.
  	    
  
  %% simplify an expression by masking variable names and literal variables, and also replace
  %% the concrete location values with the default value.
  simplify_expr(Exp) ->
      refac_util:full_buTP(fun(Node,_Others)->do_simplify_expr(Node) end, Exp,{}).
  
  do_simplify_expr(Node) ->
      Node1 = case refac_syntax:type(Node) of 
  
negative.code: %% <p> When the selected code contains multiple, but non-continuous sequence of, expressions, the first
  %% continuous sequence of expressions is taken as the user-selected expression. A continuous sequence of
  %% expressions is a sequence of expressions separated by ','.
  %% </p>
  %% =================================================================================================
  %% @spec expr_search(FileName::filename(), Start::Pos, End::Pos, integer())-> 
  %%           {ok, [{integer(), integer(), integer(), integer()}]} | {error, string()}.
  %% =================================================================================================         
  
  %%-spec(expr_search/4::(filename(), pos(), pos(), integer()) -> 
  %%    {ok, [{integer(), integer(), integer(), integer()}]} | {error, string()}).    
  expr_search(FileName, Start = {Line, Col}, End = {Line1, Col1}, TabWidth) ->
      ?wrangler_io("\nCMD: ~p:expr_search(~p, {~p,~p},{~p,~p},~p).\n",
  		 [?MODULE, FileName, Line, Col, Line1, Col1, TabWidth]),
      {ok, {AnnAST, _Info}} = refac_util:parse_annotate_file(FileName, true, [], TabWidth),
      case refac_util:pos_to_expr_list(AnnAST, Start, End) of
        [E| Es] ->
  	  Res = case Es == [] of
  		  true ->
  		      SE = refac_sim_expr_search:get_start_end_loc(E),
  		      SearchRes = search_one_expr(AnnAST, E),
  		      [SE| SearchRes -- [SE]];
  		  _ ->
  		      SE = refac_sim_expr_search:get_start_end_loc([E| Es]),
  		      SearchRes = search_expr_seq(AnnAST, [E| Es]),
  		      [SE| SearchRes -- [SE]]
  		end,
  	  case Res of
  	    [] -> ?wrangler_io("No identical expression has been found. \n", []),
  		  {ok, []};
  	    [_] ->
  		  ?wrangler_io("No identical expression has been found. \n", []),
  		  {ok, []};
  	    _ -> ?wrangler_io("\n~p identical expressions(including the "
  			      "expression selected) have been found.\n", [length(Res)]),
  		 ?wrangler_io(compose_search_result_info(FileName, Res), []),
  		 ?wrangler_io("\nUse 'C-c C-e' to remove highlights!\n", []),
  		 {ok, Res}
  	  end;
        _ -> {error, "You have not selected an expression!"}
      end.
  
  %%-spec(expr_search_eclipse/4::(filename(), pos(), pos(), integer()) ->
  %%   {ok, [{integer(), integer(), integer(), integer()}]} | {error, string()}).
  expr_search_eclipse(FileName, Start, End, TabWidth) ->
      {ok, {AnnAST, _Info}} =refac_util:parse_annotate_file(FileName,true, [], TabWidth),
      case refac_util:pos_to_expr_list(AnnAST, Start, End) of 
  