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.
 
 
 
 
 
 

35 lines
996 B

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