You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

36 lines
1.0 KiB

  1. -- ec = require("editorconfig_core")
  2. local function getProperties(fullpath)
  3. -- TODO: Avoid command injection vulnerability
  4. local file = io.popen("editorconfig '" .. fullpath .. "'", "r")
  5. local output = file:read("*all")
  6. file:close()
  7. local properties = {}
  8. -- TODO: Which is better? output:gmatch(), string.gmatch(output, ...)
  9. for line in output:gmatch('([^\n]+)') do
  10. -- TODO: Fix regex
  11. local key, value = line:match('([^=]*)=(.*)')
  12. key = key:gsub('^%s(.-)%s*$', '%1')
  13. value = value:gsub('^%s(.-)%s*$', '%1')
  14. -- TODO: Throw error when key is empty string
  15. properties[key] = value
  16. end
  17. return properties
  18. end
  19. function onViewOpen(view)
  20. -- Is this portable? (work on windows?)
  21. local pwd = os.getenv("PWD")
  22. local filename = view.Buf.Path
  23. -- prop, names = ec.parse(filepath)
  24. local fullpath = JoinPaths(pwd, filename)
  25. local out = getProperties(fullpath)
  26. messenger:Message("edconf: " .. out["indent_style"])
  27. end
  28. function onSave(view)
  29. messenger:Message("Saved!")
  30. end