| author | Marc Aubry | 2012-07-13 05:44:26 (EDT) |
|---|---|---|
| committer | sbernard | 2012-07-13 05:44:26 (EDT) |
| commit | a4b892dd3d655d6327e98adcb3bfd89e5948fe92 (patch) (side-by-side diff) | |
| tree | 0b590cc33fa729cd30882f615c54127a5a4b6e07 | |
| parent | b84f91c3dba6e0d1cffb6cd6b46668bdca2332cb (diff) | |
| download | org.eclipse.koneki.ldt-a4b892dd3d655d6327e98adcb3bfd89e5948fe92.zip org.eclipse.koneki.ldt-a4b892dd3d655d6327e98adcb3bfd89e5948fe92.tar.gz org.eclipse.koneki.ldt-a4b892dd3d655d6327e98adcb3bfd89e5948fe92.tar.bz2 | |
Bug 385019 - [formatter] No formatting of the file first line
| -rw-r--r-- | libraries/luaformatter/luaformatter.lua | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/libraries/luaformatter/luaformatter.lua b/libraries/luaformatter/luaformatter.lua index 39d4da7..14499c4 100644 --- a/libraries/luaformatter/luaformatter.lua +++ b/libraries/luaformatter/luaformatter.lua @@ -58,7 +58,7 @@ local function getindentlevel(source,indenttable) -- -- Define AST walker -- - local linetodepth = {} + local linetodepth = {0} local walker = { block = {}, expr = {}, @@ -72,14 +72,12 @@ local function getindentlevel(source,indenttable) -- get first line of the block local startline,startoffset = getfirstline(node) local endline = getlastline(node) - if source:sub(1,startoffset-1):find("[\r\n]%s*$") then - for i=startline, endline do - linetodepth[i]=walker.depth - end - else - for i=startline+1, endline do - linetodepth[i]=walker.depth - end + -- If the block don't start by a new line, don't indent the first line + if not source:sub(1,startoffset-1):find("[\r\n]%s*$") then + startline = startline + 1 + end + for i=startline, endline do + linetodepth[i]=walker.depth end walker.depth = walker.depth + 1 end @@ -205,7 +203,6 @@ function M.indentcode(source, delimiter,indenttable, ...) -- calculate indentation local linetodepth = getindentlevel(source,indenttable) - -- Concatenate string with right identation local indented = {} for position=1, #positions do |

