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.
 
 
 
 
 
 

38 lines
1.1 KiB

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