From f247d246725d76412242e547e7c212bf947542f8 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Mon, 18 Mar 2013 15:31:07 +0100 Subject: Let escript recognize an encoding comment on the second line The manual says that an Emacs directive can be placed on the second line. With this patch that directive is also recognized when selecting encoding of the script. --- lib/stdlib/src/escript.erl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/stdlib/src') diff --git a/lib/stdlib/src/escript.erl b/lib/stdlib/src/escript.erl index 32742e419b..fea718541d 100644 --- a/lib/stdlib/src/escript.erl +++ b/lib/stdlib/src/escript.erl @@ -602,9 +602,15 @@ parse_beam(S, File, HeaderSz, CheckOnly) -> parse_source(S, File, Fd, StartLine, HeaderSz, CheckOnly) -> {PreDefMacros, Module} = pre_def_macros(File), IncludePath = [], - {ok, _} = file:position(Fd, {bof, HeaderSz}), + %% Read the encoding on the second line, if there is any: + {ok, _} = file:position(Fd, 0), + _ = io:get_line(Fd, ''), + Encoding = epp:set_encoding(Fd), + {ok, _} = file:position(Fd, HeaderSz), case epp:open(File, Fd, StartLine, IncludePath, PreDefMacros) of {ok, Epp} -> + _ = [io:setopts(Fd, [{encoding,Encoding}]) || + Encoding =/= none], {ok, FileForm} = epp:parse_erl_form(Epp), OptModRes = epp:parse_erl_form(Epp), S2 = S#state{source = text, module = Module}, -- cgit v1.2.3