LuaFormatter icon indicating copy to clipboard operation
LuaFormatter copied to clipboard

help: two blank lines between the functions. How to set this format?

Open membphis opened this issue 4 years ago • 7 comments

I checked the doc: https://github.com/Koihik/LuaFormatter/blob/master/docs/Style-Config.md

I do not find this field.

membphis avatar Jan 21 '21 15:01 membphis

@Koihik can you give me some suggestions about this feature? I want to make a try with it.

membphis avatar Jan 22 '21 10:01 membphis

I didn't quite understand what you want to achieve.

Could you provide some code samples?

tammela avatar Jan 22 '21 14:01 tammela

need a way to specify the style(one or two blank lines between the functions):

-- two blank lines between the functions
function x()
  print(1)
end


function y()
  print(1)
end

-- one blank line between the functions
function x()
  print(1)
end

function y()
  print(1)
end

membphis avatar Jan 23 '21 03:01 membphis

We don't have this configuration and at a glance it seems non trivial (perhaps even impossible) to implement

tammela avatar Jan 23 '21 15:01 tammela

here is my hack way:

https://github.com/Koihik/LuaFormatter/compare/master...membphis:membphis-2blank-func

I do not sure if it is acceptable, if yes, I'll try to submit a PR.

membphis avatar Jan 24 '21 01:01 membphis

here is my hack way:

master...membphis:membphis-2blank-func

I do not sure if it is acceptable, if yes, I'll try to submit a PR.

If it works out for you then it's fine. The problem is that we can't accept it as is because it would also affect code like this:

set_callback(function ()
   -- ...
end)

function foo()
   function bar()
   end
   -- ...
end

local a = function ()
   -- ...
end

The visitor pattern that we use to parse the AST can't distinguish the function declaration in these situations without the need for more processing

tammela avatar Jan 25 '21 13:01 tammela

@tammela Many thx for your remind I'll try to find a better way

membphis avatar Jan 25 '21 15:01 membphis