Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

90 linhas
2.7 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. local indent_size = tonumber(indent_size_str, 10)
  7. local tab_width = tonumber(tab_width_str, 10)
  8. if indent_size_str == "tab" then
  9. indent_size = tab_width
  10. elseif tab_width == nil then
  11. tab_width = indent_size
  12. end
  13. if indent_size ~= nil then
  14. messenger:Message("set tabsize to " .. indent_size_str)
  15. SetLocalOption("tabsize", indent_size, view)
  16. end
  17. if indent_style == "space" then
  18. SetLocalOption("tabstospaces", "on", view)
  19. if indent_size ~= nil then
  20. messenger:Message("set tabsize to " .. tostring(indent_size))
  21. SetLocalOption("tabsize", indent_size, view)
  22. end
  23. elseif indent_style == "tab" then
  24. SetLocalOption("tabstospaces", "off", view)
  25. if tab_width ~= nil then
  26. messenger:Message("set tabsize to " .. tostring(tab_width))
  27. SetLocalOption("tabsize", tab_width, view)
  28. end
  29. else
  30. messenger:Message("unknown indent_style")
  31. end
  32. end
  33. local function setInsertFinalNewline(properties, view)
  34. local val = properties["insert_final_newline"]
  35. if val == "true" then
  36. SetLocalOption("eofnewline", true, view)
  37. elseif val == "false" then
  38. SetLocalOption("eofnewline", false, view)
  39. end
  40. end
  41. local function applyProperties(properties, view)
  42. setIndentation(properties, view)
  43. -- Currently micro does not support changing coding-systems
  44. -- (Always use utf-8 with LF?)
  45. -- setCodingSystem(properties, view)
  46. -- `ruler' is not what we want!
  47. -- setMaxLineLength(properties, view)
  48. -- setTrimTrailingWhitespace(properties, view)
  49. setInsertFinalNewline(properties, view)
  50. -- messenger:Message("ed output: " .. output)
  51. end
  52. function onEditorConfigExit(output)
  53. local properties = {}
  54. for line in output:gmatch('([^\n]+)') do
  55. local key, value = line:match('([^=]*)=(.*)')
  56. if key == nil or value == nil then
  57. messenger:Message("Failed to parse editorconfig output: " .. output)
  58. return
  59. end
  60. key = key:gsub('^%s(.-)%s*$', '%1')
  61. value = value:gsub('^%s(.-)%s*$', '%1')
  62. properties[key] = value
  63. end
  64. local view = CurView()
  65. applyProperties(properties, view)
  66. end
  67. local function getApplyProperties(view)
  68. local fullpath = view.Buf.AbsPath
  69. messenger:Message("editorconfig " .. fullpath)
  70. -- JobSpawn("editorconfig", {fullpath}, "", "", "init.onEditorConfigExit")
  71. JobStart("editorconfig " .. fullpath, "", "", "init.onEditorConfigExit")
  72. end
  73. function onViewOpen(view)
  74. getApplyProperties(view)
  75. end
  76. function onSave(view)
  77. -- messenger:Message("Saved!")
  78. end