anchor.diff:  %% @see get_ctxt_user/1
   %% @see set_ctxt_user/2
   
  -format(Node, Options) ->
  -    W = proplists:get_value(paper, Options, ?PAPER),
  -    L = proplists:get_value(ribbon, Options, ?RIBBON),
  -    prettypr:format(layout(Node, Options), W, L).
  -
  +
  +format(Node,Options) ->
  +    W = proplists:get_value(paper,Options,?PAPER),
  +    L = proplists:get_value(ribbon,Options,?RIBBON),
  +    prettypr:format(layout(Node,Options),W,L).
   
   %% =====================================================================
   %% @spec best(Tree::syntaxTree()) -> empty | document()
   %% @equiv best(Tree, [])
   
  -best(Node) ->
  -    best(Node, []).
  -
  +
  +best(Node) -> best(Node,[]).
   
   %% =====================================================================
   %% @spec best(Tree::syntaxTree(), Options::[term()]) ->
  
positive.code: %% @see erl_parse
  %% @see get_ctxt_precedence/1
  
  set_ctxt_precedence(Ctxt, Prec) ->
      set_prec(Ctxt, Prec).
  
  set_prec(Ctxt, Prec) ->
      Ctxt#ctxt{prec = Prec}.    % used internally
  
  reset_prec(Ctxt) ->
      set_prec(Ctxt, 0).    % used internally
  
  %% @spec (context()) -> integer()
  %% @doc Returns the paper widh field of the prettyprinter context.
  %% @see set_ctxt_paperwidth/2
  
  get_ctxt_paperwidth(Ctxt) ->
      Ctxt#ctxt.paper.
  
  %% @spec (context(), integer()) -> context()
  %%
  
negative.code: %% <code>prettypr</code>, for text formatting of abstract syntax trees
  %% defined by the module <code>erl_syntax</code>.</p>
  
  
  -module(refac_prettypr).
  
  -export([format/1,format/2,best/1,best/2,layout/1,
  	 layout/2,get_ctxt_precedence/1,set_ctxt_precedence/2,
  	 get_ctxt_paperwidth/1,set_ctxt_paperwidth/2,
  	 get_ctxt_linewidth/1,set_ctxt_linewidth/2,
  	 get_ctxt_hook/1,set_ctxt_hook/2,get_ctxt_user/1,
  	 set_ctxt_user/2,print_ast/1]).
  
  -import(prettypr,
  	[text/1,nest/2,above/2,beside/2,sep/1,par/1,par/2,
  	 floating/3,floating/1,break/1,follow/2,follow/3,
  	 empty/0]).
  
  -import(erl_parse,
  	[preop_prec/1,inop_prec/1,func_prec/0,max_prec/0]).
  
  -define(PADDING, 2).
  
  -define(PAPER, 80).
  
  -define(RIBBON, 56).
  
  -define(NOUSER, undefined).
  
  -define(NOHOOK, none).
  
  -record(ctxt,
  	{prec = 0,sub_indent = 2,break_indent = 4,
  	 clause = undefined,hook = ?NOHOOK,paper = ?PAPER,
  	 ribbon = ?RIBBON,user = ?NOUSER}).
  
  %% Start of added by HL
  %% ====================================================================
  %% user-program guided pretty-printing of an abstract syntax tree which
  %% must be a form list.
  print_ast(AST) -> print_ast(AST,[]).
  
  print_ast(AST,Options) ->
      Ctxt = #ctxt{hook =
  		     proplists:get_value(hook,Options,?NOHOOK),
  		 paper = proplists:get_value(paper,Options,?PAPER),
  		 ribbon = proplists:get_value(ribbon,Options,?RIBBON),
  		 user = proplists:get_value(user,Options)},
      Fs = erl_syntax:form_list_elements(AST),
      Es = seq_pr(Fs,none,reset_prec(Ctxt),fun lay/2),
      LayoutedEs = lists:map(fun (E) ->
  				   refac_prettypr_0:layout(E)
  			   end,Es),
      vertical_concat(lists:zip(LayoutedEs,Fs)).
  
  seq_pr([H| T],Separator,Ctxt,Fun) ->
      {Paper,Ribbon} = get_paper_ribbon_width(H),
      case T of
        [] -> [prettypr:best(Fun(H,Ctxt),Paper,Ribbon)];
        _ ->
  	  [maybe_append(Separator,prettypr:best(Fun(H,Ctxt),Paper,Ribbon))
  	   | seq_pr(T,Separator,Ctxt,Fun)]
      end;
  seq_pr([],_,_,_) -> [].
  
  vertical_concat(Es) -> vertical_concat(Es,"").
  
  vertical_concat([],Acc) -> Acc;
  vertical_concat([{E,Form}| T],Acc) ->
      SpecialForm = fun (F) ->
  			  case refac_syntax:type(F) of
  			    error_marker -> true;
  			    attribute ->
  				case
  				  refac_syntax:atom_value(refac_syntax:attribute_name(F))
  				    of
  				  type -> true;
  				  'spec' -> true;
  				  _ -> false
  				end;
  			    _ -> false
  			  end
  		  end,
      F = refac_util:concat_toks(refac_util:get_toks(Form)),
      {ok,EToks,_} = refac_scan:string(E),
      {ok,FToks,_} = refac_scan:string(io_lib:write_string(F)),
      EStr = process_str(refac_util:concat_toks(EToks)),
      FStr = process_str(refac_util:concat_toks(FToks)),
      Acc1 = case Acc of
  	     "" -> Acc;
  	     _ ->
  		 case (EStr == FStr) or SpecialForm(Form) of
  		   true -> Acc;
  		   false -> Acc ++ "\n"
  		 end
  	   end,
      Str = case (EStr == FStr) or SpecialForm(Form) of
  	    true -> F;
  	    false ->
  		case T of
  		  [] -> E;
  		  [{_E1,_Form1}| _] -> E ++ "\n"
  		end
  	  end,
      case T of
        [] -> Acc1 ++ Str;
        _ -> vertical_concat(T,Acc1 ++ Str)
      end.
  
  process_str(S) ->
      lists:flatmap(fun (C) ->
  			  case C of
  			    ' ' -> [];
  			    $" -> [];
  			    _ -> [C]
  			  end
  		  end,
  		  S).
  
  get_paper_ribbon_width(Form) -> {?PAPER,?RIBBON}.
  
  %% get_paper_ribbon_width(Form) ->
  %%     case refac_syntax:type(Form) of
  %% 	attribute -> {?PAPER, ?RIBBON};
  %% 	_ ->
  %% 	    Fun = fun(T,Acc) ->
  %% 			   {S, E} = refac_util:get_range(T),
  %% 			   [S,E]++ Acc
  %% 		   end,
  %% 	     AllRanges =refac_syntax_lib:fold(Fun, [], Form),
  %% 	     case AllRanges of
  %% 		 [] -> {?PAPER, ?RIBBON};
  %% 		 _ ->  {Start,End} = refac_util:get_range(Form),
  %% 		       GroupedRanges = group_by(1, (lists:filter(fun(Loc) ->
  %% 									 (Loc>= Start) and (Loc=<End) end, AllRanges))),
  %% 		       MinMaxCols=lists:map(fun(Rs) ->Cols = lists:map(fun({_Ln, Col}) -> Col end, Rs),
  %% 						      case Cols of
  %% 							  [] -> {1, 80};
  %% 							  _ -> {lists:min(Cols),lists:max(Cols)}
  %% 						      end
  %% 					    end,  GroupedRanges),
  %% 		       Paper = lists:max(lists:map(fun({_Min, Max}) ->
  %% 							   Max end, MinMaxCols)),
  %% 		       Ribbon = lists:max(lists:map(fun({Min, Max}) ->
  %% 							    Max-Min+1 end, MinMaxCols)),
  %% 		       Paper1 = case Paper < ?PAPER of
  %% 				    true -> ?PAPER;
  %% 				    _ -> Paper
  %% 				end,
  %% 		       Ribbon1 = case Ribbon < ?RIBBON of
  %% 				     true -> ?RIBBON;
  %% 				     _  -> Ribbon
  %% 				 end,	
  %% 		       {Paper1+5, Ribbon1+5}  %% adjustion to take the ending tokens such as brackets/commas into account.
  %% 	     end
  %%     end.
  
  
  group_by(N,TupleList) ->
      SortedTupleList = lists:keysort(N,TupleList),
      group_by(N,SortedTupleList,[]).
  
  group_by(_N,[],Acc) -> Acc;
  group_by(N,TupleList = [T| _Ts],Acc) ->
      E = element(N,T),
      {TupleList1,TupleList2} = lists:partition(fun (T1) ->
  						      element(N,T1) == E
  					      end,
  					      TupleList),
      group_by(N,TupleList2,Acc ++ [TupleList1]).
  
  %% End of added by HL.
  %% =====================================================================
  %% =====================================================================
  %% The following functions examine and modify contexts:
  
  
  %% @spec (context()) -> context()
  %% @doc Returns the operator precedence field of the prettyprinter
  %% context.
  %%
  %% @see set_ctxt_precedence/2
  
  
  get_ctxt_precedence(Ctxt) -> Ctxt#ctxt.prec.
  
  %% @spec (context(), integer()) -> context()
  %%
  