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.
 
 
 
 
 
 

78 lines
2.4 KiB

  1. -- ec = require("editorconfig_core")
  2. local function setIndentation(properties, view)
  3. local indent_size_str = properties["indent_size"]
  4. local tab_width_str = properties["tab_width"]
  5. local indent_style = properties["indent_style"]
  6. -- TODO: Fix logic to decide indent_size
  7. local indent_size = tonumber(indent_size_str, 10)
  8. if indent_size ~= nil then
  9. messenger:Message("set tabsize to " .. indent_size_str)
  10. SetLocalOption("tabsize", indent_size, view)
  11. end
  12. if indent_style == "space" then
  13. SetLocalOption("tabstospaces", "on", view)
  14. elseif indent_style == "tab" then
  15. SetLocalOption("tabstospaces", "off", view)
  16. else
  17. messenger:Message("unknown indent_style")
  18. end
  19. end
  20. local function setInsertFinalNewline(properties, view)
  21. local val = properties["insert_final_newline"]
  22. if val == "true" then
  23. SetLocalOption("eofnewline", true, view)
  24. elseif val == "false" then
  25. SetLocalOption("eofnewline", false, view)
  26. end
  27. end
  28. local function applyProperties(properties, view)
  29. setIndentation(properties, view)
  30. -- Currently micro does not support changing coding-systems
  31. -- (Always use utf-8 with LF?)
  32. -- setCodingSystem(properties, view)
  33. -- `ruler' is not what we want!
  34. -- setMaxLineLength(properties, view)
  35. -- setTrimTrailingWhitespace(properties, view)
  36. setInsertFinalNewline(properties, view)
  37. -- messenger:Message("ed output: " .. output)
  38. end
  39. function onEditorConfigExit(output)
  40. -- messenger:Message(output)
  41. -- FIXME: messege when editorconfig exit with error
  42. local properties = {}
  43. -- TODO: Which is better? output:gmatch(), string.gmatch(output, ...)
  44. for line in output:gmatch('([^\n]+)') do
  45. -- TODO: Fix regex
  46. -- TODO: Throw error for invalid output
  47. local key, value = line:match('([^=]*)=(.*)')
  48. key = key:gsub('^%s(.-)%s*$', '%1')
  49. value = value:gsub('^%s(.-)%s*$', '%1')
  50. properties[key] = value
  51. end
  52. local view = CurView()
  53. applyProperties(properties, view)
  54. end
  55. local function getApplyProperties(view)
  56. local fullpath = view.Buf.AbsPath
  57. messenger:Message("editorconfig " .. fullpath)
  58. -- JobSpawn("editorconfig", {fullpath}, "", "", "init.onEditorConfigExit")
  59. JobStart("editorconfig " .. fullpath, "", "", "init.onEditorConfigExit")
  60. end
  61. function onViewOpen(view)
  62. getApplyProperties(view)
  63. -- messenger:Message(view.Buf.AbsPath)
  64. end
  65. function onSave(view)
  66. -- messenger:Message("Saved!")
  67. end